mirror of
https://github.com/langgenius/dify.git
synced 2026-07-31 01:09:32 +08:00
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: yyh <yuanyouhuilyz@gmail.com> Co-authored-by: yyh <92089059+lyzno1@users.noreply.github.com>
49 lines
1.6 KiB
TypeScript
49 lines
1.6 KiB
TypeScript
import type { App, AppCategory } from '@/models/explore'
|
|
import { useQuery } from '@tanstack/react-query'
|
|
import { useLocale } from '@/context/i18n'
|
|
import { consoleQuery } from './client'
|
|
import { fetchAppList, fetchLearnDifyAppList } from './explore'
|
|
|
|
type ExploreAppListData = {
|
|
categories: AppCategory[]
|
|
allList: App[]
|
|
}
|
|
|
|
export const useExploreAppList = (options: { enabled?: boolean } = {}) => {
|
|
const locale = useLocale()
|
|
const exploreAppsInput = locale ? { query: { language: locale } } : {}
|
|
const exploreAppsLanguage = exploreAppsInput?.query?.language
|
|
|
|
return useQuery<ExploreAppListData>({
|
|
queryKey: [
|
|
...consoleQuery.explore.apps.get.queryKey({ input: exploreAppsInput }),
|
|
exploreAppsLanguage,
|
|
],
|
|
queryFn: async () => {
|
|
const { categories, recommended_apps } = await fetchAppList(exploreAppsLanguage)
|
|
return {
|
|
categories,
|
|
allList: [...recommended_apps].sort((a, b) => a.position - b.position),
|
|
}
|
|
},
|
|
enabled: options.enabled,
|
|
})
|
|
}
|
|
|
|
export const useLearnDifyAppList = () => {
|
|
const locale = useLocale()
|
|
const learnDifyAppsInput = locale ? { query: { language: locale } } : {}
|
|
const learnDifyAppsLanguage = learnDifyAppsInput?.query?.language
|
|
|
|
return useQuery({
|
|
queryKey: [
|
|
...consoleQuery.explore.apps.learnDify.get.queryKey({ input: learnDifyAppsInput }),
|
|
learnDifyAppsLanguage,
|
|
],
|
|
queryFn: async () => {
|
|
const { recommended_apps } = await fetchLearnDifyAppList(learnDifyAppsLanguage)
|
|
return [...recommended_apps].sort((a, b) => a.position - b.position)
|
|
},
|
|
})
|
|
}
|