mirror of
https://github.com/lucasrcsantana/story-generator.git
synced 2025-12-16 21:37:51 +00:00
58 lines
1.5 KiB
TypeScript
58 lines
1.5 KiB
TypeScript
import { useQuery } from '@tanstack/react-query';
|
|
import { supabase } from '@/lib/supabase';
|
|
import type { PhonicsExercise, PhonicsExerciseCategory } from '@/types/phonics';
|
|
|
|
export function usePhonicsExercises(categoryId?: string) {
|
|
return useQuery({
|
|
queryKey: ['phonics-exercises', categoryId],
|
|
queryFn: async () => {
|
|
const query = supabase
|
|
.from('phonics_exercises')
|
|
.select(`
|
|
*,
|
|
category:phonics_categories(
|
|
id,
|
|
name,
|
|
description,
|
|
level
|
|
),
|
|
type:phonics_exercise_types(
|
|
id,
|
|
name
|
|
),
|
|
words:phonics_exercise_words(
|
|
id,
|
|
is_correct_answer,
|
|
order_index,
|
|
word:phonics_words(word)
|
|
)
|
|
`)
|
|
.eq('is_active', true)
|
|
.order('difficulty_level', { ascending: true });
|
|
|
|
if (categoryId) {
|
|
query.eq('category_id', categoryId);
|
|
}
|
|
|
|
const { data, error } = await query;
|
|
if (error) throw error;
|
|
|
|
return data as PhonicsExercise[];
|
|
}
|
|
});
|
|
}
|
|
|
|
export function usePhonicsCategories() {
|
|
return useQuery({
|
|
queryKey: ['phonics-categories'],
|
|
queryFn: async () => {
|
|
const { data, error } = await supabase
|
|
.from('phonics_categories')
|
|
.select('*')
|
|
.order('order_index', { ascending: true });
|
|
|
|
if (error) throw error;
|
|
return data as PhonicsExerciseCategory[];
|
|
}
|
|
});
|
|
}
|