From 7aef0471b2a4e89f37726b33d5d6cec4012cf548 Mon Sep 17 00:00:00 2001 From: Artem Bulgakov Date: Sat, 30 Nov 2024 14:39:04 +0300 Subject: [PATCH] chore: show dice count --- frontend/src/routes/index.tsx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/frontend/src/routes/index.tsx b/frontend/src/routes/index.tsx index 338df39..ddc2805 100644 --- a/frontend/src/routes/index.tsx +++ b/frontend/src/routes/index.tsx @@ -1,8 +1,11 @@ import type { LevelInfo } from '@/components/mahjong/levels.ts' +import { FieldTemplate } from '@/components/mahjong/field-template.ts' import { levels } from '@/components/mahjong/levels.ts' import { Button } from '@/components/ui/button.tsx' import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from '@/components/ui/card.tsx' +import { pluralize } from '@/lib/utils.ts' import { createFileRoute, Link } from '@tanstack/react-router' +import { useMemo } from 'react' export const Route = createFileRoute('/')({ component: RouteComponent, @@ -32,12 +35,20 @@ function RouteComponent() { } function LevelCard({ level, isUnlocked }: { level: LevelInfo, isUnlocked: boolean }) { + const diceCount = useMemo(() => { + const decoded = FieldTemplate.decode(level.template) + return decoded.tileCoords.length + }, [level]) + return ( {level.title} - 72 кости, + {diceCount} + {' '} + {pluralize(diceCount, 'кость', 'кости', 'костей')} + , {' '} {level.description}