mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-06 21:35:52 +08:00
fix: fix waring in usetags (#7039)
fix: 修复usetags中的警告 Co-authored-by: linshuhao <nmnm1996>
This commit is contained in:
parent
4f28086a64
commit
d2147aed3b
@ -1,4 +1,5 @@
|
|||||||
import { useAppDispatch, useAppSelector } from '@renderer/store'
|
import { createSelector } from '@reduxjs/toolkit'
|
||||||
|
import { RootState, useAppDispatch, useAppSelector } from '@renderer/store'
|
||||||
import { setTagsOrder, updateAssistants } from '@renderer/store/assistants'
|
import { setTagsOrder, updateAssistants } from '@renderer/store/assistants'
|
||||||
import { flatMap, groupBy, uniq } from 'lodash'
|
import { flatMap, groupBy, uniq } from 'lodash'
|
||||||
import { useCallback, useMemo } from 'react'
|
import { useCallback, useMemo } from 'react'
|
||||||
@ -6,15 +7,19 @@ import { useTranslation } from 'react-i18next'
|
|||||||
|
|
||||||
import { useAssistants } from './useAssistant'
|
import { useAssistants } from './useAssistant'
|
||||||
|
|
||||||
|
// 基础选择器
|
||||||
|
const selectAssistantsState = (state: RootState) => state.assistants
|
||||||
|
// 记忆化 tagsOrder 选择器(自动处理默认值)--- 这是一个选择器,用于从 store 中获取 tagsOrder 的值。因为之前的tagsOrder是后面新加的,不这样做会报错,所以这里需要处理一下默认值
|
||||||
|
const selectTagsOrder = createSelector([selectAssistantsState], (assistants) => assistants.tagsOrder ?? [])
|
||||||
|
|
||||||
// 定义useTags的返回类型,包含所有标签和获取特定标签的助手函数
|
// 定义useTags的返回类型,包含所有标签和获取特定标签的助手函数
|
||||||
// 为了不增加新的概念,标签直接作为助手的属性,所以这里的标签是指助手的标签属性
|
// 为了不增加新的概念,标签直接作为助手的属性,所以这里的标签是指助手的标签属性
|
||||||
// 但是为了方便管理,增加了一个获取特定标签的助手函数
|
// 但是为了方便管理,增加了一个获取特定标签的助手函数
|
||||||
|
|
||||||
export const useTags = () => {
|
export const useTags = () => {
|
||||||
const { assistants } = useAssistants()
|
const { assistants } = useAssistants()
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const dispatch = useAppDispatch()
|
const dispatch = useAppDispatch()
|
||||||
const savedTagsOrder = useAppSelector((state) => state.assistants.tagsOrder || [])
|
const savedTagsOrder = useAppSelector(selectTagsOrder)
|
||||||
|
|
||||||
// 计算所有标签
|
// 计算所有标签
|
||||||
const allTags = useMemo(() => {
|
const allTags = useMemo(() => {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user