
add new hooks for fetching QuizCRQuestions and categories, update related components to use the new hooks, and refactor SelectCategory page to use the new API ```
31 lines
800 B
TypeScript
31 lines
800 B
TypeScript
import { idCard } from 'ionicons/icons';
|
|
import { QuizCRQuestion } from '../types/QuizCRQuestion';
|
|
import { usePocketBase } from './usePocketBase';
|
|
import { QueryClient } from '@tanstack/react-query';
|
|
import PocketBase from 'pocketbase';
|
|
|
|
const queryClient = new QueryClient({
|
|
defaultOptions: {
|
|
queries: {
|
|
staleTime: Infinity,
|
|
},
|
|
},
|
|
});
|
|
|
|
const fetchCRQuestions = async (cat_id: string, pb: PocketBase) => {
|
|
const response = await queryClient.fetchQuery({
|
|
queryKey: ['fetchData', cat_id],
|
|
staleTime: 60 * 1000,
|
|
queryFn: async () => {
|
|
return await pb.collection('QuizCRQuestions').getList<QuizCRQuestion>(1, 9999, {
|
|
filter: `cat_id = "${cat_id}"`,
|
|
$autoCancel: false,
|
|
});
|
|
},
|
|
});
|
|
|
|
return response;
|
|
};
|
|
|
|
export default fetchCRQuestions;
|