```
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;
|
@@ -0,0 +1,38 @@
|
||||
// CR = ConnectiveRevision
|
||||
import { usePocketBase } from './usePocketBase.tsx';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import IListeningPracticeCategory from '../interfaces/IListeningPracticeCategory.tsx';
|
||||
|
||||
const useListQuizCRCategories = () => {
|
||||
const { user, pb } = usePocketBase();
|
||||
return useQuery({
|
||||
queryKey: [
|
||||
'useListQuizConnectiveRevisionContent',
|
||||
'feeds',
|
||||
'all',
|
||||
user?.id || '',
|
||||
//
|
||||
],
|
||||
staleTime: 60 * 1000,
|
||||
queryFn: async ({
|
||||
queryKey,
|
||||
}: {
|
||||
queryKey: [
|
||||
'useListQuizConnectiveRevisionContent',
|
||||
'feeds',
|
||||
'all',
|
||||
string | null,
|
||||
//
|
||||
];
|
||||
}) => {
|
||||
console.log('calling useListQuizConnectiveRevisionContent');
|
||||
return await pb.collection('LessonsCategories').getList<IListeningPracticeCategory>(1, 9999, {
|
||||
sort: 'pos',
|
||||
$autoCancel: false,
|
||||
});
|
||||
},
|
||||
// enabled: !!user?.id,
|
||||
});
|
||||
};
|
||||
|
||||
export default useListQuizCRCategories;
|
@@ -0,0 +1,26 @@
|
||||
import { usePocketBase } from './usePocketBase.tsx';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { QuizCRQuestion } from '../types/QuizCRQuestion.ts/index.ts';
|
||||
|
||||
const useListQuizCRQuestionByCRCategoryId = (CRCategoryId: string) => {
|
||||
const { user, pb } = usePocketBase();
|
||||
return useQuery({
|
||||
queryKey: ['useListQuizCRQuestionByCRCategoryId', 'feeds', 'all', user?.id || '', CRCategoryId],
|
||||
staleTime: 60 * 1000,
|
||||
queryFn: async ({
|
||||
queryKey,
|
||||
}: {
|
||||
queryKey: ['useListQuizCRQuestionByCRCategoryId', 'feeds', 'all', string | null, string];
|
||||
}) => {
|
||||
console.log('calling useListQuizCRQuestionByCRCategoryId');
|
||||
return await pb.collection('QuizCRQuestions').getList<QuizCRQuestion>(1, 9999, {
|
||||
filter: `cat_id = "${CRCategoryId}"`,
|
||||
sort: 'id',
|
||||
$autoCancel: false,
|
||||
});
|
||||
},
|
||||
// enabled: !!user?.id && !!CRCategoryId,
|
||||
});
|
||||
};
|
||||
|
||||
export default useListQuizCRQuestionByCRCategoryId;
|
Reference in New Issue
Block a user