Initialize Vyryi front-end project with React, Vite, and TypeScript. Add essential files including configuration, environment variables, and basic structure. Implement authentication, routing, and API interaction for a Telegram Mini App UI. Include README and styling for a cohesive user experience.
This commit is contained in:
41
src/pages/GamePage.tsx
Normal file
41
src/pages/GamePage.tsx
Normal file
@@ -0,0 +1,41 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { Link, Navigate, useParams } from 'react-router-dom'
|
||||
import { api } from '../api'
|
||||
import { useAuth } from '../auth'
|
||||
import type { GameStub } from '../types'
|
||||
|
||||
export function GamePage() {
|
||||
const { slug } = useParams<{ slug: string }>()
|
||||
const { user, loading } = useAuth()
|
||||
const [game, setGame] = useState<GameStub | null>(null)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
|
||||
useEffect(() => {
|
||||
if (!slug) return
|
||||
void api
|
||||
.getGame(slug)
|
||||
.then(setGame)
|
||||
.catch((err: unknown) => setError(err instanceof Error ? err.message : 'Не найдено'))
|
||||
}, [slug])
|
||||
|
||||
if (!loading && user && !user.agreement_accepted) {
|
||||
return <Navigate to="/" replace />
|
||||
}
|
||||
|
||||
return (
|
||||
<main className="game-page">
|
||||
<Link to="/home" className="back-link">
|
||||
← Назад
|
||||
</Link>
|
||||
{error && <p className="error">{error}</p>}
|
||||
{game && (
|
||||
<section className="game-stub">
|
||||
<img src="/logo.png" alt="" className="game-stub__mark" />
|
||||
<h1>{game.title}</h1>
|
||||
<p>{game.description}</p>
|
||||
<p className="game-stub__badge">В разработке</p>
|
||||
</section>
|
||||
)}
|
||||
</main>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user