This commit is contained in:
2026-04-12 18:54:59 +07:00
parent 28e866a64e
commit ec3d400e8a
71 changed files with 7888 additions and 333 deletions

View File

@@ -1,16 +1,32 @@
import { useQuery } from "@tanstack/react-query"
import { supabase } from "@/lib/supabase"
import type { VocabWord, VocabTopic } from "@/types"
export function useVocab(topic?: string) {
// Maps a Supabase row to VocabWord.
// DB column `meaning_vi` → interface field `meaningVi`.
function rowToVocabWord(row: Record<string, unknown>): VocabWord {
return {
id: row.id as string,
word: row.word as string,
phonetic: (row.phonetic as string) ?? '',
meaningVi: row.meaning_vi as string,
topic: row.topic as VocabTopic,
example: (row.example as string) ?? '',
}
}
// Fetches ALL vocab; topic filtering is done in-component so we avoid
// separate queries per topic and keep the cache simple.
export function useVocab() {
return useQuery({
queryKey: ["vocab", topic],
queryKey: ['vocab'],
queryFn: async () => {
let query = supabase.from("vocab").select("*")
if (topic) query = query.eq("topic", topic.toLowerCase())
const { data, error } = await query
const { data, error } = await supabase
.from('vocab')
.select('*')
.order('topic')
if (error) throw error
return data
return (data ?? []).map(rowToVocabWord)
},
enabled: false, // Enabled during feature implementation
})
}