This commit is contained in:
louiscklaw
2025-04-29 16:09:30 +08:00
parent 4c72861eda
commit 9d3e832081
29 changed files with 446 additions and 136 deletions

View File

@@ -0,0 +1,6 @@
# GUIDELINE
- single file contains single function only
- please refer to the `tsx` files already exist in this directory for
- styling
- naming convention

View File

@@ -0,0 +1,20 @@
import { usePocketBase } from './usePocketBase';
import { useQuery } from '@tanstack/react-query';
import { CategoryType } from '../types/CategoryTypes';
const useListCategoriesByLessonId = (lessonId: string) => {
const { pb } = usePocketBase();
return useQuery({
queryKey: ['categories', 'byLessonType', lessonId],
queryFn: async () => {
return await pb.collection('LessonsCategories').getList<LessonCategory>(1, 9999, {
filter: `lesson_id = "${lessonId}"`,
sort: 'pos',
});
},
staleTime: 60 * 1000 * 5, // 5 minutes
});
};
export default useListCategoriesByLessonId;

View File

@@ -0,0 +1,19 @@
import { usePocketBase } from './usePocketBase';
import { useQuery } from '@tanstack/react-query';
const useListMatchingFrenzyCategories = () => {
const { user, pb } = usePocketBase();
return useQuery({
queryKey: ['useListMatchingFrenzyCategories'],
staleTime: 60 * 1000,
queryFn: async () => {
return await pb.collection('QuizMFCategories').getList<MatchingFrenzyCategory>(1, 9999, {
$autoCancel: false,
});
},
// enabled: !!user?.id,
});
};
export default useListMatchingFrenzyCategories;

View File

@@ -0,0 +1,26 @@
import { usePocketBase } from './usePocketBase.tsx';
import { useQuery } from '@tanstack/react-query';
// import { QuizLPQuestion } from '../types/QuizLPQuestion';
const useListQuizLPQuestionByLPCategoryId = (LPCategoryId: string) => {
const { user, pb } = usePocketBase();
return useQuery({
queryKey: ['useListQuizLPQuestionByLPCategoryId', 'feeds', 'all', user?.id || '', LPCategoryId],
staleTime: 60 * 1000,
queryFn: async ({
queryKey,
}: {
queryKey: ['useListQuizLPQuestionByLPCategoryId', 'feeds', 'all', string | null, string];
}) => {
console.log('calling useListQuizLPQuestionByLPCategoryId');
return await pb.collection('QuizLPQuestions').getList<QuizLPQuestion>(1, 9999, {
filter: `cat_id = "${LPCategoryId}"`,
sort: 'id',
$autoCancel: false,
});
},
// enabled: !!user?.id && !!LPCategoryId,
});
};
export default useListQuizLPQuestionByLPCategoryId;

View File

@@ -0,0 +1,37 @@
import { usePocketBase } from './usePocketBase.tsx';
import { useQuery } from '@tanstack/react-query';
import IListeningPracticeCategory from '../interfaces/IListeningPracticeCategory.tsx';
const useListQuizListeningPracticeContent = () => {
const { user, pb } = usePocketBase();
return useQuery({
queryKey: [
'useListQuizListeningPracticeContent',
'feeds',
'all',
user?.id || '',
//
],
staleTime: 60 * 1000,
queryFn: async ({
queryKey,
}: {
queryKey: [
'useListQuizListeningPracticeContent',
'feeds',
'all',
string | null,
//
];
}) => {
console.log('calling useListQuizListeningPracticeContent');
return await pb.collection('LessonsCategories').getList<IListeningPracticeCategory>(1, 9999, {
sort: 'pos',
$autoCancel: false,
});
},
// enabled: !!user?.id,
});
};
export default useListQuizListeningPracticeContent;

View File

@@ -1,5 +1,6 @@
import { useCallback, useState, useEffect, createContext, useContext } from 'react';
import PocketBase, { AuthRecord } from 'pocketbase';
import { POCKETBASE_URL } from '../constants';
type PocketBaseContextValue = {
pb: PocketBase;
user: AuthRecord;
@@ -7,7 +8,7 @@ type PocketBaseContextValue = {
};
const PocketBaseContext = createContext<PocketBaseContextValue | null>(null);
const POCKETBASE_URL = import.meta.env.VITE_POCKETBASE_URL;
// const POCKETBASE_URL = import.meta.env.VITE_POCKETBASE_URL;
export const PocketBaseProvider = ({ children }: { children: any }) => {
const [pb, _] = useState(new PocketBase(POCKETBASE_URL));