Files
zap.stream/src/hooks/game-info.ts
kieran 5794dc3d2f feat: default category images
chore: video/stream-tile split
2024-05-27 11:24:33 +01:00

31 lines
911 B
TypeScript

import { AllCategories } from "@/pages/category";
import GameDatabase, { GameInfo } from "@/service/game-database";
import { useEffect, useState } from "react";
export default function useGameInfo(gameId?: string, gameInfo?: GameInfo) {
const [game, setGame] = useState<GameInfo | undefined>(gameInfo);
useEffect(() => {
if (!gameInfo && gameId) {
const [prefix, id] = gameId.split(":");
if (prefix === "internal" || !gameId.includes(":")) {
const ix = AllCategories.find(a => a.id === id || a.id === gameId);
if (ix) {
setGame({
...ix,
id: `internal:${ix.id}`,
name: ix.name,
genres: ix.tags,
className: ix.className,
cover: ix.cover,
});
}
} else {
new GameDatabase().getGame(gameId).then(setGame);
}
}
}, [gameInfo, gameId]);
return game;
}