update,
This commit is contained in:
6
002_source/ionic_mobile/src/hooks/_GUIDELINES.md
Normal file
6
002_source/ionic_mobile/src/hooks/_GUIDELINES.md
Normal 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
|
@@ -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;
|
@@ -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;
|
@@ -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;
|
@@ -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;
|
@@ -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));
|
||||
|
Reference in New Issue
Block a user