From 15247adfa3f89bca0b612e108e954eefd188e138 Mon Sep 17 00:00:00 2001 From: StepanovPlaton Date: Sun, 12 May 2024 13:12:13 +0400 Subject: [PATCH] Init game page --- src/app/games/[game_id]/page.tsx | 48 ++++++++++++++++++++++++++++++ src/app/games/page.tsx | 6 ++-- src/app/layout.tsx | 4 ++- src/app/page.tsx | 4 +-- src/entities/game/game.ts | 4 +++ src/entities/game/schemas/game.ts | 7 ++--- src/features/gameCard/gameCard.tsx | 5 ++-- src/shared/ui/cover/cover.tsx | 19 ++++++++++++ src/shared/ui/cover/index.ts | 3 ++ 9 files changed, 88 insertions(+), 12 deletions(-) create mode 100644 src/app/games/[game_id]/page.tsx create mode 100644 src/shared/ui/cover/cover.tsx create mode 100644 src/shared/ui/cover/index.ts diff --git a/src/app/games/[game_id]/page.tsx b/src/app/games/[game_id]/page.tsx new file mode 100644 index 0000000..e8bba56 --- /dev/null +++ b/src/app/games/[game_id]/page.tsx @@ -0,0 +1,48 @@ +import { GameService } from "@/entities/game"; +import { GameCard } from "@/features/gameCard"; +import { Section } from "@/widgets/section"; +import Image from "next/image"; + +export default async function Games({ + params: { game_id }, +}: { + params: { game_id: number }; +}) { + const gameCards = await GameService.getGameCards(); + const game = await GameService.getGame(game_id); + return ( + <> + {game && ( +
+ {game.cover && ( + + )} +
+

{game.title}

+

+ {game.description} +

+
+
+ )} + + {gameCards && ( +
+ {gameCards.map((card) => ( + + ))} +
+ )} + + ); +} diff --git a/src/app/games/page.tsx b/src/app/games/page.tsx index 7cceb5b..cb408cc 100644 --- a/src/app/games/page.tsx +++ b/src/app/games/page.tsx @@ -9,10 +9,10 @@ export const metadata: Metadata = { ".Torrent: Игры - каталог .torrent файлов для обмена видеоиграми", }; -export default async function Home() { +export default async function Games() { const gameCards = await GameService.getGameCards(); return ( -
+ <> {gameCards && (
{gameCards.map((card) => ( @@ -20,6 +20,6 @@ export default async function Home() { ))}
)} -
+ ); } diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 7f85a7f..a77ffd3 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -23,7 +23,9 @@ export default function RootLayout({
- {children} +
+ {children} +
diff --git a/src/app/page.tsx b/src/app/page.tsx index 982e5fb..50f7e68 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -5,7 +5,7 @@ import { Section } from "@/widgets/section"; export default async function Home() { const gameCards = await GameService.getGameCards(); return ( -
+ <> {gameCards && (
)} -
+ ); } diff --git a/src/entities/game/game.ts b/src/entities/game/game.ts index c16032a..5478154 100644 --- a/src/entities/game/game.ts +++ b/src/entities/game/game.ts @@ -1,5 +1,6 @@ import { HTTPService } from "@/shared/http/httpService"; import { gameCardsSchema, GameCardType } from "./schemas/gameCard"; +import { gameSchema, GameType } from "./schemas/game"; export abstract class GameService { public static async getGameCards() { @@ -8,4 +9,7 @@ export abstract class GameService { gameCardsSchema ); } + public static async getGame(id: number) { + return await HTTPService.get(`/games/${id}`, gameSchema); + } } diff --git a/src/entities/game/schemas/game.ts b/src/entities/game/schemas/game.ts index 5131223..26861c0 100644 --- a/src/entities/game/schemas/game.ts +++ b/src/entities/game/schemas/game.ts @@ -1,8 +1,7 @@ import { z } from "zod"; import { gameCardSchema } from "./gameCard"; -export const gameSchema = z.union([ - gameCardSchema, +export const gameSchema = gameCardSchema.and( z.object({ torrent_file: z.string().min(1), language: z.string().optional(), @@ -17,8 +16,8 @@ export const gameSchema = z.union([ .string() .min(1) .transform((d) => new Date(d)), - }), -]); + }) +); export type GameType = z.infer; export const isGame = (a: any): a is GameType => { diff --git a/src/features/gameCard/gameCard.tsx b/src/features/gameCard/gameCard.tsx index a5a9949..d980f28 100644 --- a/src/features/gameCard/gameCard.tsx +++ b/src/features/gameCard/gameCard.tsx @@ -1,9 +1,10 @@ import { GameCardType } from "@/entities/game"; import Image from "next/image"; +import Link from "next/link"; export const GameCard = ({ card }: { card: GameCardType }) => { return ( -
+ {!!card.cover_preview && ( {

{card.description}

-
+ ); }; diff --git a/src/shared/ui/cover/cover.tsx b/src/shared/ui/cover/cover.tsx new file mode 100644 index 0000000..dc92ec1 --- /dev/null +++ b/src/shared/ui/cover/cover.tsx @@ -0,0 +1,19 @@ +import Image from "next/image"; + +export const Cover = ({ + cover, + type = "preview", +}: { + cover: string; + type?: "cover" | "preview"; +}) => { + return ( + + ); +}; diff --git a/src/shared/ui/cover/index.ts b/src/shared/ui/cover/index.ts new file mode 100644 index 0000000..c19549b --- /dev/null +++ b/src/shared/ui/cover/index.ts @@ -0,0 +1,3 @@ +import { Cover } from "./cover"; + +export { Cover };