update,
This commit is contained in:
28
002_source/ionic_mobile/src/hooks/fetchMFQuestions.tsx
Normal file
28
002_source/ionic_mobile/src/hooks/fetchMFQuestions.tsx
Normal file
@@ -0,0 +1,28 @@
|
||||
import { QuizMFQuestion } from '../types/QuizMFQuestion';
|
||||
import { usePocketBase } from './usePocketBase';
|
||||
import { QueryClient } from '@tanstack/react-query';
|
||||
|
||||
const queryClient = new QueryClient({
|
||||
defaultOptions: {
|
||||
queries: {
|
||||
staleTime: Infinity,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const fetchMFQuestions = async (cat_id: string, pb: any) => {
|
||||
const response = await queryClient.fetchQuery({
|
||||
queryKey: ['fetchData'],
|
||||
staleTime: 60 * 1000,
|
||||
queryFn: async () => {
|
||||
return await pb.collection('QuizMFQuestions').getList<QuizMFQuestion>(1, 9999, {
|
||||
filter: `cat_id = "${cat_id}"`,
|
||||
$autoCancel: false,
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
return response;
|
||||
};
|
||||
|
||||
export default fetchMFQuestions;
|
@@ -0,0 +1,44 @@
|
||||
import { QuizMFQuestion } from '../types/QuizMFQuestion';
|
||||
import { usePocketBase } from './usePocketBase';
|
||||
import { QueryClient } from '@tanstack/react-query';
|
||||
|
||||
const queryClient = new QueryClient({
|
||||
defaultOptions: {
|
||||
queries: {
|
||||
staleTime: Infinity,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const useListQuizMFQuestionsByCategoryId = (cat_id: string) => {
|
||||
const { user, pb } = usePocketBase();
|
||||
|
||||
const fetchData = async () => {
|
||||
const response = await queryClient.fetchQuery({
|
||||
queryKey: ['fetchData'],
|
||||
staleTime: 60 * 1000,
|
||||
queryFn: async () => {
|
||||
return await pb.collection('QuizMFQuestions').getList<QuizMFQuestion>(1, 9999, {
|
||||
filter: `cat_id = "${cat_id}"`,
|
||||
$autoCancel: false,
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
return response;
|
||||
};
|
||||
|
||||
return useQuery({
|
||||
queryKey: ['useListQuizMFQuestionsByCategoryId'],
|
||||
staleTime: 60 * 1000,
|
||||
queryFn: async () => {
|
||||
return await pb.collection('QuizMFQuestions').getList<QuizMFQuestion>(1, 9999, {
|
||||
filter: `cat_id = "${cat_id}"`,
|
||||
$autoCancel: false,
|
||||
});
|
||||
},
|
||||
// enabled: !!user.id,
|
||||
});
|
||||
};
|
||||
|
||||
export default useListQuizMFQuestionsByCategoryId;
|
Reference in New Issue
Block a user