From 360a3c35a396584d48cc0050d69e174f24b91528 Mon Sep 17 00:00:00 2001 From: Zhou Weidong <502333560@qq.com> Date: Tue, 10 Nov 2026 16:07:43 +0800 Subject: [PATCH] feat: connect listing and search pages to app API --- src/pages/ListingPage.jsx | 5 ++++- src/pages/SearchPage.jsx | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/pages/ListingPage.jsx b/src/pages/ListingPage.jsx index 1e97401..52699b9 100644 --- a/src/pages/ListingPage.jsx +++ b/src/pages/ListingPage.jsx @@ -3,5 +3,8 @@ import { MediaCard } from '../components/MediaCard'; import { SectionHeading } from '../components/SectionHeading'; import { videos } from '../data/catalog'; import { useAppStore } from '../app/store'; +import { appApi } from '../services/appApi'; +import { normalizeDrama, normalizePage } from '../services/normalizers'; +import { useApi } from '../hooks/useApi'; -export function ListingPage({ type }) { const { locale } = useAppStore(); const title = type === 'shorts' ? locale.shortTitle : type === 'subscriptions' ? locale.channels : type === 'history' ? locale.history : locale.library; return <>
{videos.map((video) => )}
; } +export function ListingPage({ type }) { const { locale } = useAppStore(); const title = type === 'shorts' ? locale.shortTitle : type === 'subscriptions' ? locale.channels : type === 'history' ? locale.history : locale.library; const api = useApi(() => appApi.dramas().then((payload) => normalizePage(payload).list.map((item) => normalizeDrama(item, locale.code))), [locale.code]); const items = api.data?.length ? api.data : videos; return <>
{api.loading ? locale.loading : api.error ? locale.apiFallback : ''}
{items.map((video) => )}
; } diff --git a/src/pages/SearchPage.jsx b/src/pages/SearchPage.jsx index 4967d03..16cbcb9 100644 --- a/src/pages/SearchPage.jsx +++ b/src/pages/SearchPage.jsx @@ -4,5 +4,8 @@ import { MediaCard } from '../components/MediaCard'; import { SectionHeading } from '../components/SectionHeading'; import { useAppStore } from '../app/store'; import { searchCatalog } from '../services/catalogService'; +import { appApi } from '../services/appApi'; +import { normalizeDrama, normalizePage } from '../services/normalizers'; +import { useApi } from '../hooks/useApi'; -export function SearchPage() { const { locale } = useAppStore(); const [params] = useSearchParams(); const query = params.get('q') || ''; const results = searchCatalog(query, '', 0); return <>
{results.map((video) => )}
; } +export function SearchPage() { const { locale } = useAppStore(); const [params] = useSearchParams(); const query = params.get('q') || ''; const api = useApi(() => appApi.dramas().then((payload) => normalizePage(payload).list.map((item) => normalizeDrama(item, locale.code))), [locale.code]); const source = api.data?.length ? api.data : searchCatalog('', '', 0); const normalizedQuery = query.toLowerCase(); const results = source.filter((video) => `${video.title} ${video.channel} ${video.genre}`.toLowerCase().includes(normalizedQuery)); return <>
{api.loading ? locale.loading : api.error ? locale.apiFallback : ''}
{results.map((video) => )}
; }