```
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 ```
This commit is contained in:
30
002_source/ionic_mobile/src/hooks/fetchCRQuestions.tsx
Normal file
30
002_source/ionic_mobile/src/hooks/fetchCRQuestions.tsx
Normal file
@@ -0,0 +1,30 @@
|
||||
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;
|
Reference in New Issue
Block a user