Enhance search #215

Merged
enes merged 4 commits from issues/212-improved-search into staging 2025-02-04 09:27:09 +00:00
Showing only changes of commit 4bba7c888e - Show all commits

View File

@ -5,11 +5,14 @@ import { Game } from 'types'
import { log, LogType } from 'utils' import { log, LogType } from 'utils'
import gameFiles from '../utils/games' import gameFiles from '../utils/games'
let cachedGamesData: Game[] | null = null
export const useGames = () => { export const useGames = () => {
const hasProcessedFiles = useRef(false) const hasProcessedFiles = useRef(false)
const [games, setGames] = useState<Game[]>([]) const [games, setGames] = useState<Game[]>(cachedGamesData || [])
useEffect(() => { useEffect(() => {
if (cachedGamesData) return
if (hasProcessedFiles.current) return if (hasProcessedFiles.current) return
hasProcessedFiles.current = true hasProcessedFiles.current = true
@ -52,6 +55,7 @@ export const useGames = () => {
}) })
await Promise.all(promises) await Promise.all(promises)
cachedGamesData = uniqueGames
setGames(uniqueGames) setGames(uniqueGames)
} catch (err) { } catch (err) {
log( log(