Improve video fetching by enabling dynamic query parameter support
Update the FolxStadlPage component to dynamically construct API query parameters using URLSearchParams, enhancing flexibility and addressing potential issues with fixed query strings in the useQuery hook. Replit-Commit-Author: Agent Replit-Commit-Session-Id: ab9cd02a-d0b2-4288-9ceb-1964d0059648 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/8cc42625-c1f5-4e43-99bd-77f2c4dedee2/ab9cd02a-d0b2-4288-9ceb-1964d0059648/XzF7myD
This commit is contained in:
parent
ef52d070d9
commit
a7ea13c377
@ -20,7 +20,23 @@ export default function FolxStadlPage() {
|
||||
const itemsPerPage = 10;
|
||||
|
||||
const { data, isLoading } = useQuery<{videos: Video[], total: number}>({
|
||||
queryKey: ['/api/videos?limit=200'],
|
||||
queryKey: ['/api/videos', { limit: 200 }],
|
||||
queryFn: async ({ queryKey }) => {
|
||||
const [, params] = queryKey as [string, any];
|
||||
const searchParams = new URLSearchParams();
|
||||
|
||||
Object.entries(params).forEach(([key, value]) => {
|
||||
if (value !== undefined) {
|
||||
searchParams.append(key, String(value));
|
||||
}
|
||||
});
|
||||
|
||||
const response = await fetch(`/api/videos?${searchParams}`);
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to fetch videos');
|
||||
}
|
||||
return response.json();
|
||||
},
|
||||
select: (response) => response || { videos: [], total: 0 }
|
||||
});
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user