From 5d9c07eb3a6bdede158724c9521ae66ee6128976 Mon Sep 17 00:00:00 2001 From: tresabhi <43380238+tresabhi@users.noreply.github.com> Date: Fri, 27 Nov 2026 14:57:39 -0600 Subject: [PATCH] migrate tier list --- CLAUDE.md | 68 ++++++ packages/core/src/blitzkit/api/cache.ts | 2 +- packages/core/src/blitzkit/index.ts | 2 +- .../{metaSortTank.ts => metaSortTanks.ts} | 2 +- packages/i18n/strings/en.json | 14 ++ .../components/AlertDialog/index.module.css | 7 - .../src/components/AlertDialog/index.tsx | 19 +- .../src/components/CompareControls/index.tsx | 5 +- .../CompareInsertionMarker/constants.ts | 4 - .../CompareInsertionMarker/index.module.css | 14 -- .../CompareInsertionMarker/index.tsx | 24 -- .../src/components/CompareTable/index.tsx | 93 ++++--- .../src/components/CompareTankCard/index.tsx | 62 +++-- .../src/components/CompareURLManager.astro | 42 ++++ .../src/components/Dialog/index.module.css | 11 - .../website/src/components/Dialog/index.tsx | 24 +- .../components/DialogActions/index.module.css | 7 + .../src/components/DialogActions/index.tsx | 8 + .../DialogBody/index.module.css} | 3 +- .../src/components/DialogBody/index.tsx | 8 + .../components/DialogField/index.module.css | 5 + .../src/components/DialogField/index.tsx | 24 ++ .../components/DialogHeader/index.module.css | 5 + .../src/components/DialogHeader/index.tsx | 8 + .../components/Embeds/GenerateURL/index.tsx | 13 +- .../Embeds/PreviewWrapper/index.tsx | 2 +- .../src/components/Embeds/breakdown.tsx | 2 +- .../src/components/HomeCosmetics.astro | 2 +- .../website/src/components/HomeGames.astro | 2 +- .../website/src/components/HomePlayers.astro | 2 +- .../website/src/components/HomeTanks.astro | 2 +- .../src/components/HomeTechnical.astro | 2 +- .../InsertionMarker/index.module.css | 24 ++ .../src/components/InsertionMarker/index.tsx | 15 ++ .../website/src/components/NavbarFine.astro | 2 +- .../src/components/Popover/index.module.css | 1 + .../website/src/components/Popover/index.tsx | 14 +- .../src/components/ScreenshotButton/index.tsx | 5 +- .../website/src/components/Table/index.tsx | 6 +- .../components/TankSearchResults/index.tsx | 4 +- .../components/TankSandbox/Title/index.tsx | 2 +- .../TankopediaSkinSwitcher/index.tsx | 2 +- .../src/components/TanksEmbed/index.tsx | 2 +- .../TierList/Controls/components/Share.tsx | 22 -- .../components/TierList/Controls/index.tsx | 27 --- .../TierList/Row/components/Header.tsx | 113 --------- .../src/components/TierList/Row/index.tsx | 53 ---- .../components/TierList/Table/constants.ts | 17 -- .../src/components/TierList/Table/index.tsx | 15 -- .../website/src/components/TierList/Tile.tsx | 211 ---------------- .../website/src/components/TierList/Tiles.tsx | 58 ----- .../src/components/TierList/URLManager.tsx | 34 --- .../TierListControls/index.module.css | 5 + .../src/components/TierListControls/index.tsx | 34 +++ .../components/TierListRow/index.module.css | 3 + .../src/components/TierListRow/index.tsx | 27 +++ .../TierListRowHeader/index.module.css | 35 +++ .../components/TierListRowHeader/index.tsx | 139 +++++++++++ .../components/TierListTable/index.module.css | 17 ++ .../src/components/TierListTable/index.tsx | 51 ++++ .../components/TierListTile/index.module.css | 11 + .../src/components/TierListTile/index.tsx | 227 ++++++++++++++++++ .../src/components/TierListTiles/index.tsx | 58 +++++ .../src/components/TierListURLManager.astro | 44 ++++ .../website/src/components/ToolBanner.astro | 2 +- .../website/src/components/ToolCard.astro | 2 +- .../src/components/ToolOpenGraph.astro | 2 +- packages/website/src/config/compare.ts | 4 + .../src/{constants => config}/dialog.ts | 0 .../src/{constants => config}/embeds.ts | 0 .../src/{constants => config}/navbar.ts | 0 .../src/{constants => config}/skinNumber.ts | 0 packages/website/src/config/tierList.ts | 41 ++++ .../src/{constants => config}/tools.ts | 5 +- .../core/blitzkit/generateTierListParams.ts | 11 - .../src/core/blitzkit/showInsertionMarker.ts | 24 ++ packages/website/src/layouts/BaseLayout.astro | 2 +- packages/website/src/pages/404.astro | 2 +- .../tools/[tool]/banners/[size].webp.ts | 2 +- .../[...locale]/auth/[provider]/_index.astro | 2 +- .../[...locale]/avatars/_index.astro | 2 +- .../[...locale]/compare/_index.tsx | 86 ------- .../[...locale]/compare/index.astro | 26 +- .../[...locale]/components.astro | 2 +- .../[...locale]/credits/_index.astro | 2 +- .../docs/[directory]/[document]/_index.astro | 2 +- .../[...locale]/docs/patches/_index.astro | 2 +- .../[...locale]/embed/[embed]/_index.tsx | 2 +- .../[...locale]/embed/[embed]/host/_index.tsx | 2 +- .../[...locale]/embed/[embed]/index.astro | 4 +- .../[...locale]/embed/_index.tsx | 2 +- .../[...locale]/embed/index.astro | 2 +- .../[...locale]/guesser/index.astro | 2 +- .../[...locale]/index.astro | 2 +- .../[...locale]/mixer/index.astro | 2 +- .../[...locale]/performance/index.astro | 2 +- .../[...locale]/playlist/_index.astro | 2 +- .../[...locale]/session/_index.astro | 2 +- .../[...locale]/tanks/[slug]/index.astro | 2 +- .../[...locale]/tanks/index.astro | 2 +- .../[...locale]/tier-list/_index.astro | 13 - .../[...locale]/tier-list/_index.tsx | 30 --- .../[...locale]/tier-list/index.astro | 45 ++++ .../tools/embed/[embed]/index.astro | 2 +- .../[id]/skins/[skin].glb.ts | 2 +- .../website/src/stores/compareEphemeral.ts | 14 +- .../src/stores/embedState/utilities.ts | 2 +- packages/website/src/stores/tierList.ts | 37 ++- 108 files changed, 1238 insertions(+), 922 deletions(-) create mode 100644 CLAUDE.md rename packages/core/src/blitzkit/{metaSortTank.ts => metaSortTanks.ts} (95%) delete mode 100644 packages/website/src/components/CompareInsertionMarker/constants.ts delete mode 100644 packages/website/src/components/CompareInsertionMarker/index.module.css delete mode 100644 packages/website/src/components/CompareInsertionMarker/index.tsx create mode 100644 packages/website/src/components/CompareURLManager.astro create mode 100644 packages/website/src/components/DialogActions/index.module.css create mode 100644 packages/website/src/components/DialogActions/index.tsx rename packages/website/src/{pages/[...chunk_default]/[...locale]/compare/_index.module.css => components/DialogBody/index.module.css} (69%) create mode 100644 packages/website/src/components/DialogBody/index.tsx create mode 100644 packages/website/src/components/DialogField/index.module.css create mode 100644 packages/website/src/components/DialogField/index.tsx create mode 100644 packages/website/src/components/DialogHeader/index.module.css create mode 100644 packages/website/src/components/DialogHeader/index.tsx create mode 100644 packages/website/src/components/InsertionMarker/index.module.css create mode 100644 packages/website/src/components/InsertionMarker/index.tsx delete mode 100644 packages/website/src/components/TierList/Controls/components/Share.tsx delete mode 100644 packages/website/src/components/TierList/Controls/index.tsx delete mode 100644 packages/website/src/components/TierList/Row/components/Header.tsx delete mode 100644 packages/website/src/components/TierList/Row/index.tsx delete mode 100644 packages/website/src/components/TierList/Table/constants.ts delete mode 100644 packages/website/src/components/TierList/Table/index.tsx delete mode 100644 packages/website/src/components/TierList/Tile.tsx delete mode 100644 packages/website/src/components/TierList/Tiles.tsx delete mode 100644 packages/website/src/components/TierList/URLManager.tsx create mode 100644 packages/website/src/components/TierListControls/index.module.css create mode 100644 packages/website/src/components/TierListControls/index.tsx create mode 100644 packages/website/src/components/TierListRow/index.module.css create mode 100644 packages/website/src/components/TierListRow/index.tsx create mode 100644 packages/website/src/components/TierListRowHeader/index.module.css create mode 100644 packages/website/src/components/TierListRowHeader/index.tsx create mode 100644 packages/website/src/components/TierListTable/index.module.css create mode 100644 packages/website/src/components/TierListTable/index.tsx create mode 100644 packages/website/src/components/TierListTile/index.module.css create mode 100644 packages/website/src/components/TierListTile/index.tsx create mode 100644 packages/website/src/components/TierListTiles/index.tsx create mode 100644 packages/website/src/components/TierListURLManager.astro create mode 100644 packages/website/src/config/compare.ts rename packages/website/src/{constants => config}/dialog.ts (100%) rename packages/website/src/{constants => config}/embeds.ts (100%) rename packages/website/src/{constants => config}/navbar.ts (100%) rename packages/website/src/{constants => config}/skinNumber.ts (100%) create mode 100644 packages/website/src/config/tierList.ts rename packages/website/src/{constants => config}/tools.ts (95%) delete mode 100644 packages/website/src/core/blitzkit/generateTierListParams.ts create mode 100644 packages/website/src/core/blitzkit/showInsertionMarker.ts delete mode 100644 packages/website/src/pages/[...chunk_default]/[...locale]/compare/_index.tsx delete mode 100644 packages/website/src/pages/[...chunk_default]/[...locale]/tier-list/_index.astro delete mode 100644 packages/website/src/pages/[...chunk_default]/[...locale]/tier-list/_index.tsx create mode 100644 packages/website/src/pages/[...chunk_default]/[...locale]/tier-list/index.astro diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 000000000..2d1f10048 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,68 @@ +# BlitzKit + +## Git + +- Never commit or push. +- Never stage (`git add`, `git mv`, ...) unless the maintainer asks for it. The one exception is deletions: deleted files may always be staged (`git rm`, `git add` on a removed path). +- Move files with plain `mv`, not `git mv`. + +## Migration + +The `data-driven` branch is migrating off the old system (Radix Themes, the `Duel` store, `PageWrapper`, ...) onto the new components and stores (`Tankopedia`, `Soapstone` stores, `components/Button`, ...). Leftover references to the old system are expected bugs: when something is undefined or a module is missing, look for its replacement in neighboring migrated code rather than restoring the old one. + +Pages that are not migrated yet are named `_index.astro` so Astro skips them. Migrating one renames it to `index.astro`. + +## Layout + +- Components live flat at `src/components/Name/index.tsx` with `index.module.css` beside it. No flat `Name.tsx` files and no nested `components/Parent/components/Child` folders: a sub-component becomes its own top-level folder prefixed with its feature, e.g. `MixerScene/components/Model.tsx` becomes `components/MixerModel/index.tsx`. +- Pages keep their styles in `_index.module.css` next to `_index.tsx`. + +## TypeScript + +- No return type annotations. Put `satisfies Type` on the returned expression instead. +- Wrap functions defined inside React components in `useCallback`. +- Never inline a complex type (a union of object shapes, etc.) in a signature; name it as an interface or type. +- In object literals, `...spread` entries come first, each on its own line, followed by a blank line, then the custom entries. A single-line object with a spread becomes multi-line. +- When an object literal's values are long expressions, compute them first into `const`s named after their keys, then build the object with shorthand (`{ name, color, tanks: [] }`). Short values stay inline. +- Always hoist values that take work to compute (a function call, math, a lookup, like `"A".charCodeAt(0)` or `1 - SCROLL_ZONE`) and don't change between iterations or calls out of loops and repeatedly called functions into a `const` above them. No exceptions. Plain literals (strings, numbers, selectors like `"[data-row]"`) cost nothing and stay inline. +- A helper function used in only one place gets inlined there. Only extract a function once it has a second caller. +- Assert data that is known to be present with `!` instead of `?.` or `?? 0`; crashing beats silently showing a plausible wrong value. Keep `?.` only where absence is real logic: `optional` proto fields (check the `.proto`), optional script effect fields, and lookups that can legitimately miss. +- Single-line comments use `//`, never `/** */`. Keep `/** */` for multi-line doc comments. + +## JSX + +- An icon and its text go on separate lines, never ` {label}` on one line. Spacing comes from the parent's flex `gap`, not a literal space: + + ```tsx + + {label} + ``` + +- In menu-like items (ContextMenu, DropdownMenu, Select and similar), the icon goes after the text. `ItemIndicator` stays in the left gutter. +- Don't add `aria-label` (or replacements like `aria-labelledby`) for now. + +## CSS + +- Constant CSS goes in the CSS module, never in `style={{ }}`. Only runtime values (measured sizes, user settings) go inline; split an element's constant and dynamic styles between the two. Presentational props like `width="1em"` on icons are CSS too. +- Toggle state and variants with data attributes (`data-split={bool}` with `.x[data-split="true"]`), never conditional modifier classes. +- CSS module classes are kebab-case, accessed as `styles["tank-image"]`. PascalCase is only for Radix part names in composed components. +- Containers own the padding and space their children with a flex `gap`. Children like `Header`, `Body` and `Actions` don't carry padding to fake spacing; fix the container instead. +- Select elements by their own class, never by structure or tag (`> *`, `> div`, `:first-child`, bare `svg`, `[data-x] > *`). If an element needs styling, give it a class and nest that class under its parent. The exception is content a component renders internally that has no `className` to pass, like the icon inside an `IconButton` (`.swatch svg`). +- Nest CSS to mirror the markup: a child's rules go inside its parent's block (`.marker { .bar { } }`), so the stylesheet reads like the HTML tree. +- Fully rounded corners use `var(--radius-max)`, never `var(--max-size)`. +- `z-index` stays at `1` unless a real overlap needs more. + +## Components + +- Dialog-like surfaces (`Dialog`, `AlertDialog`, `Popover`) share their extra parts, which live as their own top-level components: `DialogHeader`, `DialogBody`, `DialogActions` and `DialogField` (a labeled control, taking a `label` prop). Each surface attaches them as `X.Header`, `X.Body`, `X.Actions` and `X.Field`; none defines its own copy. Fix their spacing in the part's own CSS module. +- Other extra non-Radix parts of a composed component are local functions in that component's `index.tsx`, `function Name({ className, ...props }: ComponentProps<"div">)` using `classNames(styles["kebab-class"], className)`, spread in with `{ ...composeRadixComponents(_, styles), Name }`. Once a part is shared by several components, it moves out into its own top-level component instead, like the `Dialog*` parts. A part shared across menus (`Discriminator` in DropdownMenu) is styled through a data attribute, since CSS modules re-hash classes per importing file. + +## Strings and naming + +- Only edit `packages/i18n/strings/en.json`. Other locales are managed by Crowdin; never touch them, even for key renames. +- Name strings and keys after what the game UI calls things (its English strings), not code or XML names. Tier 11 upgrade progression is "augments" everywhere in BlitzKit; "upgrade" stays only where it names a game file, folder or XML tag, and for the modules panel. +- Characteristic group keys follow the UI title (`nitro`, `combat_stabilization`), and item keys are prefixed with their group key (`steady_aim_system_duration`). Item labels stay short and drop what the group title already says. + +## Endpoints + +- The site is built statically, so Astro endpoint handlers return `new Response(body)` with no `headers`. The file extension decides the type. diff --git a/packages/core/src/blitzkit/api/cache.ts b/packages/core/src/blitzkit/api/cache.ts index 2ac5bcf98..ddf88ffad 100644 --- a/packages/core/src/blitzkit/api/cache.ts +++ b/packages/core/src/blitzkit/api/cache.ts @@ -2,7 +2,7 @@ export function Cache(disableInDev = false) { const cache = new WeakMap>>(); return function ( - target: (this: This, ...args: Arguments) => Promise + target: (this: This, ...args: Arguments) => Promise, // TODO: evaluate if we need context to make the error trace easier // context: ClassMethodDecoratorContext< // This, diff --git a/packages/core/src/blitzkit/index.ts b/packages/core/src/blitzkit/index.ts index 6a68c4d81..3545dbf76 100644 --- a/packages/core/src/blitzkit/index.ts +++ b/packages/core/src/blitzkit/index.ts @@ -13,7 +13,7 @@ export * from "./environment"; export * from "./eventManager"; export * from "./getTimeDaysAgo"; export * from "./isExplosive"; -export * from "./metaSortTank"; +export * from "./metaSortTanks"; export * from "./normalizeBoundingBox"; export * from "./patientFetchJSON"; export * from "./popularTanks"; diff --git a/packages/core/src/blitzkit/metaSortTank.ts b/packages/core/src/blitzkit/metaSortTanks.ts similarity index 95% rename from packages/core/src/blitzkit/metaSortTank.ts rename to packages/core/src/blitzkit/metaSortTanks.ts index 8f520cd4c..4d9001338 100644 --- a/packages/core/src/blitzkit/metaSortTank.ts +++ b/packages/core/src/blitzkit/metaSortTanks.ts @@ -2,7 +2,7 @@ import { GameDefinitions, TankDefinition } from "@blitzkit/protos"; import { tankClassOrder } from "../config/tankClassOrder"; import { treeTypeOrder } from "../config/treeTypeOrder"; -export function metaSortTank( +export function metaSortTanks( tanks: TankDefinition[], gameDefinitions: GameDefinitions, ) { diff --git a/packages/i18n/strings/en.json b/packages/i18n/strings/en.json index 3ac713e18..c337db9d2 100644 --- a/packages/i18n/strings/en.json +++ b/packages/i18n/strings/en.json @@ -155,6 +155,20 @@ } }, + "tier_list": { + "add": "Add tier", + "reset": "Reset", + "share": "Share", + "edit": { + "placeholder": "Tier name", + "label": "Label", + "color": "Color", + "remove": "Remove", + "cancel": "Cancel", + "apply": "Apply" + } + }, + "units": { "m": "{value}m", "mm": "{value}mm", diff --git a/packages/website/src/components/AlertDialog/index.module.css b/packages/website/src/components/AlertDialog/index.module.css index f02ab0506..2bab8b266 100644 --- a/packages/website/src/components/AlertDialog/index.module.css +++ b/packages/website/src/components/AlertDialog/index.module.css @@ -39,10 +39,3 @@ color: var(--gray-11); } -.actions { - display: flex; - justify-content: flex-end; - gap: var(--space-3); - - margin-top: var(--space-3); -} diff --git a/packages/website/src/components/AlertDialog/index.tsx b/packages/website/src/components/AlertDialog/index.tsx index 0845f9395..aa1e93cef 100644 --- a/packages/website/src/components/AlertDialog/index.tsx +++ b/packages/website/src/components/AlertDialog/index.tsx @@ -1,11 +1,18 @@ import { AlertDialog as _ } from "radix-ui"; -import type { ComponentProps } from "react"; -import { classNames } from "../../ui/classNames"; import { composeRadixComponents } from "../../ui/compose"; +import { DialogActions } from "../DialogActions"; +import { DialogBody } from "../DialogBody"; +import { DialogField } from "../DialogField"; +import { DialogHeader } from "../DialogHeader"; import styles from "./index.module.css"; -function Actions({ className, ...props }: ComponentProps<"div">) { - return
; -} +// TODO: figoure out tree shaking for these kinds of wrapped components +// The extra parts live in their own components, shared by every dialog-like surface +export const AlertDialog = { + ...composeRadixComponents(_, styles), -export const AlertDialog = { ...composeRadixComponents(_, styles), Actions }; + Header: DialogHeader, + Body: DialogBody, + Actions: DialogActions, + Field: DialogField, +}; diff --git a/packages/website/src/components/CompareControls/index.tsx b/packages/website/src/components/CompareControls/index.tsx index 6122e2ea2..9606718de 100644 --- a/packages/website/src/components/CompareControls/index.tsx +++ b/packages/website/src/components/CompareControls/index.tsx @@ -1,6 +1,7 @@ import { PlusIcon, TrashIcon } from "@radix-ui/react-icons"; import { useMemo, useState } from "react"; import { tankToCompareMember } from "../../core/blitzkit/tankToCompareMember"; +import { withLocale } from "../../hocs/withLocale"; import { useStrings } from "../../hooks/useStrings"; import { CompareEphemeral, syncShellSlot } from "../../stores/compareEphemeral"; import { @@ -15,7 +16,9 @@ import { SegmentedControl } from "../SegmentedControl"; import { TankSearchResults } from "../TankSearchResults"; import styles from "./index.module.css"; -export function CompareControls() { +export const CompareControls = withLocale(Content); + +function Content() { const strings = useStrings(); const deltaMode = ComparePersistent.use((state) => state.deltaMode); const syncShells = CompareEphemeral.use((state) => state.syncShells); diff --git a/packages/website/src/components/CompareInsertionMarker/constants.ts b/packages/website/src/components/CompareInsertionMarker/constants.ts deleted file mode 100644 index 6eb066645..000000000 --- a/packages/website/src/components/CompareInsertionMarker/constants.ts +++ /dev/null @@ -1,4 +0,0 @@ -export const insertionMarkers = new Set<{ - element: HTMLDivElement; - index: number; -}>(); diff --git a/packages/website/src/components/CompareInsertionMarker/index.module.css b/packages/website/src/components/CompareInsertionMarker/index.module.css deleted file mode 100644 index 39a84a193..000000000 --- a/packages/website/src/components/CompareInsertionMarker/index.module.css +++ /dev/null @@ -1,14 +0,0 @@ -.marker { - position: absolute; - right: 0; - top: 50%; - transform: translateY(-50%); - - height: calc(100% - 2 * var(--space-4)); - width: var(--space-1); - - border-radius: var(--radius-max); - background-color: var(--accent-12); - - opacity: 0; -} diff --git a/packages/website/src/components/CompareInsertionMarker/index.tsx b/packages/website/src/components/CompareInsertionMarker/index.tsx deleted file mode 100644 index 447ea9c07..000000000 --- a/packages/website/src/components/CompareInsertionMarker/index.tsx +++ /dev/null @@ -1,24 +0,0 @@ -import { useEffect, useRef } from "react"; -import { insertionMarkers } from "./constants"; -import styles from "./index.module.css"; - -interface CompareInsertionMarkerProps { - index: number; -} - -export function CompareInsertionMarker({ index }: CompareInsertionMarkerProps) { - const marker = useRef(null); - - useEffect(() => { - const element = marker.current!; - const insertionMarker = { element, index }; - - insertionMarkers.add(insertionMarker); - - return () => { - insertionMarkers.delete(insertionMarker); - }; - }, [index]); - - return
; -} diff --git a/packages/website/src/components/CompareTable/index.tsx b/packages/website/src/components/CompareTable/index.tsx index cb3569b18..ac5f8318e 100644 --- a/packages/website/src/components/CompareTable/index.tsx +++ b/packages/website/src/components/CompareTable/index.tsx @@ -7,7 +7,9 @@ import { } from "@radix-ui/react-icons"; import { useMemo } from "react"; import { characteristicsGroups } from "../../config/characteristicsGroups"; +import { compareInsertionMarker } from "../../config/compare"; import { computeCharacteristics } from "../../hooks/useCharacteristics"; +import { withLocale } from "../../hocs/withLocale"; import { useStrings } from "../../hooks/useStrings"; import { useUnwrapper } from "../../hooks/useUnwrapper"; import { @@ -26,10 +28,11 @@ import { } from "../../types/characteristics"; import { CharacteristicValue } from "../CharacteristicValue"; import { CompareEnvironment } from "../CompareEnvironment"; -import { CompareInsertionMarker } from "../CompareInsertionMarker"; import { CompareLoadout } from "../CompareLoadout"; import { CompareTankCard } from "../CompareTankCard"; +import { EmptyState } from "../EmptyState"; import { IconButton } from "../IconButton"; +import { InsertionMarker } from "../InsertionMarker"; import { LazyImage } from "../LazyImage"; import { Table } from "../Table"; import { Text } from "../Text"; @@ -47,8 +50,15 @@ function without(ids: number[], excluded: number[]) { return remaining; } -export function CompareTable() { - const members = CompareEphemeral.use((state) => state.members); +// The table of members, or an empty state when there are none +export const CompareTable = withLocale(Content); + +function Content() { + const strings = useStrings(); + const members = CompareEphemeral.useDeferred( + (state) => state.members, + CompareEphemeral.initial.members, + ); const environment = CompareEphemeral.use((state) => state.environment); // Other tanks' consumables and provisions can reduce a tank's damage, so each @@ -74,44 +84,55 @@ export function CompareTable() { }); }, [members, environment]); + if (members.length === 0) { + return ( + + ); + } + return ( - - - - - - + <> + + + + - {members.map(({ key, state }, index) => ( - - ))} - - + {members.map(({ key, state }, index) => ( + + ))} + + - - - - - + + + + + - {members.map((member, index) => ( - - ))} - - + {members.map((member, index) => ( + + ))} + + - {characteristicsGroups.map((group) => ( - - ))} - + {characteristicsGroups.map((group) => ( + + ))} + + + + ); } diff --git a/packages/website/src/components/CompareTankCard/index.tsx b/packages/website/src/components/CompareTankCard/index.tsx index 093a3a0ba..7da23c7d4 100644 --- a/packages/website/src/components/CompareTankCard/index.tsx +++ b/packages/website/src/components/CompareTankCard/index.tsx @@ -2,10 +2,10 @@ import { tankIcon } from "@blitzkit/core"; import type { TankDefinition } from "@blitzkit/protos"; import { useEffect, useRef } from "react"; import { Vector2 } from "three"; +import { compareInsertionMarker } from "../../config/compare"; +import { showInsertionMarker } from "../../core/blitzkit/showInsertionMarker"; import { useUnwrapper } from "../../hooks/useUnwrapper"; import { CompareEphemeral } from "../../stores/compareEphemeral"; -import { CompareInsertionMarker } from "../CompareInsertionMarker"; -import { insertionMarkers } from "../CompareInsertionMarker/constants"; import { CompareTankControl } from "../CompareTankControl"; import { LazyImage } from "../LazyImage"; import { Table } from "../Table"; @@ -24,9 +24,7 @@ export function CompareTankCard({ index, tank }: TankCardProps) { useEffect(() => { const initial = new Vector2(); - const current = new Vector2(); - const delta = new Vector2(); - const marker = new Vector2(); + const offset = new Vector2(); let initialRect = draggable.current!.getBoundingClientRect(); let dropIndex = -1; @@ -34,48 +32,44 @@ export function CompareTankCard({ index, tank }: TankCardProps) { event.preventDefault(); initialRect = draggable.current!.getBoundingClientRect(); + initial.set(event.clientX, event.clientY); - delta.set(0, 0); - current.copy(initial.set(event.clientX, event.clientY)); window.addEventListener("pointermove", handlePointerMove); window.addEventListener("pointerup", handlePointerUp); } function handlePointerMove(event: PointerEvent) { event.preventDefault(); - current.set(event.clientX, event.clientY); - delta.copy(current).sub(initial); - insertionMarkers.forEach(({ element }) => { - element.style.opacity = "0"; + // Slot i sits on the right edge of the row's i-th cell: the corner, then each card + const cells = header.current!.parentElement!.children; + let closestRect = cells[0].getBoundingClientRect(); + let closestDistance = Infinity; + + for (let cell = 0; cell < cells.length; cell++) { + const rect = cells[cell].getBoundingClientRect(); + const distance = Math.abs(rect.right - event.clientX); + + if (distance >= closestDistance) continue; + + dropIndex = cell; + closestRect = rect; + closestDistance = distance; + } + + showInsertionMarker(compareInsertionMarker.current!, { + position: [closestRect.right, closestRect.top], + height: closestRect.height, }); - - const distances = Array.from(insertionMarkers, (insertionMarker) => { - const markerBounds = insertionMarker.element.getBoundingClientRect(); - marker.set(markerBounds.left, markerBounds.top); - - return { - ...insertionMarker, - distance: marker.distanceTo(current), - }; - }); - const closest = distances.reduce((a, b) => - a.distance < b.distance ? a : b, - ); - - dropIndex = closest.index; - closest.element.style.opacity = "1"; header.current!.dataset.dragging = "true"; - draggable.current!.style.left = `${initialRect.left + delta.x}px`; - draggable.current!.style.top = `${initialRect.top + delta.y}px`; + offset.set(event.clientX, event.clientY).sub(initial); + draggable.current!.style.left = `${initialRect.left + offset.x}px`; + draggable.current!.style.top = `${initialRect.top + offset.y}px`; } function handlePointerUp(event: PointerEvent) { event.preventDefault(); delete header.current!.dataset.dragging; - - insertionMarkers.forEach(({ element }) => { - element.style.opacity = "0"; - }); + showInsertionMarker(compareInsertionMarker.current!, undefined); window.removeEventListener("pointermove", handlePointerMove); window.removeEventListener("pointerup", handlePointerUp); @@ -119,8 +113,6 @@ export function CompareTankCard({ index, tank }: TankCardProps) { {unwrap(tank.name!)}
- - ); } diff --git a/packages/website/src/components/CompareURLManager.astro b/packages/website/src/components/CompareURLManager.astro new file mode 100644 index 000000000..18a76a070 --- /dev/null +++ b/packages/website/src/components/CompareURLManager.astro @@ -0,0 +1,42 @@ + + diff --git a/packages/website/src/components/Dialog/index.module.css b/packages/website/src/components/Dialog/index.module.css index ae48503a7..761da6db8 100644 --- a/packages/website/src/components/Dialog/index.module.css +++ b/packages/website/src/components/Dialog/index.module.css @@ -42,14 +42,3 @@ text-align: left; } -.header { - display: flex; - flex-direction: column; - gap: var(--space-2); -} - -.body { - display: flex; - flex-direction: column; - gap: var(--space-4); -} diff --git a/packages/website/src/components/Dialog/index.tsx b/packages/website/src/components/Dialog/index.tsx index f0a4082bb..cda953477 100644 --- a/packages/website/src/components/Dialog/index.tsx +++ b/packages/website/src/components/Dialog/index.tsx @@ -1,17 +1,17 @@ import { Dialog as _ } from "radix-ui"; -import type { ComponentProps } from "react"; -import { classNames } from "../../ui/classNames"; import { composeRadixComponents } from "../../ui/compose"; +import { DialogActions } from "../DialogActions"; +import { DialogBody } from "../DialogBody"; +import { DialogField } from "../DialogField"; +import { DialogHeader } from "../DialogHeader"; import styles from "./index.module.css"; -// Groups a title and description -function Header({ className, ...props }: ComponentProps<"div">) { - return
; -} +// The extra parts live in their own components, shared by every dialog-like surface +export const Dialog = { + ...composeRadixComponents(_, styles), -// Stacks the content that follows the header -function Body({ className, ...props }: ComponentProps<"div">) { - return
; -} - -export const Dialog = { ...composeRadixComponents(_, styles), Header, Body }; + Header: DialogHeader, + Body: DialogBody, + Actions: DialogActions, + Field: DialogField, +}; diff --git a/packages/website/src/components/DialogActions/index.module.css b/packages/website/src/components/DialogActions/index.module.css new file mode 100644 index 000000000..433b59454 --- /dev/null +++ b/packages/website/src/components/DialogActions/index.module.css @@ -0,0 +1,7 @@ +.actions { + display: flex; + justify-content: flex-end; + gap: var(--space-3); + + margin-top: var(--space-3); +} diff --git a/packages/website/src/components/DialogActions/index.tsx b/packages/website/src/components/DialogActions/index.tsx new file mode 100644 index 000000000..206fa14e8 --- /dev/null +++ b/packages/website/src/components/DialogActions/index.tsx @@ -0,0 +1,8 @@ +import type { ComponentProps } from "react"; +import { classNames } from "../../ui/classNames"; +import styles from "./index.module.css"; + +// The row of buttons that closes things out +export function DialogActions({ className, ...props }: ComponentProps<"div">) { + return
; +} diff --git a/packages/website/src/pages/[...chunk_default]/[...locale]/compare/_index.module.css b/packages/website/src/components/DialogBody/index.module.css similarity index 69% rename from packages/website/src/pages/[...chunk_default]/[...locale]/compare/_index.module.css rename to packages/website/src/components/DialogBody/index.module.css index d221ecf5f..eae85dee6 100644 --- a/packages/website/src/pages/[...chunk_default]/[...locale]/compare/_index.module.css +++ b/packages/website/src/components/DialogBody/index.module.css @@ -1,6 +1,5 @@ -.top { +.body { display: flex; flex-direction: column; - align-items: center; gap: var(--space-4); } diff --git a/packages/website/src/components/DialogBody/index.tsx b/packages/website/src/components/DialogBody/index.tsx new file mode 100644 index 000000000..3f8040940 --- /dev/null +++ b/packages/website/src/components/DialogBody/index.tsx @@ -0,0 +1,8 @@ +import type { ComponentProps } from "react"; +import { classNames } from "../../ui/classNames"; +import styles from "./index.module.css"; + +// Stacks the content that follows the header +export function DialogBody({ className, ...props }: ComponentProps<"div">) { + return
; +} diff --git a/packages/website/src/components/DialogField/index.module.css b/packages/website/src/components/DialogField/index.module.css new file mode 100644 index 000000000..53804c3f6 --- /dev/null +++ b/packages/website/src/components/DialogField/index.module.css @@ -0,0 +1,5 @@ +.field { + display: flex; + flex-direction: column; + gap: var(--space-3); +} diff --git a/packages/website/src/components/DialogField/index.tsx b/packages/website/src/components/DialogField/index.tsx new file mode 100644 index 000000000..a01409b3e --- /dev/null +++ b/packages/website/src/components/DialogField/index.tsx @@ -0,0 +1,24 @@ +import type { ComponentProps, ReactNode } from "react"; +import { classNames } from "../../ui/classNames"; +import { Text } from "../Text"; +import styles from "./index.module.css"; + +interface DialogFieldProps extends ComponentProps<"div"> { + label: ReactNode; +} + +// Stacks a label over the control it names +// TODO: figoure out the semantics of this +export function DialogField({ + className, + label, + children, + ...props +}: DialogFieldProps) { + return ( +
+ {label} + {children} +
+ ); +} diff --git a/packages/website/src/components/DialogHeader/index.module.css b/packages/website/src/components/DialogHeader/index.module.css new file mode 100644 index 000000000..28b67b3cf --- /dev/null +++ b/packages/website/src/components/DialogHeader/index.module.css @@ -0,0 +1,5 @@ +.header { + display: flex; + flex-direction: column; + gap: var(--space-2); +} diff --git a/packages/website/src/components/DialogHeader/index.tsx b/packages/website/src/components/DialogHeader/index.tsx new file mode 100644 index 000000000..6a42b3afd --- /dev/null +++ b/packages/website/src/components/DialogHeader/index.tsx @@ -0,0 +1,8 @@ +import type { ComponentProps } from "react"; +import { classNames } from "../../ui/classNames"; +import styles from "./index.module.css"; + +// Groups a title and description +export function DialogHeader({ className, ...props }: ComponentProps<"div">) { + return
; +} diff --git a/packages/website/src/components/Embeds/GenerateURL/index.tsx b/packages/website/src/components/Embeds/GenerateURL/index.tsx index 13dfe6a53..16e50990d 100644 --- a/packages/website/src/components/Embeds/GenerateURL/index.tsx +++ b/packages/website/src/components/Embeds/GenerateURL/index.tsx @@ -8,10 +8,9 @@ import { CaretLeftIcon, Link2Icon, PersonIcon } from "@radix-ui/react-icons"; import { debounce } from "lodash-es"; import { useCallback, useRef, useState } from "react"; import { stringify } from "urlon"; -import type { embedConfigurations } from "../../../constants/embeds"; +import type { embedConfigurations } from "../../../config/embeds"; import { useStrings } from "../../../hooks/useStrings"; import { EmbedState, type EmbedStateStore } from "../../../stores/embedState"; -import { AlertDialog } from "../../AlertDialog"; import { Button } from "../../Button"; import { CopyButton } from "../../CopyButton"; import { Dialog } from "../../Dialog"; @@ -51,7 +50,7 @@ export function GenerateURL({ embed }: GenerateURLProps) { setSearching(false); setResults(results); }, 500), - [] + [], ); const handleChange = useCallback(() => { @@ -130,13 +129,13 @@ export function GenerateURL({ embed }: GenerateURLProps) {
- + - + @@ -154,7 +153,7 @@ export function GenerateURL({ embed }: GenerateURLProps) { - + - + diff --git a/packages/website/src/components/Table/index.tsx b/packages/website/src/components/Table/index.tsx index f8c95b5a0..91271c64a 100644 --- a/packages/website/src/components/Table/index.tsx +++ b/packages/website/src/components/Table/index.tsx @@ -40,7 +40,11 @@ function Root({ children, className, ...props }: RootProps) { }, []); return ( - +
{children}
); diff --git a/packages/website/src/components/TankSearchResults/index.tsx b/packages/website/src/components/TankSearchResults/index.tsx index b9ed4e9e9..df2aacf70 100644 --- a/packages/website/src/components/TankSearchResults/index.tsx +++ b/packages/website/src/components/TankSearchResults/index.tsx @@ -1,4 +1,4 @@ -import { metaSortTank, SEARCH_KEYS } from "@blitzkit/core"; +import { metaSortTanks, SEARCH_KEYS } from "@blitzkit/core"; import { literals } from "@blitzkit/i18n/src/literals"; import type { TankDefinition } from "@blitzkit/protos"; import fuzzysort from "fuzzysort"; @@ -108,7 +108,7 @@ function Content({ onSelect, onSelectAll }: TankSearchResultsProps) { tankopediaSort.by === null || !sortableCharacteristics.has(tankopediaSort.by) ) { - const byMeta = metaSortTank([...filtered], gameDefinitions); + const byMeta = metaSortTanks([...filtered], gameDefinitions); return tankopediaSort.direction === SortDirection.Ascending ? byMeta diff --git a/packages/website/src/components/Tankopedia/HeroSection/components/TankSandbox/Title/index.tsx b/packages/website/src/components/Tankopedia/HeroSection/components/TankSandbox/Title/index.tsx index d8ed0dfd6..810b0f4b2 100644 --- a/packages/website/src/components/Tankopedia/HeroSection/components/TankSandbox/Title/index.tsx +++ b/packages/website/src/components/Tankopedia/HeroSection/components/TankSandbox/Title/index.tsx @@ -1,7 +1,7 @@ import { UpdateIcon } from "@radix-ui/react-icons"; import { Button, Flex, Heading } from "@radix-ui/themes"; import { useEffect, useRef } from "react"; -import { SKIN_NUMBER } from "../../../../../../constants/skinNumber"; +import { SKIN_NUMBER } from "../../../../../../config/skinNumber"; import { api } from "../../../../../../core/blitzkit/api"; import { useLocale } from "../../../../../../hooks/useLocale"; import { Duel } from "../../../../../../stores/duel"; diff --git a/packages/website/src/components/TankopediaSkinSwitcher/index.tsx b/packages/website/src/components/TankopediaSkinSwitcher/index.tsx index af78dd71a..f7a6be030 100644 --- a/packages/website/src/components/TankopediaSkinSwitcher/index.tsx +++ b/packages/website/src/components/TankopediaSkinSwitcher/index.tsx @@ -2,7 +2,7 @@ import { alias } from "@blitzkit/core"; import { PauseIcon, PlayIcon } from "@radix-ui/react-icons"; import { uniqBy } from "lodash-es"; import { api } from "../../api/dynamic"; -import { SKIN_NUMBER } from "../../constants/skinNumber"; +import { SKIN_NUMBER } from "../../config/skinNumber"; import { useAbsoluteDisplay } from "../../hooks/useAbsoluteDisplay"; import { useDuelModules } from "../../hooks/useDuelModules"; import { hasSkinAnimations } from "../../hooks/useSkin"; diff --git a/packages/website/src/components/TanksEmbed/index.tsx b/packages/website/src/components/TanksEmbed/index.tsx index 26fc0629f..b31f73cfb 100644 --- a/packages/website/src/components/TanksEmbed/index.tsx +++ b/packages/website/src/components/TanksEmbed/index.tsx @@ -8,7 +8,7 @@ import { TankClass, TankDefinition, TankType } from "@blitzkit/protos"; import { amberDark, blueDark } from "@radix-ui/colors"; import { times } from "lodash-es"; import type { ComponentProps } from "react"; -import { breakdownConfig } from "../../constants/embeds"; +import { breakdownConfig } from "../../config/embeds"; import { useUnwrapper } from "../../hooks/useUnwrapper"; import { embedRadius, embedSpace } from "../../stores/embedState/tokens"; import { useEmbedStateCurry } from "../../stores/embedState/utilities"; diff --git a/packages/website/src/components/TierList/Controls/components/Share.tsx b/packages/website/src/components/TierList/Controls/components/Share.tsx deleted file mode 100644 index 14f7fa16c..000000000 --- a/packages/website/src/components/TierList/Controls/components/Share.tsx +++ /dev/null @@ -1,22 +0,0 @@ -import { Share2Icon } from '@radix-ui/react-icons'; -import { generateTierListParams } from '../../../../core/blitzkit/generateTierListParams'; -import { useLocale } from '../../../../hooks/useLocale'; -import { TierList } from '../../../../stores/tierList'; -import { CopyButton } from '../../../CopyButton'; - -export function Share() { - const rows = TierList.use((state) => state.rows); - const { strings } = useLocale(); - - return ( - - `${location.origin}/tier-list?${generateTierListParams(rows)}` - } - > - - {strings.website.tools.tier_list.buttons.share} - - ); -} diff --git a/packages/website/src/components/TierList/Controls/index.tsx b/packages/website/src/components/TierList/Controls/index.tsx deleted file mode 100644 index 5850412c9..000000000 --- a/packages/website/src/components/TierList/Controls/index.tsx +++ /dev/null @@ -1,27 +0,0 @@ -import { ReloadIcon } from '@radix-ui/react-icons'; -import { Button, Flex } from '@radix-ui/themes'; -import { useLocale } from '../../../hooks/useLocale'; -import { TierList } from '../../../stores/tierList'; -import { Share } from './components/Share'; - -export function TierListControls() { - const { strings } = useLocale(); - - return ( - - - - - - ); -} diff --git a/packages/website/src/components/TierList/Row/components/Header.tsx b/packages/website/src/components/TierList/Row/components/Header.tsx deleted file mode 100644 index 394d58509..000000000 --- a/packages/website/src/components/TierList/Row/components/Header.tsx +++ /dev/null @@ -1,113 +0,0 @@ -import { - CheckIcon, - Cross1Icon, - Pencil1Icon, - Pencil2Icon, -} from '@radix-ui/react-icons'; -import { - Button, - Flex, - Heading, - IconButton, - Popover, - Table, - TextField, -} from '@radix-ui/themes'; -import { useRef, useState } from 'react'; -import { Var } from '../../../../core/radix/var'; -import { TierList } from '../../../../stores/tierList'; -import { tierListRows } from '../../Table/constants'; - -interface HeaderProps { - index: number; -} - -export function Header({ index }: HeaderProps) { - const rowStyle = tierListRows[index]; - const name = TierList.use((state) => state.rows[index].name); - const input = useRef(null); - const [open, setOpen] = useState(false); - - return ( - - - - - - {name} - - - - - - - - - - - { - if (!input.current) return; - - if (event.key === 'Enter') { - input.current.blur(); - } else if (event.key === 'Escape') { - input.current.value = name; - input.current.blur(); - } - }} - onBlur={() => { - if (!input.current) return; - - TierList.mutate((draft) => { - if (!input.current) return; - draft.rows[index].name = input.current.value; - }); - - setOpen(false); - }} - > - - - - - - - { - if (!input.current) return; - - input.current.value = name; - }} - > - - - - - - - - - - ); -} diff --git a/packages/website/src/components/TierList/Row/index.tsx b/packages/website/src/components/TierList/Row/index.tsx deleted file mode 100644 index 167fde474..000000000 --- a/packages/website/src/components/TierList/Row/index.tsx +++ /dev/null @@ -1,53 +0,0 @@ -import { Flex, Table } from "@radix-ui/themes"; -import { useEffect, useRef } from "react"; -import { api } from "../../../api/dynamic"; -import { TierList } from "../../../stores/tierList"; -import { tierListRowElements } from "../Table/constants"; -import { TierListTile } from "../Tile"; -import { Header } from "./components/Header"; - -interface TierListRowProps { - index: number; -} - -const tankDefinitions = await api.tanks(); - -export function TierListRow({ index }: TierListRowProps) { - const tanks = TierList.use((state) => state.rows[index].tanks); - const row = useRef(null); - - useEffect(() => { - if (!row.current) return; - - tierListRowElements.add(row.current); - - return () => { - if (!row.current) return; - - tierListRowElements.delete(row.current); - }; - }); - - return ( - -
- - - - {tanks.map((id, tankIndex) => { - const tank = tankDefinitions.tanks[id]; - return ( - - ); - })} - - - - ); -} diff --git a/packages/website/src/components/TierList/Table/constants.ts b/packages/website/src/components/TierList/Table/constants.ts deleted file mode 100644 index c90423b36..000000000 --- a/packages/website/src/components/TierList/Table/constants.ts +++ /dev/null @@ -1,17 +0,0 @@ -import type { VarName } from '../../../core/radix/var'; - -export const tierListRows: { - name: string; - color: VarName; -}[] = [ - { name: 'S', color: 'tomato-9' }, - { name: 'A', color: 'orange-9' }, - { name: 'B', color: 'amber-9' }, - { name: 'C', color: 'green-9' }, - { name: 'D', color: 'blue-9' }, -]; - -export const tierListRowElements = new Set(); -export const tierListCardElements = tierListRows.map( - () => new Set(), -); diff --git a/packages/website/src/components/TierList/Table/index.tsx b/packages/website/src/components/TierList/Table/index.tsx deleted file mode 100644 index 7c5b74c55..000000000 --- a/packages/website/src/components/TierList/Table/index.tsx +++ /dev/null @@ -1,15 +0,0 @@ -import { Table } from '@radix-ui/themes'; -import { TierListRow } from '../Row'; -import { tierListRows } from './constants'; - -export function TierListTable() { - return ( - - - {tierListRows.map((_, index) => ( - - ))} - - - ); -} diff --git a/packages/website/src/components/TierList/Tile.tsx b/packages/website/src/components/TierList/Tile.tsx deleted file mode 100644 index be14be588..000000000 --- a/packages/website/src/components/TierList/Tile.tsx +++ /dev/null @@ -1,211 +0,0 @@ -import type { TankDefinition } from "@blitzkit/protos"; -import { Box } from "@radix-ui/themes"; -import { - useCallback, - useEffect, - useRef, - type PointerEvent as ReactPointerEvent, -} from "react"; -import { TierList } from "../../stores/tierList"; -import { TankCard } from "../TankCard"; -import { tierListCardElements, tierListRowElements } from "./Table/constants"; - -const SCROLL_ZONE = 1 / 3; - -type TierListTileProps = { - tank: TankDefinition; -} & ( - | { - isPlaced?: false; - } - | { - isPlaced: true; - rowIndex: number; - tileIndex: number; - } -); - -export function TierListTile(props: TierListTileProps) { - const card = useRef(null); - const lastPosition = useRef({ x: 0, y: 0 }); - const autoScroll = useRef(false); - const lastT = useRef(0); - - const autoScrollLoop = useCallback(() => { - if (!autoScroll.current) return; - - let scrollSpeed = 0; - const v = lastPosition.current.y / window.innerHeight; - - if (v <= SCROLL_ZONE) { - scrollSpeed = v / SCROLL_ZONE - 1; - } else if (v >= 1 - SCROLL_ZONE) { - scrollSpeed = 1 - (1 - v) / SCROLL_ZONE; - } - - const t = performance.now(); - const dt = t - lastT.current; - lastT.current = t; - - window.scrollBy({ - behavior: "instant", - top: scrollSpeed * dt, - }); - - requestAnimationFrame(autoScrollLoop); - }, []); - - const handlePointerDown = useCallback( - (event: ReactPointerEvent) => { - if (!card.current) return; - - event.preventDefault(); - - const rect = card.current.getBoundingClientRect(); - - card.current.style.position = "fixed"; - card.current.style.cursor = "grabbing"; - card.current.style.zIndex = "1"; - card.current.style.left = `${rect.left}px`; - card.current.style.top = `${rect.top}px`; - - lastPosition.current = { x: event.clientX, y: event.clientY }; - - window.scrollTo({ behavior: "instant", top: 124 }); - - window.addEventListener("pointermove", handlePointerMove); - window.addEventListener("pointerup", handlePointerUp); - - TierList.mutate((draft) => { - draft.dragging = true; - }); - - autoScroll.current = true; - lastT.current = performance.now(); - autoScrollLoop(); - }, - [], - ); - const handlePointerMove = useCallback((event: PointerEvent) => { - if (!card.current) return; - - event.preventDefault(); - - const rect = card.current.getBoundingClientRect(); - const dx = event.clientX - lastPosition.current.x; - const dy = event.clientY - lastPosition.current.y; - - card.current.style.left = `${rect.left + dx}px`; - card.current.style.top = `${rect.top + dy}px`; - - lastPosition.current = { x: event.clientX, y: event.clientY }; - }, []); - const handlePointerUp = useCallback(() => { - if (!card.current) return; - - const cardRect = card.current.getBoundingClientRect(); - const cardX = (cardRect.left + cardRect.right) / 2; - const cardY = (cardRect.top + cardRect.bottom) / 2; - let wasPlaced = false; - - rowLoop: for (const row of tierListRowElements) { - const rowRect = row.getBoundingClientRect(); - const isWithinRow = - cardX >= rowRect.left && - cardX <= rowRect.right && - cardY >= rowRect.top && - cardY <= rowRect.bottom; - - if (!isWithinRow) continue; - - const rowIndex = Number(row.dataset.index); - - for (const tile of tierListCardElements[rowIndex]) { - const tileId = Number(tile.dataset.tileId); - - if (tileId === props.tank.id) continue; - - const tileRect = tile.getBoundingClientRect(); - const isWithinTile = - cardX >= tileRect.left && - cardX <= tileRect.right && - cardY >= tileRect.top && - cardY <= tileRect.bottom; - - if (!isWithinTile) continue; - - const tileIndex = Number(tile.dataset.tileIndex); - - TierList.mutate((draft) => { - draft.dragging = false; - draft.rows.forEach((row) => { - row.tanks = row.tanks.filter((tankId) => tankId !== props.tank.id); - }); - draft.rows[rowIndex].tanks.splice(tileIndex, 0, props.tank.id); - draft.placedTanks.add(props.tank.id); - }); - - wasPlaced = true; - - break rowLoop; - } - - TierList.mutate((draft) => { - draft.dragging = false; - draft.rows.forEach((row) => { - row.tanks = row.tanks.filter((tankId) => tankId !== props.tank.id); - }); - draft.rows[rowIndex].tanks.push(props.tank.id); - draft.placedTanks.add(props.tank.id); - }); - - wasPlaced = true; - - break; - } - - if (!wasPlaced) { - TierList.mutate((draft) => { - draft.dragging = false; - draft.rows.forEach((row) => { - row.tanks = row.tanks.filter((tankId) => tankId !== props.tank.id); - }); - draft.placedTanks.delete(props.tank.id); - }); - } - - card.current.style.position = "static"; - card.current.style.zIndex = "unset"; - card.current.style.cursor = "grab"; - - window.removeEventListener("pointermove", handlePointerMove); - window.removeEventListener("pointerup", handlePointerUp); - - autoScroll.current = false; - }, []); - - useEffect(() => { - if (!props.isPlaced || !card.current) return; - - tierListCardElements[props.rowIndex].add(card.current); - - return () => { - if (!card.current) return; - - tierListCardElements[props.rowIndex].delete(card.current); - }; - }, []); - - return ( - - - - ); -} diff --git a/packages/website/src/components/TierList/Tiles.tsx b/packages/website/src/components/TierList/Tiles.tsx deleted file mode 100644 index 332d40f1f..000000000 --- a/packages/website/src/components/TierList/Tiles.tsx +++ /dev/null @@ -1,58 +0,0 @@ -import { metaSortTank } from "@blitzkit/core"; -import { times } from "lodash-es"; -import { useMemo, useState } from "react"; -import usePromise from "react-promise-suspense"; -import { api } from "../../api/dynamic"; -import { filterTanks } from "../../core/blitzkit/filterTanks"; -import { TankFilters } from "../../stores/tankFilters"; -import { TierList } from "../../stores/tierList"; -import { TankCardSkeleton } from "../TankCardSkeleton"; -import { TankCardWrapper } from "../TankCardWrapper"; -import { TierListTile } from "./Tile"; - -const [tankDefinitions, gameDefinitions] = await Promise.all([ - api.tanks(), - api.game(), -]); - -const tanks = Object.values(tankDefinitions.tanks); - -const PREVIEW_COUNT = 32; -const DEFAULT_LOADED_CARDS = 75; - -export function TierListTiles() { - const filters = TankFilters.use(); - const placedTanks = TierList.use((state) => state.placedTanks); - const filteredTanks = usePromise( - () => - filterTanks(filters, tanks).then((tanks) => - tanks.filter(({ id }) => !placedTanks.has(id)), - ), - // react-promise-suspense has awful type annotations - [filters, placedTanks] as any, - ); - const sorted = useMemo( - () => metaSortTank(filteredTanks, gameDefinitions).reverse(), - [filters, placedTanks], - ); - const [loadedTiles, setLoadedTiles] = useState(DEFAULT_LOADED_CARDS); - - return ( - - {sorted.slice(0, loadedTiles).map((tank) => ( - - ))} - - {times(Math.min(PREVIEW_COUNT, sorted.length - loadedTiles), (index) => { - return ( - { - setLoadedTiles((state) => Math.min(state + 2, sorted.length)); - }} - /> - ); - })} - - ); -} diff --git a/packages/website/src/components/TierList/URLManager.tsx b/packages/website/src/components/TierList/URLManager.tsx deleted file mode 100644 index 615ae912d..000000000 --- a/packages/website/src/components/TierList/URLManager.tsx +++ /dev/null @@ -1,34 +0,0 @@ -import { useEffect } from "react"; -import { api } from "../../api/dynamic"; -import { generateTierListParams } from "../../core/blitzkit/generateTierListParams"; -import { TierList } from "../../stores/tierList"; - -const tankDefinitions = await api.tanks(); - -export function URLManager() { - const rows = TierList.use((state) => state.rows); - - useEffect(() => { - const params = new URLSearchParams(window.location.search); - - params.forEach((value, key) => { - if (key.startsWith("row-")) { - const index = Number.parseInt(key.slice(4), 10); - const values = value - .split(",") - .map(Number) - .filter((id) => id in tankDefinitions.tanks); - - TierList.mutate((draft) => { - draft.rows[index].tanks = values; - }); - } - }); - }, []); - - useEffect(() => { - window.history.replaceState(null, "", `?${generateTierListParams(rows)}`); - }, [rows]); - - return null; -} diff --git a/packages/website/src/components/TierListControls/index.module.css b/packages/website/src/components/TierListControls/index.module.css new file mode 100644 index 000000000..34cb77bc9 --- /dev/null +++ b/packages/website/src/components/TierListControls/index.module.css @@ -0,0 +1,5 @@ +.controls { + display: flex; + justify-content: center; + gap: var(--space-3); +} diff --git a/packages/website/src/components/TierListControls/index.tsx b/packages/website/src/components/TierListControls/index.tsx new file mode 100644 index 000000000..54861f050 --- /dev/null +++ b/packages/website/src/components/TierListControls/index.tsx @@ -0,0 +1,34 @@ +import { ReloadIcon, Share2Icon } from "@radix-ui/react-icons"; +import { withLocale } from "../../hocs/withLocale"; +import { useStrings } from "../../hooks/useStrings"; +import { TierList } from "../../stores/tierList"; +import { Button } from "../Button"; +import { CopyButton } from "../CopyButton"; +import styles from "./index.module.css"; + +export const TierListControls = withLocale(Content); + +function Content() { + const strings = useStrings(); + + return ( +
+ + + {/* The url is kept in sync with the rows */} + location.href}> + + {strings.tier_list.share} + +
+ ); +} diff --git a/packages/website/src/components/TierListRow/index.module.css b/packages/website/src/components/TierListRow/index.module.css new file mode 100644 index 000000000..95326cd35 --- /dev/null +++ b/packages/website/src/components/TierListRow/index.module.css @@ -0,0 +1,3 @@ +.tanks { + width: 100%; +} diff --git a/packages/website/src/components/TierListRow/index.tsx b/packages/website/src/components/TierListRow/index.tsx new file mode 100644 index 000000000..4c409713e --- /dev/null +++ b/packages/website/src/components/TierListRow/index.tsx @@ -0,0 +1,27 @@ +import type { TierListRowState } from "../../stores/tierList"; +import { Table } from "../Table"; +import { TankCardWrapper } from "../TankCardWrapper"; +import { TierListRowHeader } from "../TierListRowHeader"; +import { TierListTile } from "../TierListTile"; +import styles from "./index.module.css"; + +interface TierListRowProps { + index: number; + row: TierListRowState; +} + +export function TierListRow({ index, row }: TierListRowProps) { + return ( + + + + + + {row.tanks.map((id) => ( + + ))} + + + + ); +} diff --git a/packages/website/src/components/TierListRowHeader/index.module.css b/packages/website/src/components/TierListRowHeader/index.module.css new file mode 100644 index 000000000..44ab71a1f --- /dev/null +++ b/packages/website/src/components/TierListRowHeader/index.module.css @@ -0,0 +1,35 @@ +/* A plain cell, since a row header's own background would cover the accent */ +.header { + vertical-align: middle; + + background-color: var(--accent-9); + cursor: pointer; + + /* Table cells ignore max-width, so the content carries the size: the widest name, within limits */ + .content { + width: max-content; + min-width: 5rem; + max-width: 12rem; + min-height: 8rem; + + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + gap: var(--space-2); + } +} + +.swatches { + /* Adds no width of its own, filling and wrapping within what the rest of the popover sets */ + display: flex; + flex-wrap: wrap; + gap: var(--space-2); + width: 0; + min-width: 100%; + + /* Every swatch keeps its check so the buttons stay the same size; only the selected one shows it */ + .swatch[data-selected="false"] svg { + visibility: hidden; + } +} diff --git a/packages/website/src/components/TierListRowHeader/index.tsx b/packages/website/src/components/TierListRowHeader/index.tsx new file mode 100644 index 000000000..4c4e744fb --- /dev/null +++ b/packages/website/src/components/TierListRowHeader/index.tsx @@ -0,0 +1,139 @@ +import { + CheckIcon, + Cross1Icon, + Pencil2Icon, + TrashIcon, +} from "@radix-ui/react-icons"; +import { useState, type KeyboardEvent } from "react"; +import { tierListColors } from "../../config/tierList"; +import { useStrings } from "../../hooks/useStrings"; +import { TierList, type TierListRowState } from "../../stores/tierList"; +import { Button } from "../Button"; +import { Heading } from "../Heading"; +import { IconButton } from "../IconButton"; +import { Popover } from "../Popover"; +import { Table } from "../Table"; +import { TextField } from "../TextField"; +import styles from "./index.module.css"; + +interface TierListRowHeaderProps { + index: number; + row: TierListRowState; +} + +export function TierListRowHeader({ index, row }: TierListRowHeaderProps) { + const strings = useStrings(); + const rowCount = TierList.useDeferred( + (state) => state.rows.length, + TierList.initial.rows.length, + ); + const [open, setOpen] = useState(false); + const [name, setName] = useState(row.name); + const [color, setColor] = useState(row.color); + + function apply() { + TierList.mutate((draft) => { + draft.rows[index].name = name; + draft.rows[index].color = color; + }); + + setOpen(false); + } + + function remove() { + TierList.mutate((draft) => { + draft.rows.splice(index, 1); + }); + + setOpen(false); + } + + function handleKeyDown(event: KeyboardEvent) { + if (event.key === "Enter") apply(); + } + + return ( + { + if (open) { + setName(row.name); + setColor(row.color); + } + + setOpen(open); + }} + > + + +
+ + {row.name} + + + + + +
+
+
+ + + + + + setName((event.target as HTMLInputElement).value) + } + onKeyDown={handleKeyDown} + /> + + + +
+ {tierListColors.map((swatch) => ( + setColor(swatch)} + > + + + ))} +
+
+ + + + + + + + + + +
+
+
+ ); +} diff --git a/packages/website/src/components/TierListTable/index.module.css b/packages/website/src/components/TierListTable/index.module.css new file mode 100644 index 000000000..344133d5a --- /dev/null +++ b/packages/website/src/components/TierListTable/index.module.css @@ -0,0 +1,17 @@ +.table { + width: 100%; + background-color: var(--gray-2); + + .body { + scroll-margin-top: var(--page-padding); + } + + .add { + padding: var(--space-3); + + /* Stretches the button across the table */ + .button { + width: 100%; + } + } +} diff --git a/packages/website/src/components/TierListTable/index.tsx b/packages/website/src/components/TierListTable/index.tsx new file mode 100644 index 000000000..160e95756 --- /dev/null +++ b/packages/website/src/components/TierListTable/index.tsx @@ -0,0 +1,51 @@ +import { PlusIcon } from "@radix-ui/react-icons"; +import { tierListInsertionMarker, tierListTable } from "../../config/tierList"; +import { withLocale } from "../../hocs/withLocale"; +import { useStrings } from "../../hooks/useStrings"; +import { createTierListRow, TierList } from "../../stores/tierList"; +import { Button } from "../Button"; +import { InsertionMarker } from "../InsertionMarker"; +import { Table } from "../Table"; +import { TierListRow } from "../TierListRow"; +import styles from "./index.module.css"; + +export const TierListTable = withLocale(Content); + +function Content() { + const strings = useStrings(); + const rows = TierList.useDeferred( + (state) => state.rows, + TierList.initial.rows, + ); + + return ( + <> + + + {rows.map((row, index) => ( + + ))} + + + + + + + + + + + + ); +} diff --git a/packages/website/src/components/TierListTile/index.module.css b/packages/website/src/components/TierListTile/index.module.css new file mode 100644 index 000000000..071af2b90 --- /dev/null +++ b/packages/website/src/components/TierListTile/index.module.css @@ -0,0 +1,11 @@ +.tile { + cursor: grab; + touch-action: none; + + &[data-dragging="true"] { + position: fixed; + z-index: 1; + + cursor: grabbing; + } +} diff --git a/packages/website/src/components/TierListTile/index.tsx b/packages/website/src/components/TierListTile/index.tsx new file mode 100644 index 000000000..723cf38bd --- /dev/null +++ b/packages/website/src/components/TierListTile/index.tsx @@ -0,0 +1,227 @@ +import { useCallback, useRef, type PointerEvent } from "react"; +import { api } from "../../api/dynamic"; +import { tierListInsertionMarker, tierListTable } from "../../config/tierList"; +import { + showInsertionMarker, + type InsertionMarkerPlacement, +} from "../../core/blitzkit/showInsertionMarker"; +import { TierList } from "../../stores/tierList"; +import type { MaybeSkeletonComponentProps } from "../../types/maybeSkeletonComponentProps"; +import { TankCard } from "../TankCard"; +import { TankCardSkeleton } from "../TankCardSkeleton"; +import styles from "./index.module.css"; + +// Fraction of the viewport at either edge that scrolls the page while dragging +const SCROLL_ZONE = 1 / 3; +const SCROLL_ZONE_END = 1 - SCROLL_ZONE; + +const tankDefinitions = await api.tanks(); + +export interface TierListTileProps { + id: number; +} + +interface TierListDropTarget { + row: number; + index: number; + marker: InsertionMarkerPlacement; +} + +export function TierListTile( + props: MaybeSkeletonComponentProps, +) { + const card = useRef(null); + const pointer = useRef({ x: 0, y: 0 }); + const dragging = useRef(false); + const lastFrame = useRef(0); + const tankId = props.skeleton ? undefined : props.id; + + // Where the card would land if dropped now; undefined sends it back to the pool + const target = useRef(undefined); + + // Hit tests the cursor against the rows and the tanks already in them + const updateTarget = useCallback(() => { + const { x, y } = pointer.current; + const below = document + .elementsFromPoint(x, y) + .filter((element) => !card.current!.contains(element)) as HTMLElement[]; + + // Hit testing skips table rows themselves, so the row is found from a cell inside it + const hit = below.find((element) => element.closest("[data-row]") !== null); + + if (hit === undefined) { + target.current = undefined; + showInsertionMarker(tierListInsertionMarker.current!, undefined); + return; + } + + const row = hit.closest("[data-row]")!; + const cell = row.querySelector("[data-tier-cell]")!; + const grid = cell.querySelector("[data-tier-grid]")!; + const cellRect = cell.getBoundingClientRect(); + const gap = parseFloat(getComputedStyle(grid).columnGap); + const padding = parseFloat(getComputedStyle(cell).paddingLeft); + + // Indexed without the dragged card since it leaves its spot when placed + const siblings = [ + ...grid.querySelectorAll("[data-tank-id]"), + ].filter((element) => element !== card.current); + const tile = below.find((element) => siblings.includes(element)); + + let index = siblings.length; + + if (tile !== undefined) { + const tileRect = tile.getBoundingClientRect(); + + index = + siblings.indexOf(tile) + + (x > tileRect.left + tileRect.width / 2 ? 1 : 0); + } + + // An empty row marks its start, otherwise the gap beside the nearest tank + const start = cellRect.left + padding / 2; + let marker: InsertionMarkerPlacement = { + position: [start, cellRect.top], + height: cellRect.height, + }; + + if (siblings.length > 0) { + const before = index < siblings.length; + const anchor = + siblings[before ? index : index - 1].getBoundingClientRect(); + const left = before ? anchor.left - gap / 2 : anchor.right + gap / 2; + + marker = { position: [left, anchor.top], height: anchor.height }; + } + + target.current = { row: Number(row.dataset.row), index, marker }; + showInsertionMarker(tierListInsertionMarker.current!, marker); + }, []); + + const autoScroll = useCallback(() => { + if (!dragging.current) return; + + const v = pointer.current.y / window.innerHeight; + let speed = 0; + + if (v <= SCROLL_ZONE) { + speed = v / SCROLL_ZONE - 1; + } else if (v >= SCROLL_ZONE_END) { + speed = 1 - (1 - v) / SCROLL_ZONE; + } + + const now = performance.now(); + const dt = now - lastFrame.current; + lastFrame.current = now; + + window.scrollBy({ behavior: "instant", top: speed * dt }); + + // The page moves under a still pointer, so the target can change too + updateTarget(); + + requestAnimationFrame(autoScroll); + }, []); + + const startAutoScroll = useCallback(() => { + if (!dragging.current) return; + + lastFrame.current = performance.now(); + autoScroll(); + }, []); + + const handlePointerMove = useCallback((event: globalThis.PointerEvent) => { + event.preventDefault(); + + const rect = card.current!.getBoundingClientRect(); + const dx = event.clientX - pointer.current.x; + const dy = event.clientY - pointer.current.y; + + card.current!.style.left = `${rect.left + dx}px`; + card.current!.style.top = `${rect.top + dy}px`; + + pointer.current = { x: event.clientX, y: event.clientY }; + + updateTarget(); + }, []); + + const handlePointerUp = useCallback(() => { + updateTarget(); + + TierList.mutate((draft) => { + for (const row of draft.rows) { + row.tanks = row.tanks.filter((id) => id !== tankId); + } + + // No target sends the tank back to the pool + if (target.current === undefined) return; + + draft.rows[target.current.row].tanks.splice( + target.current.index, + 0, + tankId!, + ); + }); + + showInsertionMarker(tierListInsertionMarker.current!, undefined); + + delete card.current!.dataset.dragging; + card.current!.style.removeProperty("left"); + card.current!.style.removeProperty("top"); + card.current!.style.removeProperty("width"); + + window.removeEventListener("pointermove", handlePointerMove); + window.removeEventListener("pointerup", handlePointerUp); + window.removeEventListener("scrollend", startAutoScroll); + + dragging.current = false; + target.current = undefined; + }, [tankId]); + + const handlePointerDown = useCallback( + (event: PointerEvent) => { + event.preventDefault(); + + const rect = card.current!.getBoundingClientRect(); + + card.current!.style.left = `${rect.left}px`; + card.current!.style.top = `${rect.top}px`; + card.current!.style.width = `${rect.width}px`; + card.current!.dataset.dragging = "true"; + + pointer.current = { x: event.clientX, y: event.clientY }; + dragging.current = true; + + window.addEventListener("pointermove", handlePointerMove); + window.addEventListener("pointerup", handlePointerUp); + + // Edge scrolling only kicks in once the table has been scrolled to + const table = tierListTable.current!; + const margin = parseFloat(getComputedStyle(table).scrollMarginTop); + const distance = table.getBoundingClientRect().top - margin; + + if (Math.abs(distance) < 1 || !("onscrollend" in window)) { + table.scrollIntoView({ behavior: "instant", block: "start" }); + startAutoScroll(); + } else { + window.addEventListener("scrollend", startAutoScroll, { once: true }); + table.scrollIntoView({ behavior: "smooth", block: "start" }); + } + }, + [handlePointerUp], + ); + + if (props.skeleton) { + return ; + } + + return ( +
+ +
+ ); +} diff --git a/packages/website/src/components/TierListTiles/index.tsx b/packages/website/src/components/TierListTiles/index.tsx new file mode 100644 index 000000000..d5cd4a2e3 --- /dev/null +++ b/packages/website/src/components/TierListTiles/index.tsx @@ -0,0 +1,58 @@ +import { metaSortTanks } from "@blitzkit/core"; +import { useMemo } from "react"; +import usePromise from "react-promise-suspense"; +import { api } from "../../api/dynamic"; +import { filterTanks } from "../../core/blitzkit/filterTanks"; +import { withLocale } from "../../hocs/withLocale"; +import { App } from "../../stores/app"; +import { TankFilters } from "../../stores/tankFilters"; +import { TierList } from "../../stores/tierList"; +import { IncrementalLoader } from "../IncrementalLoader"; +import { TankCardWrapper } from "../TankCardWrapper"; +import { TankSearchNoResults } from "../TankSearchNoResults"; +import { TierListTile } from "../TierListTile"; + +const [tankDefinitions, gameDefinitions] = await Promise.all([ + api.tanks(), + api.game(), +]); +const tanks = Object.values(tankDefinitions.tanks); + +// Tanks not yet placed in any tier, ready to be dragged in +export const TierListTiles = withLocale(Content); + +function Content() { + const filters = TankFilters.use(); + const rows = TierList.useDeferred( + (state) => state.rows, + TierList.initial.rows, + ); + const wargaming = App.use((state) => state.logins.wargaming); + const filtered = usePromise( + () => filterTanks(filters, tanks, wargaming?.id), + // react-promise-suspense has awful type annotations + [filters] as any, + ); + + const data = useMemo(() => { + const placed = new Set(rows.flatMap((row) => row.tanks)); + const unplaced = filtered.filter(({ id }) => !placed.has(id)); + + return metaSortTanks(unplaced, gameDefinitions) + .reverse() + .map(({ id }) => ({ key: `${id}`, id })); + }, [filtered, rows]); + + if (data.length === 0) return ; + + return ( + + + + ); +} diff --git a/packages/website/src/components/TierListURLManager.astro b/packages/website/src/components/TierListURLManager.astro new file mode 100644 index 000000000..ce5aedd43 --- /dev/null +++ b/packages/website/src/components/TierListURLManager.astro @@ -0,0 +1,44 @@ + + diff --git a/packages/website/src/components/ToolBanner.astro b/packages/website/src/components/ToolBanner.astro index 9fbfe9802..e493337c1 100644 --- a/packages/website/src/components/ToolBanner.astro +++ b/packages/website/src/components/ToolBanner.astro @@ -1,7 +1,7 @@ --- import { alias } from "@blitzkit/core"; import { api } from "../api/dynamic"; -import type { Tool } from "../constants/tools"; +import type { Tool } from "../config/tools"; import { Logo } from "../icons/Logo"; import { Heading } from "./Heading"; diff --git a/packages/website/src/components/ToolCard.astro b/packages/website/src/components/ToolCard.astro index 143f55b26..0ea08ab35 100644 --- a/packages/website/src/components/ToolCard.astro +++ b/packages/website/src/components/ToolCard.astro @@ -1,7 +1,7 @@ --- import { alias } from "@blitzkit/core"; import { api } from "../api/dynamic"; -import type { Tool } from "../constants/tools"; +import type { Tool } from "../config/tools"; import { Heading } from "./Heading"; import { LinkI18n } from "./LinkI18n"; diff --git a/packages/website/src/components/ToolOpenGraph.astro b/packages/website/src/components/ToolOpenGraph.astro index 42e0bc11b..1eb668e98 100644 --- a/packages/website/src/components/ToolOpenGraph.astro +++ b/packages/website/src/components/ToolOpenGraph.astro @@ -1,7 +1,7 @@ --- import { AstroSeo } from "@astrolib/seo"; import { api } from "../api/dynamic"; -import type { Tool } from "../constants/tools"; +import type { Tool } from "../config/tools"; interface Props { tool: Tool; diff --git a/packages/website/src/config/compare.ts b/packages/website/src/config/compare.ts new file mode 100644 index 000000000..c37d5233b --- /dev/null +++ b/packages/website/src/config/compare.ts @@ -0,0 +1,4 @@ +import { createRef } from "react"; + +// One shared bar showing where a dragged tank would land +export const compareInsertionMarker = createRef(); diff --git a/packages/website/src/constants/dialog.ts b/packages/website/src/config/dialog.ts similarity index 100% rename from packages/website/src/constants/dialog.ts rename to packages/website/src/config/dialog.ts diff --git a/packages/website/src/constants/embeds.ts b/packages/website/src/config/embeds.ts similarity index 100% rename from packages/website/src/constants/embeds.ts rename to packages/website/src/config/embeds.ts diff --git a/packages/website/src/constants/navbar.ts b/packages/website/src/config/navbar.ts similarity index 100% rename from packages/website/src/constants/navbar.ts rename to packages/website/src/config/navbar.ts diff --git a/packages/website/src/constants/skinNumber.ts b/packages/website/src/config/skinNumber.ts similarity index 100% rename from packages/website/src/constants/skinNumber.ts rename to packages/website/src/config/skinNumber.ts diff --git a/packages/website/src/config/tierList.ts b/packages/website/src/config/tierList.ts new file mode 100644 index 000000000..18a3139d3 --- /dev/null +++ b/packages/website/src/config/tierList.ts @@ -0,0 +1,41 @@ +import { createRef } from "react"; +import type { Color } from "../ui/color"; + +// Rows a fresh tier list starts with: S, then A onward +export const tierListDefaultRowCount = 5; + +// Colors for the rows in order, before falling back to cycling every color +export const tierListRowColors: Color[] = [ + "tomato", + "orange", + "amber", + "green", + "blue", +]; + +// Every color a row can take; all read well under white text +export const tierListColors: Color[] = [ + "tomato", + "crimson", + "pink", + "plum", + "purple", + "violet", + "indigo", + "blue", + "cyan", + "teal", + "jade", + "green", + "grass", + "amber", + "orange", + "brown", + "bronze", +]; + +// Dragging scrolls up to here before scrolling by the screen's edges +export const tierListTable = createRef(); + +// One shared bar showing where a dragged tank would land +export const tierListInsertionMarker = createRef(); diff --git a/packages/website/src/constants/tools.ts b/packages/website/src/config/tools.ts similarity index 95% rename from packages/website/src/constants/tools.ts rename to packages/website/src/config/tools.ts index 0dccb8695..11455c335 100644 --- a/packages/website/src/constants/tools.ts +++ b/packages/website/src/config/tools.ts @@ -1,4 +1,4 @@ -import { discordLink } from "../config/socials"; +import { discordLink } from "./socials"; export interface Tool { id: string; @@ -66,10 +66,9 @@ export const tools: Record = { banner_background_position: "bottom", }, tier_list: { - disabled: true, id: "tier_list", slug: "tier-list", - banner_background_position: "bottom", + banner_background_position: "top", }, embed: { id: "embed", diff --git a/packages/website/src/core/blitzkit/generateTierListParams.ts b/packages/website/src/core/blitzkit/generateTierListParams.ts deleted file mode 100644 index 7a870e4bc..000000000 --- a/packages/website/src/core/blitzkit/generateTierListParams.ts +++ /dev/null @@ -1,11 +0,0 @@ -import type { TierList } from '../../stores/tierList'; - -export function generateTierListParams(rows: TierList['rows']) { - const params = new URLSearchParams(); - - rows.forEach((row, index) => { - params.set(`row-${index}`, row.tanks.join(',')); - }); - - return params; -} diff --git a/packages/website/src/core/blitzkit/showInsertionMarker.ts b/packages/website/src/core/blitzkit/showInsertionMarker.ts new file mode 100644 index 000000000..7ee313374 --- /dev/null +++ b/packages/website/src/core/blitzkit/showInsertionMarker.ts @@ -0,0 +1,24 @@ +import type { Vector2Tuple } from "three"; + +// The full span of the slot; the marker pads itself inwards +export interface InsertionMarkerPlacement { + position: Vector2Tuple; + height: number; +} + +// Undefined hides the marker +// TODO: go through core/ and dissolve every file +export function showInsertionMarker( + marker: HTMLDivElement, + placement: InsertionMarkerPlacement | undefined, +) { + if (placement === undefined) { + delete marker.dataset.visible; + return; + } + + marker.dataset.visible = "true"; + marker.style.left = `${placement.position[0]}px`; + marker.style.top = `${placement.position[1]}px`; + marker.style.height = `${placement.height}px`; +} diff --git a/packages/website/src/layouts/BaseLayout.astro b/packages/website/src/layouts/BaseLayout.astro index b9e5b9e06..0625440c5 100644 --- a/packages/website/src/layouts/BaseLayout.astro +++ b/packages/website/src/layouts/BaseLayout.astro @@ -7,7 +7,7 @@ import ColorScale from "../components/ColorScale.astro"; import NavbarCourse from "../components/NavbarCourse.astro"; import NavbarFine from "../components/NavbarFine.astro"; import SystemTheme from "../components/SystemTheme.astro"; -import type { Tool } from "../constants/tools"; +import type { Tool } from "../config/tools"; import type { LocaleAcceptorProps } from "../hooks/useLocale"; import type { Color } from "../ui/color"; diff --git a/packages/website/src/pages/404.astro b/packages/website/src/pages/404.astro index db43151a6..6d039af28 100644 --- a/packages/website/src/pages/404.astro +++ b/packages/website/src/pages/404.astro @@ -8,7 +8,7 @@ import { Link } from "../components/Link"; import { LinkI18n } from "../components/LinkI18n"; import { Text } from "../components/Text"; import { discordLink } from "../config/socials"; -import { tools } from "../constants/tools"; +import { tools } from "../config/tools"; import BaseLayout from "../layouts/BaseLayout.astro"; // the 404 page is not locale-scoped, so it always renders in the default locale diff --git a/packages/website/src/pages/[...chunk_api]/tools/[tool]/banners/[size].webp.ts b/packages/website/src/pages/[...chunk_api]/tools/[tool]/banners/[size].webp.ts index 2594c4f5d..9beafc3c8 100644 --- a/packages/website/src/pages/[...chunk_api]/tools/[tool]/banners/[size].webp.ts +++ b/packages/website/src/pages/[...chunk_api]/tools/[tool]/banners/[size].webp.ts @@ -6,7 +6,7 @@ import { TOOL_BANNER_HEIGHTS, ToolBannerSize, tools, -} from "../../../../../constants/tools"; +} from "../../../../../config/tools"; import { getStaticPaths as _getStaticPaths } from "../../../_index"; interface ToolBannerProps { diff --git a/packages/website/src/pages/[...chunk_default]/[...locale]/auth/[provider]/_index.astro b/packages/website/src/pages/[...chunk_default]/[...locale]/auth/[provider]/_index.astro index b2bfe8178..9e401097f 100644 --- a/packages/website/src/pages/[...chunk_default]/[...locale]/auth/[provider]/_index.astro +++ b/packages/website/src/pages/[...chunk_default]/[...locale]/auth/[provider]/_index.astro @@ -2,7 +2,7 @@ import { Flex, Heading, Text } from "@radix-ui/themes"; import { PageWrapper } from "../../../../../components/PageWrapper"; import { mixStaticPaths } from "../../../../../core/blitzkit/mixStaticPaths"; -import { tools } from "../../../../../constants/tools"; +import { tools } from "../../../../../config/tools"; import BaseLayout from "../../../../../layouts/BaseLayout.astro"; import { getStaticPaths as _getStaticPaths } from "../../index.astro"; import { AUTH_PROVIDER_NAMES, AUTH_PROVIDERS, Authorize } from "./_index"; diff --git a/packages/website/src/pages/[...chunk_default]/[...locale]/avatars/_index.astro b/packages/website/src/pages/[...chunk_default]/[...locale]/avatars/_index.astro index 61f735e56..61efb474c 100644 --- a/packages/website/src/pages/[...chunk_default]/[...locale]/avatars/_index.astro +++ b/packages/website/src/pages/[...chunk_default]/[...locale]/avatars/_index.astro @@ -1,7 +1,7 @@ --- import { Section } from "../../../../components/Section"; import ToolBanner from "../../../../components/ToolBanner.astro"; -import { tools } from "../../../../constants/tools"; +import { tools } from "../../../../config/tools"; import BaseLayout from "../../../../layouts/BaseLayout.astro"; import { Page } from "./_index"; diff --git a/packages/website/src/pages/[...chunk_default]/[...locale]/compare/_index.tsx b/packages/website/src/pages/[...chunk_default]/[...locale]/compare/_index.tsx deleted file mode 100644 index 2e45b47d2..000000000 --- a/packages/website/src/pages/[...chunk_default]/[...locale]/compare/_index.tsx +++ /dev/null @@ -1,86 +0,0 @@ -import { createDefaultEnvironment } from "@blitzkit/core"; -import { useEffect } from "react"; -import { api } from "../../../../api/dynamic"; -import { CompareControls } from "../../../../components/CompareControls"; -import { CompareTable } from "../../../../components/CompareTable"; -import { EmptyState } from "../../../../components/EmptyState"; -import { Section } from "../../../../components/Section"; -import { tankToCompareMember } from "../../../../core/blitzkit/tankToCompareMember"; -import { withErrorWrapper } from "../../../../hocs/withErrorWrapper"; -import { withLocale } from "../../../../hocs/withLocale"; -import { useStrings } from "../../../../hooks/useStrings"; -import { CompareEphemeral } from "../../../../stores/compareEphemeral"; -import styles from "./_index.module.css"; - -const [skillDefinitions, tankDefinitions] = await Promise.all([ - api.skills(), - api.tanks(), -]); - -export const Page = withLocale( - withErrorWrapper(() => { - CompareEphemeral.useInitialization(() => - createDefaultEnvironment(skillDefinitions), - ); - - return ; - }), -); - -function Content() { - const strings = useStrings(); - const members = CompareEphemeral.use((state) => state.members); - - // Tanks come from the url on load - useEffect(() => { - const tanks = new URLSearchParams(window.location.search).get("tanks"); - - if (tanks === null) return; - - CompareEphemeral.mutate((draft) => { - draft.members = tanks - .split(",") - .map((id) => tankDefinitions.tanks[Number(id)]) - .filter((tank) => tank !== undefined) - .map(tankToCompareMember); - }); - }, []); - - // ...and are written back whenever they change - useEffect(() => { - const search = new URLSearchParams(window.location.search); - - search.set("tanks", members.map(({ state }) => state.tank).join(",")); - - window.history.replaceState( - {}, - "", - `${window.location.pathname}?${search.toString()}`, - ); - }, [members]); - - return ( - <> -
-
- -
-
- - {members.length > 0 && ( -
- -
- )} - - {members.length === 0 && ( -
- -
- )} - - ); -} diff --git a/packages/website/src/pages/[...chunk_default]/[...locale]/compare/index.astro b/packages/website/src/pages/[...chunk_default]/[...locale]/compare/index.astro index e14704b09..57c4b620c 100644 --- a/packages/website/src/pages/[...chunk_default]/[...locale]/compare/index.astro +++ b/packages/website/src/pages/[...chunk_default]/[...locale]/compare/index.astro @@ -1,9 +1,12 @@ --- import ColorScale from "../../../../components/ColorScale.astro"; +import { CompareControls } from "../../../../components/CompareControls"; +import { CompareTable } from "../../../../components/CompareTable"; +import CompareURLManager from "../../../../components/CompareURLManager.astro"; +import { Section } from "../../../../components/Section"; import ToolBanner from "../../../../components/ToolBanner.astro"; -import { tools } from "../../../../constants/tools"; +import { tools } from "../../../../config/tools"; import BaseLayout from "../../../../layouts/BaseLayout.astro"; -import { Page } from "./_index"; export { getStaticPaths } from "../index.astro"; @@ -15,8 +18,25 @@ const { locale } = Astro.props; + + - + + +
+
+ +
+
+ +
+ +
diff --git a/packages/website/src/pages/[...chunk_default]/[...locale]/components.astro b/packages/website/src/pages/[...chunk_default]/[...locale]/components.astro index 6c9ca42fd..245f58bfc 100644 --- a/packages/website/src/pages/[...chunk_default]/[...locale]/components.astro +++ b/packages/website/src/pages/[...chunk_default]/[...locale]/components.astro @@ -2,7 +2,7 @@ import { CheckIcon, StarFilledIcon } from "@radix-ui/react-icons"; import { Badge } from "../../../components/Badge"; import ColorScale from "../../../components/ColorScale.astro"; -import { tools } from "../../../constants/tools"; +import { tools } from "../../../config/tools"; import BaseLayout from "../../../layouts/BaseLayout.astro"; import type { Color } from "../../../ui/color"; diff --git a/packages/website/src/pages/[...chunk_default]/[...locale]/credits/_index.astro b/packages/website/src/pages/[...chunk_default]/[...locale]/credits/_index.astro index 0193b018b..f62ecdd62 100644 --- a/packages/website/src/pages/[...chunk_default]/[...locale]/credits/_index.astro +++ b/packages/website/src/pages/[...chunk_default]/[...locale]/credits/_index.astro @@ -1,6 +1,6 @@ --- import CreditsPromo from "../../../../components/CreditsPromo.astro"; -import { tools } from "../../../../constants/tools"; +import { tools } from "../../../../config/tools"; import ToolLayout from "../../../../layouts/ToolLayout.astro"; export { getStaticPaths } from "../index.astro"; diff --git a/packages/website/src/pages/[...chunk_default]/[...locale]/docs/[directory]/[document]/_index.astro b/packages/website/src/pages/[...chunk_default]/[...locale]/docs/[directory]/[document]/_index.astro index a617c1834..43f38aaf3 100644 --- a/packages/website/src/pages/[...chunk_default]/[...locale]/docs/[directory]/[document]/_index.astro +++ b/packages/website/src/pages/[...chunk_default]/[...locale]/docs/[directory]/[document]/_index.astro @@ -1,7 +1,7 @@ --- import { readFile } from "fs/promises"; import { mixStaticPaths } from "../../../../../../core/blitzkit/mixStaticPaths"; -import { tools } from "../../../../../../constants/tools"; +import { tools } from "../../../../../../config/tools"; import BaseLayout from "../../../../../../layouts/BaseLayout.astro"; import { getStaticPaths as _getStaticPaths } from "../../../index.astro"; import { Page } from "./_index"; diff --git a/packages/website/src/pages/[...chunk_default]/[...locale]/docs/patches/_index.astro b/packages/website/src/pages/[...chunk_default]/[...locale]/docs/patches/_index.astro index 4de1b5f63..ebaeea47b 100644 --- a/packages/website/src/pages/[...chunk_default]/[...locale]/docs/patches/_index.astro +++ b/packages/website/src/pages/[...chunk_default]/[...locale]/docs/patches/_index.astro @@ -3,7 +3,7 @@ import { MagicWandIcon, StarFilledIcon } from "@radix-ui/react-icons"; import { Flex, Heading, Link } from "@radix-ui/themes"; import { compareVersions } from "compare-versions"; import { PageWrapper } from "../../../../../components/PageWrapper"; -import { tools } from "../../../../../constants/tools"; +import { tools } from "../../../../../config/tools"; import BaseLayout from "../../../../../layouts/BaseLayout.astro"; export { getStaticPaths } from "../../index.astro"; diff --git a/packages/website/src/pages/[...chunk_default]/[...locale]/embed/[embed]/_index.tsx b/packages/website/src/pages/[...chunk_default]/[...locale]/embed/[embed]/_index.tsx index 5e33dc63a..413bef65c 100644 --- a/packages/website/src/pages/[...chunk_default]/[...locale]/embed/[embed]/_index.tsx +++ b/packages/website/src/pages/[...chunk_default]/[...locale]/embed/[embed]/_index.tsx @@ -31,7 +31,7 @@ import { Text } from "../../../../../components/Text"; import { embedConfigurations, extractEmbedConfigDefaults, -} from "../../../../../constants/embeds"; +} from "../../../../../config/embeds"; import { LocaleProvider, type LocaleAcceptorProps, diff --git a/packages/website/src/pages/[...chunk_default]/[...locale]/embed/[embed]/host/_index.tsx b/packages/website/src/pages/[...chunk_default]/[...locale]/embed/[embed]/host/_index.tsx index 888fbf2c4..7e88e23e8 100644 --- a/packages/website/src/pages/[...chunk_default]/[...locale]/embed/[embed]/host/_index.tsx +++ b/packages/website/src/pages/[...chunk_default]/[...locale]/embed/[embed]/host/_index.tsx @@ -4,7 +4,7 @@ import { embedConfigurations, embedRenderers, extractEmbedConfigDefaults, -} from "../../../../../../constants/embeds"; +} from "../../../../../../config/embeds"; import { LocaleProvider, type LocaleAcceptorProps, diff --git a/packages/website/src/pages/[...chunk_default]/[...locale]/embed/[embed]/index.astro b/packages/website/src/pages/[...chunk_default]/[...locale]/embed/[embed]/index.astro index 413bc08cc..edb36716c 100644 --- a/packages/website/src/pages/[...chunk_default]/[...locale]/embed/[embed]/index.astro +++ b/packages/website/src/pages/[...chunk_default]/[...locale]/embed/[embed]/index.astro @@ -1,7 +1,7 @@ --- import { mixStaticPaths } from "../../../../../astro/mixStaticPaths"; -import { embedConfigurations } from "../../../../../constants/embeds"; -import { tools } from "../../../../../constants/tools"; +import { embedConfigurations } from "../../../../../config/embeds"; +import { tools } from "../../../../../config/tools"; import BaseLayout from "../../../../../layouts/BaseLayout.astro"; import { getStaticPaths as _getStaticPaths } from "../index.astro"; import { Page } from "./_index"; diff --git a/packages/website/src/pages/[...chunk_default]/[...locale]/embed/_index.tsx b/packages/website/src/pages/[...chunk_default]/[...locale]/embed/_index.tsx index 72fd656f1..701339e3a 100644 --- a/packages/website/src/pages/[...chunk_default]/[...locale]/embed/_index.tsx +++ b/packages/website/src/pages/[...chunk_default]/[...locale]/embed/_index.tsx @@ -3,7 +3,7 @@ import { Link } from "../../../../components/Link"; import { LinkI18n } from "../../../../components/LinkI18n"; import { Text } from "../../../../components/Text"; import { discordLink } from "../../../../config/socials"; -import { embedConfigurations } from "../../../../constants/embeds"; +import { embedConfigurations } from "../../../../config/embeds"; import { type LocaleAcceptorProps, LocaleProvider, diff --git a/packages/website/src/pages/[...chunk_default]/[...locale]/embed/index.astro b/packages/website/src/pages/[...chunk_default]/[...locale]/embed/index.astro index 5e148a6c4..2cb288998 100644 --- a/packages/website/src/pages/[...chunk_default]/[...locale]/embed/index.astro +++ b/packages/website/src/pages/[...chunk_default]/[...locale]/embed/index.astro @@ -1,6 +1,6 @@ --- import ToolBanner from "../../../../components/ToolBanner.astro"; -import { tools } from "../../../../constants/tools"; +import { tools } from "../../../../config/tools"; import BaseLayout from "../../../../layouts/BaseLayout.astro"; import { Page } from "./_index"; diff --git a/packages/website/src/pages/[...chunk_default]/[...locale]/guesser/index.astro b/packages/website/src/pages/[...chunk_default]/[...locale]/guesser/index.astro index 50b145c09..f818a16f4 100644 --- a/packages/website/src/pages/[...chunk_default]/[...locale]/guesser/index.astro +++ b/packages/website/src/pages/[...chunk_default]/[...locale]/guesser/index.astro @@ -1,6 +1,6 @@ --- import ColorScale from "../../../../components/ColorScale.astro"; -import { tools } from "../../../../constants/tools"; +import { tools } from "../../../../config/tools"; import BaseLayout from "../../../../layouts/BaseLayout.astro"; import { Page } from "./_index"; diff --git a/packages/website/src/pages/[...chunk_default]/[...locale]/index.astro b/packages/website/src/pages/[...chunk_default]/[...locale]/index.astro index 020adc94c..e867923ce 100644 --- a/packages/website/src/pages/[...chunk_default]/[...locale]/index.astro +++ b/packages/website/src/pages/[...chunk_default]/[...locale]/index.astro @@ -9,7 +9,7 @@ import HomeGames from "../../../components/HomeGames.astro"; import HomePlayers from "../../../components/HomePlayers.astro"; import HomeTanks from "../../../components/HomeTanks.astro"; import HomeTechnical from "../../../components/HomeTechnical.astro"; -import { tools, type Tool } from "../../../constants/tools"; +import { tools, type Tool } from "../../../config/tools"; import BaseLayout from "../../../layouts/BaseLayout.astro"; import { getStaticPaths as _getStaticPaths } from "../_index"; diff --git a/packages/website/src/pages/[...chunk_default]/[...locale]/mixer/index.astro b/packages/website/src/pages/[...chunk_default]/[...locale]/mixer/index.astro index b3dd72791..3a019c126 100644 --- a/packages/website/src/pages/[...chunk_default]/[...locale]/mixer/index.astro +++ b/packages/website/src/pages/[...chunk_default]/[...locale]/mixer/index.astro @@ -1,6 +1,6 @@ --- import ToolOpenGraph from "../../../../components/ToolOpenGraph.astro"; -import { tools } from "../../../../constants/tools"; +import { tools } from "../../../../config/tools"; import BaseLayout from "../../../../layouts/BaseLayout.astro"; import { Page } from "./_index"; diff --git a/packages/website/src/pages/[...chunk_default]/[...locale]/performance/index.astro b/packages/website/src/pages/[...chunk_default]/[...locale]/performance/index.astro index b03d06c01..3912ee3f4 100644 --- a/packages/website/src/pages/[...chunk_default]/[...locale]/performance/index.astro +++ b/packages/website/src/pages/[...chunk_default]/[...locale]/performance/index.astro @@ -1,7 +1,7 @@ --- import ColorScale from "../../../../components/ColorScale.astro"; import ToolBanner from "../../../../components/ToolBanner.astro"; -import { tools } from "../../../../constants/tools"; +import { tools } from "../../../../config/tools"; import BaseLayout from "../../../../layouts/BaseLayout.astro"; import { Page } from "./_index"; diff --git a/packages/website/src/pages/[...chunk_default]/[...locale]/playlist/_index.astro b/packages/website/src/pages/[...chunk_default]/[...locale]/playlist/_index.astro index b86aebfe2..81eb2f656 100644 --- a/packages/website/src/pages/[...chunk_default]/[...locale]/playlist/_index.astro +++ b/packages/website/src/pages/[...chunk_default]/[...locale]/playlist/_index.astro @@ -1,6 +1,6 @@ --- import ToolOpenGraph from "../../../../components/ToolOpenGraph.astro"; -import { tools } from "../../../../constants/tools"; +import { tools } from "../../../../config/tools"; import BaseLayout from "../../../../layouts/BaseLayout.astro"; import { Page } from "./_index.tsx"; diff --git a/packages/website/src/pages/[...chunk_default]/[...locale]/session/_index.astro b/packages/website/src/pages/[...chunk_default]/[...locale]/session/_index.astro index 3c20b8923..dc51cbe8b 100644 --- a/packages/website/src/pages/[...chunk_default]/[...locale]/session/_index.astro +++ b/packages/website/src/pages/[...chunk_default]/[...locale]/session/_index.astro @@ -1,5 +1,5 @@ --- -import { tools } from "../../../../constants/tools"; +import { tools } from "../../../../config/tools"; import ToolLayout from "../../../../layouts/ToolLayout.astro"; import type { getStaticPaths } from "../index.astro"; import { Page } from "./_index"; diff --git a/packages/website/src/pages/[...chunk_default]/[...locale]/tanks/[slug]/index.astro b/packages/website/src/pages/[...chunk_default]/[...locale]/tanks/[slug]/index.astro index 29dbcd5db..8f0caa582 100644 --- a/packages/website/src/pages/[...chunk_default]/[...locale]/tanks/[slug]/index.astro +++ b/packages/website/src/pages/[...chunk_default]/[...locale]/tanks/[slug]/index.astro @@ -3,7 +3,7 @@ import { api } from "../../../../../api/dynamic"; import { mixStaticPaths } from "../../../../../astro/mixStaticPaths"; import ColorRanks from "../../../../../components/ColorRanks.astro"; import ColorScale from "../../../../../components/ColorScale.astro"; -import { tools } from "../../../../../constants/tools"; +import { tools } from "../../../../../config/tools"; import BaseLayout from "../../../../../layouts/BaseLayout.astro"; import { getStaticPaths as _getStaticPaths } from "../index.astro"; import { Loadout, Sandbox } from "./_index"; diff --git a/packages/website/src/pages/[...chunk_default]/[...locale]/tanks/index.astro b/packages/website/src/pages/[...chunk_default]/[...locale]/tanks/index.astro index 8b1e8d196..5fe3a7b17 100644 --- a/packages/website/src/pages/[...chunk_default]/[...locale]/tanks/index.astro +++ b/packages/website/src/pages/[...chunk_default]/[...locale]/tanks/index.astro @@ -7,7 +7,7 @@ import { TankSearchBar } from "../../../../components/TankSearchBar"; import { TankSearchFilters } from "../../../../components/TankSearchFilters"; import { TankSearchResults } from "../../../../components/TankSearchResults"; import ToolBanner from "../../../../components/ToolBanner.astro"; -import { tools } from "../../../../constants/tools"; +import { tools } from "../../../../config/tools"; import BaseLayout from "../../../../layouts/BaseLayout.astro"; export { getStaticPaths } from "../index.astro"; diff --git a/packages/website/src/pages/[...chunk_default]/[...locale]/tier-list/_index.astro b/packages/website/src/pages/[...chunk_default]/[...locale]/tier-list/_index.astro deleted file mode 100644 index cd30d4053..000000000 --- a/packages/website/src/pages/[...chunk_default]/[...locale]/tier-list/_index.astro +++ /dev/null @@ -1,13 +0,0 @@ ---- -import { tools } from "../../../../constants/tools"; -import ToolLayout from "../../../../layouts/ToolLayout.astro"; -import { Page } from "./_index"; - -export { getStaticPaths } from "../index.astro"; - -const { locale } = Astro.props; ---- - - - - diff --git a/packages/website/src/pages/[...chunk_default]/[...locale]/tier-list/_index.tsx b/packages/website/src/pages/[...chunk_default]/[...locale]/tier-list/_index.tsx deleted file mode 100644 index b74cd222d..000000000 --- a/packages/website/src/pages/[...chunk_default]/[...locale]/tier-list/_index.tsx +++ /dev/null @@ -1,30 +0,0 @@ -import { PageWrapper } from "../../../../components/PageWrapper"; -import { TankSearchFilters } from "../../../../components/TankSearchFilters"; -import { TierListControls } from "../../../../components/TierList/Controls"; -import { TierListTable } from "../../../../components/TierList/Table"; -import { TierListTiles } from "../../../../components/TierList/Tiles"; -import { URLManager } from "../../../../components/TierList/URLManager"; -import { - LocaleProvider, - type LocaleAcceptorProps, -} from "../../../../hooks/useLocale"; - -export function Page({ locale }: LocaleAcceptorProps) { - return ( - - - - ); -} - -function Content() { - return ( - - - - - - - - ); -} diff --git a/packages/website/src/pages/[...chunk_default]/[...locale]/tier-list/index.astro b/packages/website/src/pages/[...chunk_default]/[...locale]/tier-list/index.astro new file mode 100644 index 000000000..37e68168c --- /dev/null +++ b/packages/website/src/pages/[...chunk_default]/[...locale]/tier-list/index.astro @@ -0,0 +1,45 @@ +--- +import ColorScale from "../../../../components/ColorScale.astro"; +import { ScrollerCurtains } from "../../../../components/ScrollerCurtains"; +import { Section } from "../../../../components/Section"; +import { TankSearchFilters } from "../../../../components/TankSearchFilters"; +import { TierListControls } from "../../../../components/TierListControls"; +import { TierListTable } from "../../../../components/TierListTable"; +import { TierListTiles } from "../../../../components/TierListTiles"; +import TierListURLManager from "../../../../components/TierListURLManager.astro"; +import ToolBanner from "../../../../components/ToolBanner.astro"; +import { tierListColors } from "../../../../config/tierList"; +import { tools } from "../../../../config/tools"; +import BaseLayout from "../../../../layouts/BaseLayout.astro"; + +export { getStaticPaths } from "../index.astro"; + +const { locale } = Astro.props; +--- + +{tierListColors.map((color) => ( + +))} + + + + + + +
+ +
+ +
+ +
+ +
+ + +
+ +
+ +
+
diff --git a/packages/website/src/pages/[...chunk_default]/[...locale]/tools/embed/[embed]/index.astro b/packages/website/src/pages/[...chunk_default]/[...locale]/tools/embed/[embed]/index.astro index e1b726dda..8fdc0ec5d 100644 --- a/packages/website/src/pages/[...chunk_default]/[...locale]/tools/embed/[embed]/index.astro +++ b/packages/website/src/pages/[...chunk_default]/[...locale]/tools/embed/[embed]/index.astro @@ -1,6 +1,6 @@ --- import { mixStaticPaths } from "../../../../../../astro/mixStaticPaths"; -import { embedConfigurations } from "../../../../../../constants/embeds"; +import { embedConfigurations } from "../../../../../../config/embeds"; import LegacyRedirect from "../../../../../../layouts/LegacyRedirect.astro"; import { getStaticPaths as _getStaticPaths } from "../index.astro"; diff --git a/packages/website/src/pages/[...chunk_models_legendary]/[id]/skins/[skin].glb.ts b/packages/website/src/pages/[...chunk_models_legendary]/[id]/skins/[skin].glb.ts index e82374fbd..df306de3a 100644 --- a/packages/website/src/pages/[...chunk_models_legendary]/[id]/skins/[skin].glb.ts +++ b/packages/website/src/pages/[...chunk_models_legendary]/[id]/skins/[skin].glb.ts @@ -19,7 +19,7 @@ import type { APIContext } from "astro"; import type { Vector3Tuple, Vector4Tuple } from "three"; import { api } from "../../../../api/dynamic"; import { mixStaticPaths } from "../../../../astro/mixStaticPaths"; -import { SKIN_NUMBER } from "../../../../constants/skinNumber"; +import { SKIN_NUMBER } from "../../../../config/skinNumber"; import { switcherStates } from "../../../../core/blitzkit/switcherStates"; import { vfs } from "../../../../core/blitzkit/vfs"; import { diff --git a/packages/website/src/stores/compareEphemeral.ts b/packages/website/src/stores/compareEphemeral.ts index d06a0e5a4..fdab2df19 100644 --- a/packages/website/src/stores/compareEphemeral.ts +++ b/packages/website/src/stores/compareEphemeral.ts @@ -1,5 +1,6 @@ -import type { TankEnvironment } from "@blitzkit/core"; +import { createDefaultEnvironment, type TankEnvironment } from "@blitzkit/core"; import { Soapstone } from "soapstone"; +import { api } from "../api/dynamic"; import { resolveTankModules } from "../tankopedia/resolveTankModules"; import type { TankState } from "../tankopedia/tankState"; import { SortDirection } from "./tankopediaPersistent"; @@ -17,15 +18,14 @@ export interface CompareEphemeral { sorting: TankSort; } -export const CompareEphemeral = new Soapstone< - CompareEphemeral, - TankEnvironment ->((environment) => ({ - environment, +const skills = await api.skills(); + +export const CompareEphemeral = new Soapstone({ + environment: createDefaultEnvironment(skills), syncShells: false, members: [], sorting: { by: null, direction: SortDirection.Descending }, -})); +}); // Picks the shell at the same slot on every member, where one exists export function syncShellSlot(members: CompareMember[], slot: number) { diff --git a/packages/website/src/stores/embedState/utilities.ts b/packages/website/src/stores/embedState/utilities.ts index eed332bde..55cb553c0 100644 --- a/packages/website/src/stores/embedState/utilities.ts +++ b/packages/website/src/stores/embedState/utilities.ts @@ -2,7 +2,7 @@ import { EmbedState, type EmbedConfig, type ExtractEmbedConfigTypes } from "."; import { breakdownConfig, extractEmbedConfigDefaults, -} from "../../constants/embeds"; +} from "../../config/embeds"; import type { EmbedConfigItemType, EmbedItemType } from "./constants"; import { embedText } from "./tokens"; diff --git a/packages/website/src/stores/tierList.ts b/packages/website/src/stores/tierList.ts index 8c323b5b8..c85246438 100644 --- a/packages/website/src/stores/tierList.ts +++ b/packages/website/src/stores/tierList.ts @@ -1,17 +1,34 @@ -import { enableMapSet } from "immer"; import { Soapstone } from "soapstone"; -import { tierListRows } from "../components/TierList/Table/constants"; +import { + tierListColors, + tierListDefaultRowCount, + tierListRowColors, +} from "../config/tierList"; +import type { Color } from "../ui/color"; + +export interface TierListRowState { + name: string; + color: Color; + tanks: number[]; +} export interface TierList { - dragging: boolean; - rows: { name: string; tanks: number[] }[]; - placedTanks: Set; + rows: TierListRowState[]; +} + +const A_CODE = "A".charCodeAt(0); + +// The first row is S, then the lettering runs from A +export function createTierListRow(index: number) { + const name = index === 0 ? "S" : String.fromCharCode(A_CODE + index - 1); + const color = + tierListRowColors[index] ?? tierListColors[index % tierListColors.length]; + + return { name, color, tanks: [] } satisfies TierListRowState; } export const TierList = new Soapstone({ - dragging: false, - rows: tierListRows.map((row) => ({ name: row.name, tanks: [] })), - placedTanks: new Set(), + rows: Array.from({ length: tierListDefaultRowCount }, (_, index) => + createTierListRow(index), + ), }); - -enableMapSet();