mirror of
https://github.com/langgenius/dify.git
synced 2026-04-18 04:16:28 +08:00
Signed-off-by: yyh <yuanyouhuilyz@gmail.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: CodingOnStar <hanxujiang@dify.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Coding On Star <447357187@qq.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: -LAN- <laipz8200@outlook.com> Co-authored-by: statxc <tyleradams93226@gmail.com>
36 lines
991 B
TypeScript
36 lines
991 B
TypeScript
import { atom, useAtomValue, useSetAtom } from 'jotai'
|
|
import { selectAtom } from 'jotai/utils'
|
|
import { useCallback, useMemo } from 'react'
|
|
|
|
const expandedAtom = atom<Record<string, boolean>>({})
|
|
|
|
export function useModelProviderListExpanded(providerName: string) {
|
|
return useAtomValue(
|
|
useMemo(
|
|
() => selectAtom(expandedAtom, s => !!s[providerName]),
|
|
[providerName],
|
|
),
|
|
)
|
|
}
|
|
|
|
export function useSetModelProviderListExpanded(providerName: string) {
|
|
const set = useSetAtom(expandedAtom)
|
|
return useCallback(
|
|
(expanded: boolean) => set(prev => ({ ...prev, [providerName]: expanded })),
|
|
[providerName, set],
|
|
)
|
|
}
|
|
|
|
export function useExpandModelProviderList() {
|
|
const set = useSetAtom(expandedAtom)
|
|
return useCallback(
|
|
(providerName: string) => set(prev => ({ ...prev, [providerName]: true })),
|
|
[set],
|
|
)
|
|
}
|
|
|
|
export function useResetModelProviderListExpanded() {
|
|
const set = useSetAtom(expandedAtom)
|
|
return useCallback(() => set({}), [set])
|
|
}
|