diff --git a/DESIGN.md b/DESIGN.md index 2d44042cd..f5c46f7bc 100644 --- a/DESIGN.md +++ b/DESIGN.md @@ -113,8 +113,8 @@ worth sending. clean board: tactile, cheerful, quick. Not cream paper and serifs, not a casino, not a brain-training lab. -**The tile is the idea.** The mark is an ink tile with a question-mark hook -and an amber dot; that amber dot is the moment the answer clicks. Games are +**The tile is the idea.** The mark is a T built from five puzzle tiles on an +ink ground, the last one amber; that amber tile is the moment the answer clicks. Games are tiles, buttons are tiles with a pressable edge, and the one amber thing on a screen is the thing to press next. @@ -247,7 +247,7 @@ tiles or blobs. Icons: 2px rounded-stroke line icons, 24px grid. - Do give each game one tile colour and use it on its card, hero and share image. - Do put Ink text on every Amber and tile-colour fill; never white on them. - Do show the free daily puzzle first and let a guest finish it with no signup. -- Don't use cream paper, newspaper serifs or rule lines; that is another brand. +- Don't use newspaper serifs in the interface or decorative rule lines; the home masthead's one heavy ink rule is the only rule. - Don't put Sylphx next to the mark, in headlines or in any image. - Don't show today's answer in any post, preview or result card. - Don't rely on colour alone for tile states. diff --git a/apps/puzzled/e2e-tests/phone-first.e2e.ts b/apps/puzzled/e2e-tests/phone-first.e2e.ts index b6c4a3437..f23e70f0f 100644 --- a/apps/puzzled/e2e-tests/phone-first.e2e.ts +++ b/apps/puzzled/e2e-tests/phone-first.e2e.ts @@ -7,7 +7,7 @@ for (const viewport of [ { width: 390, height: 844 }, { width: 360, height: 640 }, ]) { - test(`first visit keeps the whole puzzle, Play and consent clear at ${viewport.width}x${viewport.height}`, async ({ + test(`first visit keeps the whole puzzle and Play above the consent bar at ${viewport.width}x${viewport.height}`, async ({ page, }) => { // The served build is plain HTTP on loopback, where this spec's WebKit @@ -45,6 +45,9 @@ for (const viewport of [ const action = document.querySelector('[data-day-primary-action]')! const r = action.getBoundingClientRect() return { + cardDocTop: + document.querySelector('[data-day-puzzle-card]')!.getBoundingClientRect().top + + window.scrollY, card: bounds('[data-day-puzzle-card]'), play: bounds('[data-day-primary-action]'), consent: bounds('[data-consent-banner]'), @@ -52,18 +55,19 @@ for (const viewport of [ hit: action.contains(document.elementFromPoint(r.x + r.width / 2, r.y + r.height / 2)), } }) - expect(geometry.consent.bottom).toBeLessThanOrEqual(geometry.card.top) - expect(geometry.card.bottom).toBeLessThanOrEqual(geometry.nav.top) + // The consent bar sits at the bottom, above the tab bar, and below the + // whole featured card: it never covers the puzzle or Play. + expect(geometry.card.bottom).toBeLessThanOrEqual(geometry.consent.top) + expect(geometry.consent.bottom).toBeLessThanOrEqual(geometry.nav.top + 1) expect(geometry.play.height).toBeGreaterThanOrEqual(48) expect(geometry.hit).toBe(true) await expect(play).toHaveAttribute('href', /start=1#play$/) await consent.getByRole('button', { name: 'Decline', exact: true }).click() await expect(consent).toBeHidden() await expect(play).toBeVisible() - const after = await card.boundingBox() - expect(after!.y).toBeCloseTo( - geometry.card.top - (geometry.consent.bottom - geometry.consent.top), - 0, - ) + // Deciding moves nothing in the layout: the bar never pushed the hero down. + // (Compared in document coordinates: pressing a sticky button may scroll.) + const after = await card.evaluate((el) => el.getBoundingClientRect().top + window.scrollY) + expect(after).toBeCloseTo(geometry.cardDocTop, 0) }) } diff --git a/apps/puzzled/public/apple-touch-icon.png b/apps/puzzled/public/apple-touch-icon.png index dc0567495..2ea1b2841 100644 Binary files a/apps/puzzled/public/apple-touch-icon.png and b/apps/puzzled/public/apple-touch-icon.png differ diff --git a/apps/puzzled/public/brand/mark-mono.svg b/apps/puzzled/public/brand/mark-mono.svg index 685ab6da2..cedf24ec0 100644 --- a/apps/puzzled/public/brand/mark-mono.svg +++ b/apps/puzzled/public/brand/mark-mono.svg @@ -1 +1 @@ - \ No newline at end of file + diff --git a/apps/puzzled/public/brand/mark.svg b/apps/puzzled/public/brand/mark.svg index 1c726699f..b5144d3c9 100644 --- a/apps/puzzled/public/brand/mark.svg +++ b/apps/puzzled/public/brand/mark.svg @@ -1 +1 @@ - \ No newline at end of file + diff --git a/apps/puzzled/public/favicon.ico b/apps/puzzled/public/favicon.ico index dce0b3cfb..1f49ac552 100644 Binary files a/apps/puzzled/public/favicon.ico and b/apps/puzzled/public/favicon.ico differ diff --git a/apps/puzzled/public/favicon.png b/apps/puzzled/public/favicon.png index 01b87c484..328e075c2 100644 Binary files a/apps/puzzled/public/favicon.png and b/apps/puzzled/public/favicon.png differ diff --git a/apps/puzzled/public/favicon.svg b/apps/puzzled/public/favicon.svg index 94dab064d..2bb2a481f 100644 --- a/apps/puzzled/public/favicon.svg +++ b/apps/puzzled/public/favicon.svg @@ -1 +1 @@ - + diff --git a/apps/puzzled/public/icons/icon-128.png b/apps/puzzled/public/icons/icon-128.png index fe4bbe42d..003ff6a9f 100644 Binary files a/apps/puzzled/public/icons/icon-128.png and b/apps/puzzled/public/icons/icon-128.png differ diff --git a/apps/puzzled/public/icons/icon-144.png b/apps/puzzled/public/icons/icon-144.png index da652a0da..06da1f74d 100644 Binary files a/apps/puzzled/public/icons/icon-144.png and b/apps/puzzled/public/icons/icon-144.png differ diff --git a/apps/puzzled/public/icons/icon-152.png b/apps/puzzled/public/icons/icon-152.png index d1aaad475..f79a71854 100644 Binary files a/apps/puzzled/public/icons/icon-152.png and b/apps/puzzled/public/icons/icon-152.png differ diff --git a/apps/puzzled/public/icons/icon-192.png b/apps/puzzled/public/icons/icon-192.png index 583085f60..735c2bece 100644 Binary files a/apps/puzzled/public/icons/icon-192.png and b/apps/puzzled/public/icons/icon-192.png differ diff --git a/apps/puzzled/public/icons/icon-384.png b/apps/puzzled/public/icons/icon-384.png index 8c0993f91..d0ed0c3be 100644 Binary files a/apps/puzzled/public/icons/icon-384.png and b/apps/puzzled/public/icons/icon-384.png differ diff --git a/apps/puzzled/public/icons/icon-48.png b/apps/puzzled/public/icons/icon-48.png index 8d059abcc..beedb9d65 100644 Binary files a/apps/puzzled/public/icons/icon-48.png and b/apps/puzzled/public/icons/icon-48.png differ diff --git a/apps/puzzled/public/icons/icon-512.png b/apps/puzzled/public/icons/icon-512.png index ded953207..892a1f6b9 100644 Binary files a/apps/puzzled/public/icons/icon-512.png and b/apps/puzzled/public/icons/icon-512.png differ diff --git a/apps/puzzled/public/icons/icon-72.png b/apps/puzzled/public/icons/icon-72.png index c0cea8794..977faf477 100644 Binary files a/apps/puzzled/public/icons/icon-72.png and b/apps/puzzled/public/icons/icon-72.png differ diff --git a/apps/puzzled/public/icons/icon-96.png b/apps/puzzled/public/icons/icon-96.png index d21849370..8943855c8 100644 Binary files a/apps/puzzled/public/icons/icon-96.png and b/apps/puzzled/public/icons/icon-96.png differ diff --git a/apps/puzzled/public/icons/icon-maskable-512.png b/apps/puzzled/public/icons/icon-maskable-512.png index befcff057..b2cc3e157 100644 Binary files a/apps/puzzled/public/icons/icon-maskable-512.png and b/apps/puzzled/public/icons/icon-maskable-512.png differ diff --git a/apps/puzzled/public/motifs/arithmo-zoom.svg b/apps/puzzled/public/motifs/arithmo-zoom.svg new file mode 100644 index 000000000..d0bb0cbb4 --- /dev/null +++ b/apps/puzzled/public/motifs/arithmo-zoom.svg @@ -0,0 +1 @@ + diff --git a/apps/puzzled/public/motifs/arithmo.svg b/apps/puzzled/public/motifs/arithmo.svg new file mode 100644 index 000000000..6aab6f144 --- /dev/null +++ b/apps/puzzled/public/motifs/arithmo.svg @@ -0,0 +1 @@ + diff --git a/apps/puzzled/public/motifs/block-slide-zoom.svg b/apps/puzzled/public/motifs/block-slide-zoom.svg new file mode 100644 index 000000000..9b8ae9435 --- /dev/null +++ b/apps/puzzled/public/motifs/block-slide-zoom.svg @@ -0,0 +1 @@ + diff --git a/apps/puzzled/public/motifs/block-slide.svg b/apps/puzzled/public/motifs/block-slide.svg new file mode 100644 index 000000000..3c4bdf9d6 --- /dev/null +++ b/apps/puzzled/public/motifs/block-slide.svg @@ -0,0 +1 @@ + diff --git a/apps/puzzled/public/motifs/crossword-zoom.svg b/apps/puzzled/public/motifs/crossword-zoom.svg new file mode 100644 index 000000000..a223b16ad --- /dev/null +++ b/apps/puzzled/public/motifs/crossword-zoom.svg @@ -0,0 +1 @@ + diff --git a/apps/puzzled/public/motifs/crossword.svg b/apps/puzzled/public/motifs/crossword.svg new file mode 100644 index 000000000..1f6f189c2 --- /dev/null +++ b/apps/puzzled/public/motifs/crossword.svg @@ -0,0 +1 @@ + diff --git a/apps/puzzled/public/motifs/crowns-zoom.svg b/apps/puzzled/public/motifs/crowns-zoom.svg new file mode 100644 index 000000000..3884fc64f --- /dev/null +++ b/apps/puzzled/public/motifs/crowns-zoom.svg @@ -0,0 +1 @@ + diff --git a/apps/puzzled/public/motifs/crowns.svg b/apps/puzzled/public/motifs/crowns.svg new file mode 100644 index 000000000..05a0ae0ff --- /dev/null +++ b/apps/puzzled/public/motifs/crowns.svg @@ -0,0 +1 @@ + diff --git a/apps/puzzled/public/motifs/cryptogram-zoom.svg b/apps/puzzled/public/motifs/cryptogram-zoom.svg new file mode 100644 index 000000000..4ae6bc804 --- /dev/null +++ b/apps/puzzled/public/motifs/cryptogram-zoom.svg @@ -0,0 +1 @@ + diff --git a/apps/puzzled/public/motifs/cryptogram.svg b/apps/puzzled/public/motifs/cryptogram.svg new file mode 100644 index 000000000..62b543e97 --- /dev/null +++ b/apps/puzzled/public/motifs/cryptogram.svg @@ -0,0 +1 @@ + diff --git a/apps/puzzled/public/motifs/duo-zoom.svg b/apps/puzzled/public/motifs/duo-zoom.svg new file mode 100644 index 000000000..0a2f68977 --- /dev/null +++ b/apps/puzzled/public/motifs/duo-zoom.svg @@ -0,0 +1 @@ + diff --git a/apps/puzzled/public/motifs/duo.svg b/apps/puzzled/public/motifs/duo.svg new file mode 100644 index 000000000..cc95628e6 --- /dev/null +++ b/apps/puzzled/public/motifs/duo.svg @@ -0,0 +1 @@ + diff --git a/apps/puzzled/public/motifs/killer-sudoku-zoom.svg b/apps/puzzled/public/motifs/killer-sudoku-zoom.svg new file mode 100644 index 000000000..7a9771a59 --- /dev/null +++ b/apps/puzzled/public/motifs/killer-sudoku-zoom.svg @@ -0,0 +1 @@ + diff --git a/apps/puzzled/public/motifs/killer-sudoku.svg b/apps/puzzled/public/motifs/killer-sudoku.svg new file mode 100644 index 000000000..243907fd1 --- /dev/null +++ b/apps/puzzled/public/motifs/killer-sudoku.svg @@ -0,0 +1 @@ + diff --git a/apps/puzzled/public/motifs/nonogram-zoom.svg b/apps/puzzled/public/motifs/nonogram-zoom.svg new file mode 100644 index 000000000..bfb2533e3 --- /dev/null +++ b/apps/puzzled/public/motifs/nonogram-zoom.svg @@ -0,0 +1 @@ + diff --git a/apps/puzzled/public/motifs/nonogram.svg b/apps/puzzled/public/motifs/nonogram.svg new file mode 100644 index 000000000..86d93edf8 --- /dev/null +++ b/apps/puzzled/public/motifs/nonogram.svg @@ -0,0 +1 @@ + diff --git a/apps/puzzled/public/motifs/number-path-zoom.svg b/apps/puzzled/public/motifs/number-path-zoom.svg new file mode 100644 index 000000000..7da9c2532 --- /dev/null +++ b/apps/puzzled/public/motifs/number-path-zoom.svg @@ -0,0 +1 @@ + diff --git a/apps/puzzled/public/motifs/number-path.svg b/apps/puzzled/public/motifs/number-path.svg new file mode 100644 index 000000000..d8360eb71 --- /dev/null +++ b/apps/puzzled/public/motifs/number-path.svg @@ -0,0 +1 @@ + diff --git a/apps/puzzled/public/motifs/pattern-match-zoom.svg b/apps/puzzled/public/motifs/pattern-match-zoom.svg new file mode 100644 index 000000000..8c907c2e5 --- /dev/null +++ b/apps/puzzled/public/motifs/pattern-match-zoom.svg @@ -0,0 +1 @@ + diff --git a/apps/puzzled/public/motifs/pattern-match.svg b/apps/puzzled/public/motifs/pattern-match.svg new file mode 100644 index 000000000..65f2cfa58 --- /dev/null +++ b/apps/puzzled/public/motifs/pattern-match.svg @@ -0,0 +1 @@ + diff --git a/apps/puzzled/public/motifs/pip-place-zoom.svg b/apps/puzzled/public/motifs/pip-place-zoom.svg new file mode 100644 index 000000000..6aeb59058 --- /dev/null +++ b/apps/puzzled/public/motifs/pip-place-zoom.svg @@ -0,0 +1 @@ + diff --git a/apps/puzzled/public/motifs/pip-place.svg b/apps/puzzled/public/motifs/pip-place.svg new file mode 100644 index 000000000..4cb57dc24 --- /dev/null +++ b/apps/puzzled/public/motifs/pip-place.svg @@ -0,0 +1 @@ + diff --git a/apps/puzzled/public/motifs/quad-words-zoom.svg b/apps/puzzled/public/motifs/quad-words-zoom.svg new file mode 100644 index 000000000..358ba5d1e --- /dev/null +++ b/apps/puzzled/public/motifs/quad-words-zoom.svg @@ -0,0 +1 @@ + diff --git a/apps/puzzled/public/motifs/quad-words.svg b/apps/puzzled/public/motifs/quad-words.svg new file mode 100644 index 000000000..fa9d669b0 --- /dev/null +++ b/apps/puzzled/public/motifs/quad-words.svg @@ -0,0 +1 @@ + diff --git a/apps/puzzled/public/motifs/sudoku-zoom.svg b/apps/puzzled/public/motifs/sudoku-zoom.svg new file mode 100644 index 000000000..7b92d3073 --- /dev/null +++ b/apps/puzzled/public/motifs/sudoku-zoom.svg @@ -0,0 +1 @@ + diff --git a/apps/puzzled/public/motifs/sudoku.svg b/apps/puzzled/public/motifs/sudoku.svg new file mode 100644 index 000000000..6d8f4a698 --- /dev/null +++ b/apps/puzzled/public/motifs/sudoku.svg @@ -0,0 +1 @@ + diff --git a/apps/puzzled/public/motifs/word-box-zoom.svg b/apps/puzzled/public/motifs/word-box-zoom.svg new file mode 100644 index 000000000..cbba48221 --- /dev/null +++ b/apps/puzzled/public/motifs/word-box-zoom.svg @@ -0,0 +1 @@ + diff --git a/apps/puzzled/public/motifs/word-box.svg b/apps/puzzled/public/motifs/word-box.svg new file mode 100644 index 000000000..c712388a3 --- /dev/null +++ b/apps/puzzled/public/motifs/word-box.svg @@ -0,0 +1 @@ + diff --git a/apps/puzzled/public/motifs/word-groups-zoom.svg b/apps/puzzled/public/motifs/word-groups-zoom.svg new file mode 100644 index 000000000..ad8ff7853 --- /dev/null +++ b/apps/puzzled/public/motifs/word-groups-zoom.svg @@ -0,0 +1 @@ + diff --git a/apps/puzzled/public/motifs/word-groups.svg b/apps/puzzled/public/motifs/word-groups.svg new file mode 100644 index 000000000..d6e763c1f --- /dev/null +++ b/apps/puzzled/public/motifs/word-groups.svg @@ -0,0 +1 @@ + diff --git a/apps/puzzled/public/motifs/word-guess-zoom.svg b/apps/puzzled/public/motifs/word-guess-zoom.svg new file mode 100644 index 000000000..dfc8b8c16 --- /dev/null +++ b/apps/puzzled/public/motifs/word-guess-zoom.svg @@ -0,0 +1 @@ + diff --git a/apps/puzzled/public/motifs/word-guess.svg b/apps/puzzled/public/motifs/word-guess.svg new file mode 100644 index 000000000..9461bddac --- /dev/null +++ b/apps/puzzled/public/motifs/word-guess.svg @@ -0,0 +1 @@ + diff --git a/apps/puzzled/public/motifs/word-hive-zoom.svg b/apps/puzzled/public/motifs/word-hive-zoom.svg new file mode 100644 index 000000000..d652d6d7c --- /dev/null +++ b/apps/puzzled/public/motifs/word-hive-zoom.svg @@ -0,0 +1 @@ + diff --git a/apps/puzzled/public/motifs/word-hive.svg b/apps/puzzled/public/motifs/word-hive.svg new file mode 100644 index 000000000..9cc0cca80 --- /dev/null +++ b/apps/puzzled/public/motifs/word-hive.svg @@ -0,0 +1 @@ + diff --git a/apps/puzzled/public/motifs/word-ladder-zoom.svg b/apps/puzzled/public/motifs/word-ladder-zoom.svg new file mode 100644 index 000000000..3e6558d7a --- /dev/null +++ b/apps/puzzled/public/motifs/word-ladder-zoom.svg @@ -0,0 +1 @@ + diff --git a/apps/puzzled/public/motifs/word-ladder.svg b/apps/puzzled/public/motifs/word-ladder.svg new file mode 100644 index 000000000..0d11dc5dc --- /dev/null +++ b/apps/puzzled/public/motifs/word-ladder.svg @@ -0,0 +1 @@ + diff --git a/apps/puzzled/public/motifs/word-search-zoom.svg b/apps/puzzled/public/motifs/word-search-zoom.svg new file mode 100644 index 000000000..4caf14baf --- /dev/null +++ b/apps/puzzled/public/motifs/word-search-zoom.svg @@ -0,0 +1 @@ + diff --git a/apps/puzzled/public/motifs/word-search.svg b/apps/puzzled/public/motifs/word-search.svg new file mode 100644 index 000000000..17c3d6f4c --- /dev/null +++ b/apps/puzzled/public/motifs/word-search.svg @@ -0,0 +1 @@ + diff --git a/apps/puzzled/public/offline.html b/apps/puzzled/public/offline.html index 9bd7af5f3..4d5ee41da 100644 --- a/apps/puzzled/public/offline.html +++ b/apps/puzzled/public/offline.html @@ -24,4 +24,4 @@ background: var(--ink); color: var(--paper); text-decoration: none; font-weight: 600; } a:focus-visible { outline: 2px solid var(--focus); outline-offset: 4px; } a:hover { opacity: .9; } -

You're offline

Tryit needs an internet connection to load puzzles and save finishes. Reconnect, then try again.

Try again
+

You're offline

Tryit needs an internet connection to load puzzles and save finishes. Reconnect, then try again.

Try again
diff --git a/apps/puzzled/scripts/generate-motifs.tsx b/apps/puzzled/scripts/generate-motifs.tsx new file mode 100644 index 000000000..84d17c837 --- /dev/null +++ b/apps/puzzled/scripts/generate-motifs.tsx @@ -0,0 +1,15 @@ +import { mkdirSync, writeFileSync } from 'node:fs' +import { renderToStaticMarkup } from 'react-dom/server' +import { GameMotif, MOTIF_SLUGS } from '../src/shared/components/games/game-motif' + +// Regenerate after changing a miniature in src/shared/components/games/game-motif.tsx. +const dir = new URL('../public/motifs/', import.meta.url) +mkdirSync(dir, { recursive: true }) +for (const slug of MOTIF_SLUGS) { + for (const zoom of [false, true]) { + writeFileSync( + new URL(`${slug}${zoom ? '-zoom' : ''}.svg`, dir), + `${renderToStaticMarkup()}\n`, + ) + } +} diff --git a/apps/puzzled/src/app/[locale]/(main)/archive/page.tsx b/apps/puzzled/src/app/[locale]/(main)/archive/page.tsx index e5adda62d..97e31d549 100644 --- a/apps/puzzled/src/app/[locale]/(main)/archive/page.tsx +++ b/apps/puzzled/src/app/[locale]/(main)/archive/page.tsx @@ -1,9 +1,9 @@ export const dynamic = 'force-dynamic' -import { CalendarDays } from 'lucide-react' import { getTranslations, setRequestLocale } from 'next-intl/server' import { AdSlot } from '@/features/ads/components/ad-slot' -import { ArchiveGrid } from '@/features/daily/components/archive-grid' +import { CATALOG_CATEGORIES } from '@/features/catalog/lib/catalog' +import { ArchiveAlmanac } from '@/features/daily/components/archive-almanac' import { ARCHIVE_WINDOW_DAYS, archiveDayKeys } from '@/features/daily/lib/archive-days' import { CheckoutOffer } from '@/features/plus-offer/components/checkout-offer' import { getAllGameMetadata } from '@/games/registry' @@ -47,6 +47,7 @@ export default async function ArchivePage({ params }: Props) { setRequestLocale(locale) const t = await getTranslations('archive') const tGames = await getTranslations('games') + const tCatalog = await getTranslations('catalog') const user = await withPresentationDeadline(currentUser(), null) const access = await withPresentationDeadline(getServerPlusAccess(Boolean(user?.id)), OPEN_ACCESS) const locked = access.salesOpen && !access.entitled @@ -55,54 +56,74 @@ export default async function ArchivePage({ params }: Props) { slug: game.slug, name: tGames(`${slugToCamelCase(game.slug)}.name`), theme: game.display.theme, + category: game.category, })) + const categories = CATALOG_CATEGORIES.filter((value) => + games.some((game) => game.category === value), + ).map((value) => ({ value, label: tCatalog(`category.${value}`) })) const days = archiveDayKeys(productDayKey()) return (
-
-
-
-

- {t('eyebrow')} -

-

{t('title')}

-

{t('body')}

- - {t('backToGames')} - -
+
+
+
+
+
+

{t('eyebrow')}

+

+ {t('title')} +

+

+ {t('listBody', { count: ARCHIVE_WINDOW_DAYS, games: games.length })} +

+
+ + {t('backToGames')} + +
+
+

+ {t('listTitle')} +

+ +
+
{locked ? ( - + ) : null}
-
-
-
-

- {t('listBody', { count: ARCHIVE_WINDOW_DAYS, games: games.length })} -

- -
{ads ? (
diff --git a/apps/puzzled/src/app/[locale]/(main)/games/[slug]/game-daily-fallback.tsx b/apps/puzzled/src/app/[locale]/(main)/games/[slug]/game-daily-fallback.tsx index 65b45a6cf..02bfa7fd5 100644 --- a/apps/puzzled/src/app/[locale]/(main)/games/[slug]/game-daily-fallback.tsx +++ b/apps/puzzled/src/app/[locale]/(main)/games/[slug]/game-daily-fallback.tsx @@ -2,9 +2,9 @@ import { ConnectError } from '@connectrpc/connect' import { Button } from '@sylphx/ui' -import { RotateCw } from 'lucide-react' +import { Play, RotateCw } from 'lucide-react' import { useTranslations } from 'next-intl' -import { type ReactNode, useEffect, useReducer, useRef, useState } from 'react' +import { type ReactNode, useCallback, useEffect, useReducer, useRef, useState } from 'react' import { AlreadyCompletedView } from '@/features/daily/components/already-completed-view' import { classifyDailyResponse, @@ -13,13 +13,17 @@ import { loadDailySnapshot, } from '@/features/daily/lib/daily-fallback' import { completedViewLevel } from '@/features/daily/lib/difficulty-completion' +import { takeStartIntent } from '@/features/daily/lib/start-intent' import type { GameSlug } from '@/games/how-to-play-registry' +import { type GameColorTheme, getGameColors } from '@/games/theme-colors' import type { PuzzleDifficulty } from '@/games/types' import { isPlusRequiredError } from '@/lib/billing/plus' import { startDaily } from '@/lib/connect/puzzle-client' import type { GameMode } from '@/lib/db/schema' import { Link } from '@/lib/i18n/routing' import { logger } from '@/lib/logger' +import { cn } from '@/lib/utils' +import { GameMotif } from '@/shared/components/games/game-motif' import { GamePageClient } from './game-page-client' type GameDailyFallbackProps = { @@ -35,6 +39,10 @@ type GameDailyFallbackProps = { unlock?: ReactNode /** Public metadata returned by SSR, without a playable payload. */ startDate?: string + /** The player arrived by pressing Play: the start card is the screen's one amber action. */ + started?: boolean + /** The game's colour field for the start card. */ + theme?: GameColorTheme currentStreak?: number } @@ -57,6 +65,8 @@ export function GameDailyFallback({ puzzleDate, unlock, startDate, + started = false, + theme = 'violet', currentStreak = 0, }: GameDailyFallbackProps) { const t = useTranslations('daily') @@ -71,25 +81,42 @@ export function GameDailyFallback({ const startPending = useRef(false) const [starting, setStarting] = useState(false) - async function play(date: string) { - if (startPending.current) return - startPending.current = true - setStarting(true) - try { - const daily = await startDaily({ gameSlug: slug, puzzleDate: date, difficulty }) - dispatch({ type: 'load-succeeded', snapshot: classifyDailyResponse(daily) }) - } catch (error) { - if (isPlusRequiredError(ConnectError.from(error).rawMessage)) { - dispatch({ type: 'load-refused' }) - } else { - logger.error('game-daily-fallback.start-failed', { error }) - dispatch({ type: 'load-failed' }) + const play = useCallback( + async (date: string) => { + if (startPending.current) return + startPending.current = true + setStarting(true) + try { + const daily = await startDaily({ gameSlug: slug, puzzleDate: date, difficulty }) + dispatch({ type: 'load-succeeded', snapshot: classifyDailyResponse(daily) }) + } catch (error) { + if (isPlusRequiredError(ConnectError.from(error).rawMessage)) { + dispatch({ type: 'load-refused' }) + } else { + logger.error('game-daily-fallback.start-failed', { error }) + dispatch({ type: 'load-failed' }) + } + } finally { + startPending.current = false + setStarting(false) } - } finally { - startPending.current = false - setStarting(false) - } - } + }, + [slug, difficulty], + ) + + // A Play press on the previous page is the explicit start: open the board + // now instead of asking twice. A pasted or crawled link carries no press + // (`start-intent.ts`), so it waits for the card's own button. + const startableDate = + state.status === 'ready' && state.snapshot.kind === 'startable' + ? state.snapshot.puzzleDate + : null + const autoStarted = useRef(false) + useEffect(() => { + if (!startableDate || autoStarted.current) return + autoStarted.current = true + if (takeStartIntent(slug)) void play(startableDate) + }, [startableDate, slug, play]) // `state.status` drives the fetch: retry moves error/unavailable back to // `loading`, which re-runs this effect without a hard navigation. @@ -135,21 +162,66 @@ export function GameDailyFallback({ const snapshot = state.status === 'ready' ? state.snapshot : null - if (snapshot?.kind === 'startable') { + if (snapshot?.kind === 'startable' && !started) { + // The game's own page: the hero already shows the board, so the start + // action is one compact strip under it. return ( -
+
+

+ {t('startUsesPick')} +

) } + if (snapshot?.kind === 'startable') { + const colors = getGameColors(theme) + return ( +
+ +
+ +

+ {t('startUsesPick')} +

+
+
+ ) + } + // Server-recorded finish: render the result, never a fresh board. if (snapshot?.kind === 'completed') { return ( @@ -201,7 +273,7 @@ export function GameDailyFallback({ // the puzzle that is ready. A retry would ask the same question again. if (snapshot?.kind === 'unavailable') { return ( -
+

{t('notReadyTitle', { game: gameName })}

@@ -224,7 +296,7 @@ export function GameDailyFallback({ // The fetch failed: a client-side retry. return ( -
+

{t('unavailableTitle')}

{t('unavailableDescription')}

) } diff --git a/apps/puzzled/src/app/[locale]/(main)/games/page.tsx b/apps/puzzled/src/app/[locale]/(main)/games/page.tsx index 0a2e3f788..787eb4b41 100644 --- a/apps/puzzled/src/app/[locale]/(main)/games/page.tsx +++ b/apps/puzzled/src/app/[locale]/(main)/games/page.tsx @@ -112,16 +112,16 @@ export default async function GamesCatalogPage({ params, searchParams }: Props) ) : (