Download client/src/hooks/useGameSession.js from Mistral-AI-Game-Jam/ai-interactive-comic-book: direct link, hf CLI and curl.
- Browser
- Download file 968 Bytes
-
https://huggingface.co/spaces/Mistral-AI-Game-Jam/ai-interactive-comic-book/resolve/main/client/src/hooks/useGameSession.js
- Command line
-
hf download hf://spaces/Mistral-AI-Game-Jam/ai-interactive-comic-book/client/src/hooks/useGameSession.js
-
curl -L -o useGameSession.js https://huggingface.co/spaces/Mistral-AI-Game-Jam/ai-interactive-comic-book/resolve/main/client/src/hooks/useGameSession.js
968 Bytes
| import { useState, useEffect } from "react"; | |
| import { universeApi } from "../utils/api"; | |
| export const useGameSession = () => { | |
| const [sessionId, setSessionId] = useState(null); | |
| const [universe, setUniverse] = useState(null); | |
| const [isLoading, setIsLoading] = useState(true); | |
| const [error, setError] = useState(null); | |
| useEffect(() => { | |
| const initializeGame = async () => { | |
| try { | |
| setIsLoading(true); | |
| const { session_id, base_story, style, genre, epoch, macguffin } = | |
| await universeApi.generate(); | |
| setSessionId(session_id); | |
| setUniverse({ | |
| base_story, | |
| style, | |
| genre, | |
| epoch, | |
| macguffin, | |
| }); | |
| } catch (err) { | |
| setError(err.message || "Failed to initialize game session"); | |
| } finally { | |
| setIsLoading(false); | |
| } | |
| }; | |
| initializeGame(); | |
| }, []); | |
| return { | |
| sessionId, | |
| universe, | |
| isLoading, | |
| error, | |
| }; | |
| }; | |