Files
dify/web/service/explore.ts
yyh 063f6562cb refactor(web): remove React Query state sync anti-pattern from ExploreContext
Eliminate useEffect-based synchronization of React Query server state
into React Context, which caused extra renders, state drift, and
incorrect loading/empty states on the /explore/apps page.

- Remove installedApps, isFetchingInstalledApps, and
  controlUpdateInstalledApps from ExploreContext (dead code + anti-pattern)
- Sidebar and InstalledApp now consume useGetInstalledApps() directly
- Use isLoading (not isPending) for conditionally-enabled queries to
  avoid permanent loading state when query is disabled
- Derive hasEditPermission during render instead of via useEffect
- Replace FC type annotations with const arrow functions
- Add return type to fetchInstalledAppList
- Update all related unit and integration tests
2026-02-14 13:02:10 +08:00

42 lines
1.2 KiB
TypeScript

import type { AccessMode } from '@/models/access-control'
import type { Banner } from '@/models/app'
import type { App, AppCategory, InstalledApp } from '@/models/explore'
import { del, get, patch } from './base'
export const fetchAppList = () => {
return get<{
categories: AppCategory[]
recommended_apps: App[]
}>('/explore/apps')
}
// eslint-disable-next-line ts/no-explicit-any
export const fetchAppDetail = (id: string): Promise<any> => {
return get(`/explore/apps/${id}`)
}
export const fetchInstalledAppList = (app_id?: string | null) => {
return get<{ installed_apps: InstalledApp[] }>(`/installed-apps${app_id ? `?app_id=${app_id}` : ''}`)
}
export const uninstallApp = (id: string) => {
return del(`/installed-apps/${id}`)
}
export const updatePinStatus = (id: string, isPinned: boolean) => {
return patch(`/installed-apps/${id}`, {
body: {
is_pinned: isPinned,
},
})
}
export const getAppAccessModeByAppId = (appId: string) => {
return get<{ accessMode: AccessMode }>(`/enterprise/webapp/app/access-mode?appId=${appId}`)
}
export const fetchBanners = (language?: string): Promise<Banner[]> => {
const url = language ? `/explore/banners?language=${language}` : '/explore/banners'
return get<Banner[]>(url)
}