diff --git a/web/app/components/explore/app-list/index.spec.tsx b/web/app/components/explore/app-list/index.spec.tsx
index ebf2c9c075..c84da1931c 100644
--- a/web/app/components/explore/app-list/index.spec.tsx
+++ b/web/app/components/explore/app-list/index.spec.tsx
@@ -10,7 +10,9 @@ import AppList from './index'
const allCategoriesEn = 'explore.apps.allCategories:{"lng":"en"}'
let mockTabValue = allCategoriesEn
const mockSetTab = vi.fn()
-let mockExploreData: { categories: string[], allList: App[] } = { categories: [], allList: [] }
+let mockExploreData: { categories: string[], allList: App[] } | undefined = { categories: [], allList: [] }
+let mockIsLoading = false
+let mockIsError = false
const mockHandleImportDSL = vi.fn()
const mockHandleImportDSLConfirm = vi.fn()
@@ -34,8 +36,11 @@ vi.mock('ahooks', async () => {
})
vi.mock('@/service/use-explore', () => ({
- exploreAppListInitialData: { categories: [], allList: [] },
- useExploreAppList: () => ({ data: mockExploreData }),
+ useExploreAppList: () => ({
+ data: mockExploreData,
+ isLoading: mockIsLoading,
+ isError: mockIsError,
+ }),
}))
vi.mock('@/service/explore', () => ({
@@ -136,13 +141,16 @@ describe('AppList', () => {
vi.clearAllMocks()
mockTabValue = allCategoriesEn
mockExploreData = { categories: [], allList: [] }
+ mockIsLoading = false
+ mockIsError = false
})
// Rendering: show loading when categories are not ready.
describe('Rendering', () => {
- it('should render loading when categories are empty', () => {
+ it('should render loading when the query is loading', () => {
// Arrange
- mockExploreData = { categories: [], allList: [] }
+ mockExploreData = undefined
+ mockIsLoading = true
// Act
renderWithContext()
diff --git a/web/app/components/explore/app-list/index.tsx b/web/app/components/explore/app-list/index.tsx
index 244a116e36..5ab68f9b04 100644
--- a/web/app/components/explore/app-list/index.tsx
+++ b/web/app/components/explore/app-list/index.tsx
@@ -20,7 +20,7 @@ import {
DSLImportMode,
} from '@/models/app'
import { fetchAppDetail } from '@/service/explore'
-import { exploreAppListInitialData, useExploreAppList } from '@/service/use-explore'
+import { useExploreAppList } from '@/service/use-explore'
import { cn } from '@/utils/classnames'
import s from './style.module.css'
@@ -28,11 +28,6 @@ type AppsProps = {
onSuccess?: () => void
}
-export enum PageType {
- EXPLORE = 'explore',
- CREATE = 'create',
-}
-
const Apps = ({
onSuccess,
}: AppsProps) => {
@@ -58,10 +53,16 @@ const Apps = ({
})
const {
- data: { categories, allList } = exploreAppListInitialData,
+ data,
+ isLoading,
+ isError,
} = useExploreAppList()
- const filteredList = allList.filter(item => currCategory === allCategoriesEn || item.category === currCategory)
+ const filteredList = useMemo(() => {
+ if (!data)
+ return []
+ return data.allList.filter(item => currCategory === allCategoriesEn || item.category === currCategory)
+ }, [data, currCategory, allCategoriesEn])
const searchFilteredList = useMemo(() => {
if (!searchKeywords || !filteredList || filteredList.length === 0)
@@ -119,7 +120,7 @@ const Apps = ({
})
}, [handleImportDSLConfirm, onSuccess])
- if (!categories || categories.length === 0) {
+ if (isLoading) {
return (
@@ -127,6 +128,11 @@ const Apps = ({
)
}
+ if (isError || !data)
+ return null
+
+ const { categories } = data
+
return (
{
return useQuery({
queryKey: [NAME_SPACE, 'appList'],
@@ -27,7 +22,6 @@ export const useExploreAppList = () => {
allList: [...recommended_apps].sort((a, b) => a.position - b.position),
}
},
- placeholderData: exploreAppListInitialData,
})
}