UPDATE: Update readme and Next 16.07 (CVE-2025-66478)
This commit is contained in:
37
src/hooks/useFetchConfigData.ts
Normal file
37
src/hooks/useFetchConfigData.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
"use client"
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { getConfigMazeApi, getMainAffixApi, getSubAffixApi } from '@/lib/api'
|
||||
import useAffixStore from '@/stores/affixStore'
|
||||
import useMazeStore from '@/stores/mazeStore'
|
||||
import { useEffect } from 'react'
|
||||
import { toast } from 'react-toastify'
|
||||
|
||||
export const useFetchConfigData = () => {
|
||||
|
||||
const { setMapMainAffix, setMapSubAffix } = useAffixStore()
|
||||
const { setAllMazeData } = useMazeStore()
|
||||
|
||||
const { data, error } = useQuery({
|
||||
queryKey: ['initialConfigData'],
|
||||
queryFn: async () => {
|
||||
const [maze, main, sub] = await Promise.all([
|
||||
getConfigMazeApi(),
|
||||
getMainAffixApi(),
|
||||
getSubAffixApi(),
|
||||
])
|
||||
return { maze, main, sub }
|
||||
},
|
||||
staleTime: 1000 * 60 * 5,
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
if (data && !error) {
|
||||
setAllMazeData(data.maze)
|
||||
setMapMainAffix(data.main)
|
||||
setMapSubAffix(data.sub)
|
||||
}
|
||||
else if (error) {
|
||||
toast.error("Failed to load initial config data")
|
||||
}
|
||||
}, [data, error, setAllMazeData, setMapMainAffix, setMapSubAffix])
|
||||
}
|
||||
Reference in New Issue
Block a user