mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-11-28 12:23:24 +01:00
migrate tier list
This commit is contained in:
108 files changed
+1238
-922
No files matched your search
@@ -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 `<Icon /> {label}` on one line. Spacing comes from the parent's flex `gap`, not a literal space:
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
<Icon />
|
||||||
|
{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.
|
||||||
@@ -2,7 +2,7 @@ export function Cache(disableInDev = false) {
|
|||||||
const cache = new WeakMap<object, Map<string, Promise<unknown>>>();
|
const cache = new WeakMap<object, Map<string, Promise<unknown>>>();
|
||||||
|
|
||||||
return function <This, Arguments extends any[], Return>(
|
return function <This, Arguments extends any[], Return>(
|
||||||
target: (this: This, ...args: Arguments) => Promise<Return>
|
target: (this: This, ...args: Arguments) => Promise<Return>,
|
||||||
// TODO: evaluate if we need context to make the error trace easier
|
// TODO: evaluate if we need context to make the error trace easier
|
||||||
// context: ClassMethodDecoratorContext<
|
// context: ClassMethodDecoratorContext<
|
||||||
// This,
|
// This,
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ export * from "./environment";
|
|||||||
export * from "./eventManager";
|
export * from "./eventManager";
|
||||||
export * from "./getTimeDaysAgo";
|
export * from "./getTimeDaysAgo";
|
||||||
export * from "./isExplosive";
|
export * from "./isExplosive";
|
||||||
export * from "./metaSortTank";
|
export * from "./metaSortTanks";
|
||||||
export * from "./normalizeBoundingBox";
|
export * from "./normalizeBoundingBox";
|
||||||
export * from "./patientFetchJSON";
|
export * from "./patientFetchJSON";
|
||||||
export * from "./popularTanks";
|
export * from "./popularTanks";
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@ import { GameDefinitions, TankDefinition } from "@blitzkit/protos";
|
|||||||
import { tankClassOrder } from "../config/tankClassOrder";
|
import { tankClassOrder } from "../config/tankClassOrder";
|
||||||
import { treeTypeOrder } from "../config/treeTypeOrder";
|
import { treeTypeOrder } from "../config/treeTypeOrder";
|
||||||
|
|
||||||
export function metaSortTank(
|
export function metaSortTanks(
|
||||||
tanks: TankDefinition[],
|
tanks: TankDefinition[],
|
||||||
gameDefinitions: GameDefinitions,
|
gameDefinitions: GameDefinitions,
|
||||||
) {
|
) {
|
||||||
@@ -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": {
|
"units": {
|
||||||
"m": "{value}m",
|
"m": "{value}m",
|
||||||
"mm": "{value}mm",
|
"mm": "{value}mm",
|
||||||
|
|||||||
@@ -39,10 +39,3 @@
|
|||||||
color: var(--gray-11);
|
color: var(--gray-11);
|
||||||
}
|
}
|
||||||
|
|
||||||
.actions {
|
|
||||||
display: flex;
|
|
||||||
justify-content: flex-end;
|
|
||||||
gap: var(--space-3);
|
|
||||||
|
|
||||||
margin-top: var(--space-3);
|
|
||||||
}
|
|
||||||
@@ -1,11 +1,18 @@
|
|||||||
import { AlertDialog as _ } from "radix-ui";
|
import { AlertDialog as _ } from "radix-ui";
|
||||||
import type { ComponentProps } from "react";
|
|
||||||
import { classNames } from "../../ui/classNames";
|
|
||||||
import { composeRadixComponents } from "../../ui/compose";
|
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";
|
import styles from "./index.module.css";
|
||||||
|
|
||||||
function Actions({ className, ...props }: ComponentProps<"div">) {
|
// TODO: figoure out tree shaking for these kinds of wrapped components
|
||||||
return <div className={classNames(styles.actions, className)} {...props} />;
|
// 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,
|
||||||
|
};
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import { PlusIcon, TrashIcon } from "@radix-ui/react-icons";
|
import { PlusIcon, TrashIcon } from "@radix-ui/react-icons";
|
||||||
import { useMemo, useState } from "react";
|
import { useMemo, useState } from "react";
|
||||||
import { tankToCompareMember } from "../../core/blitzkit/tankToCompareMember";
|
import { tankToCompareMember } from "../../core/blitzkit/tankToCompareMember";
|
||||||
|
import { withLocale } from "../../hocs/withLocale";
|
||||||
import { useStrings } from "../../hooks/useStrings";
|
import { useStrings } from "../../hooks/useStrings";
|
||||||
import { CompareEphemeral, syncShellSlot } from "../../stores/compareEphemeral";
|
import { CompareEphemeral, syncShellSlot } from "../../stores/compareEphemeral";
|
||||||
import {
|
import {
|
||||||
@@ -15,7 +16,9 @@ import { SegmentedControl } from "../SegmentedControl";
|
|||||||
import { TankSearchResults } from "../TankSearchResults";
|
import { TankSearchResults } from "../TankSearchResults";
|
||||||
import styles from "./index.module.css";
|
import styles from "./index.module.css";
|
||||||
|
|
||||||
export function CompareControls() {
|
export const CompareControls = withLocale(Content);
|
||||||
|
|
||||||
|
function Content() {
|
||||||
const strings = useStrings();
|
const strings = useStrings();
|
||||||
const deltaMode = ComparePersistent.use((state) => state.deltaMode);
|
const deltaMode = ComparePersistent.use((state) => state.deltaMode);
|
||||||
const syncShells = CompareEphemeral.use((state) => state.syncShells);
|
const syncShells = CompareEphemeral.use((state) => state.syncShells);
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
export const insertionMarkers = new Set<{
|
|
||||||
element: HTMLDivElement;
|
|
||||||
index: number;
|
|
||||||
}>();
|
|
||||||
@@ -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;
|
|
||||||
}
|
|
||||||
@@ -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<HTMLDivElement>(null);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const element = marker.current!;
|
|
||||||
const insertionMarker = { element, index };
|
|
||||||
|
|
||||||
insertionMarkers.add(insertionMarker);
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
insertionMarkers.delete(insertionMarker);
|
|
||||||
};
|
|
||||||
}, [index]);
|
|
||||||
|
|
||||||
return <div ref={marker} className={styles.marker} />;
|
|
||||||
}
|
|
||||||
@@ -7,7 +7,9 @@ import {
|
|||||||
} from "@radix-ui/react-icons";
|
} from "@radix-ui/react-icons";
|
||||||
import { useMemo } from "react";
|
import { useMemo } from "react";
|
||||||
import { characteristicsGroups } from "../../config/characteristicsGroups";
|
import { characteristicsGroups } from "../../config/characteristicsGroups";
|
||||||
|
import { compareInsertionMarker } from "../../config/compare";
|
||||||
import { computeCharacteristics } from "../../hooks/useCharacteristics";
|
import { computeCharacteristics } from "../../hooks/useCharacteristics";
|
||||||
|
import { withLocale } from "../../hocs/withLocale";
|
||||||
import { useStrings } from "../../hooks/useStrings";
|
import { useStrings } from "../../hooks/useStrings";
|
||||||
import { useUnwrapper } from "../../hooks/useUnwrapper";
|
import { useUnwrapper } from "../../hooks/useUnwrapper";
|
||||||
import {
|
import {
|
||||||
@@ -26,10 +28,11 @@ import {
|
|||||||
} from "../../types/characteristics";
|
} from "../../types/characteristics";
|
||||||
import { CharacteristicValue } from "../CharacteristicValue";
|
import { CharacteristicValue } from "../CharacteristicValue";
|
||||||
import { CompareEnvironment } from "../CompareEnvironment";
|
import { CompareEnvironment } from "../CompareEnvironment";
|
||||||
import { CompareInsertionMarker } from "../CompareInsertionMarker";
|
|
||||||
import { CompareLoadout } from "../CompareLoadout";
|
import { CompareLoadout } from "../CompareLoadout";
|
||||||
import { CompareTankCard } from "../CompareTankCard";
|
import { CompareTankCard } from "../CompareTankCard";
|
||||||
|
import { EmptyState } from "../EmptyState";
|
||||||
import { IconButton } from "../IconButton";
|
import { IconButton } from "../IconButton";
|
||||||
|
import { InsertionMarker } from "../InsertionMarker";
|
||||||
import { LazyImage } from "../LazyImage";
|
import { LazyImage } from "../LazyImage";
|
||||||
import { Table } from "../Table";
|
import { Table } from "../Table";
|
||||||
import { Text } from "../Text";
|
import { Text } from "../Text";
|
||||||
@@ -47,8 +50,15 @@ function without(ids: number[], excluded: number[]) {
|
|||||||
return remaining;
|
return remaining;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function CompareTable() {
|
// The table of members, or an empty state when there are none
|
||||||
const members = CompareEphemeral.use((state) => state.members);
|
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);
|
const environment = CompareEphemeral.use((state) => state.environment);
|
||||||
|
|
||||||
// Other tanks' consumables and provisions can reduce a tank's damage, so each
|
// Other tanks' consumables and provisions can reduce a tank's damage, so each
|
||||||
@@ -74,44 +84,55 @@ export function CompareTable() {
|
|||||||
});
|
});
|
||||||
}, [members, environment]);
|
}, [members, environment]);
|
||||||
|
|
||||||
|
if (members.length === 0) {
|
||||||
|
return (
|
||||||
|
<EmptyState
|
||||||
|
title={strings.compare.no_tanks.title}
|
||||||
|
body={strings.compare.no_tanks.body}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Table.Root>
|
<>
|
||||||
<Table.Head>
|
<Table.Root>
|
||||||
<Table.Row>
|
<Table.Head>
|
||||||
<Table.IconCorner>
|
<Table.Row>
|
||||||
<CompareInsertionMarker index={0} />
|
<Table.IconCorner />
|
||||||
</Table.IconCorner>
|
|
||||||
|
|
||||||
{members.map(({ key, state }, index) => (
|
{members.map(({ key, state }, index) => (
|
||||||
<CompareTankCard
|
<CompareTankCard
|
||||||
key={key}
|
key={key}
|
||||||
index={index}
|
index={index}
|
||||||
tank={resolveTankModules(state).tank}
|
tank={resolveTankModules(state).tank}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</Table.Row>
|
</Table.Row>
|
||||||
</Table.Head>
|
</Table.Head>
|
||||||
|
|
||||||
<Table.Body>
|
<Table.Body>
|
||||||
<Table.Row>
|
<Table.Row>
|
||||||
<Table.RowHeader>
|
<Table.RowHeader>
|
||||||
<CompareEnvironment />
|
<CompareEnvironment />
|
||||||
</Table.RowHeader>
|
</Table.RowHeader>
|
||||||
|
|
||||||
{members.map((member, index) => (
|
{members.map((member, index) => (
|
||||||
<LoadoutCell key={member.key} index={index} />
|
<LoadoutCell key={member.key} index={index} />
|
||||||
))}
|
))}
|
||||||
</Table.Row>
|
</Table.Row>
|
||||||
</Table.Body>
|
</Table.Body>
|
||||||
|
|
||||||
{characteristicsGroups.map((group) => (
|
{characteristicsGroups.map((group) => (
|
||||||
<Group
|
<Group
|
||||||
key={group.name}
|
key={group.name}
|
||||||
group={group}
|
group={group}
|
||||||
characteristics={characteristics}
|
characteristics={characteristics}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</Table.Root>
|
</Table.Root>
|
||||||
|
|
||||||
|
<InsertionMarker ref={compareInsertionMarker} />
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,10 +2,10 @@ import { tankIcon } from "@blitzkit/core";
|
|||||||
import type { TankDefinition } from "@blitzkit/protos";
|
import type { TankDefinition } from "@blitzkit/protos";
|
||||||
import { useEffect, useRef } from "react";
|
import { useEffect, useRef } from "react";
|
||||||
import { Vector2 } from "three";
|
import { Vector2 } from "three";
|
||||||
|
import { compareInsertionMarker } from "../../config/compare";
|
||||||
|
import { showInsertionMarker } from "../../core/blitzkit/showInsertionMarker";
|
||||||
import { useUnwrapper } from "../../hooks/useUnwrapper";
|
import { useUnwrapper } from "../../hooks/useUnwrapper";
|
||||||
import { CompareEphemeral } from "../../stores/compareEphemeral";
|
import { CompareEphemeral } from "../../stores/compareEphemeral";
|
||||||
import { CompareInsertionMarker } from "../CompareInsertionMarker";
|
|
||||||
import { insertionMarkers } from "../CompareInsertionMarker/constants";
|
|
||||||
import { CompareTankControl } from "../CompareTankControl";
|
import { CompareTankControl } from "../CompareTankControl";
|
||||||
import { LazyImage } from "../LazyImage";
|
import { LazyImage } from "../LazyImage";
|
||||||
import { Table } from "../Table";
|
import { Table } from "../Table";
|
||||||
@@ -24,9 +24,7 @@ export function CompareTankCard({ index, tank }: TankCardProps) {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const initial = new Vector2();
|
const initial = new Vector2();
|
||||||
const current = new Vector2();
|
const offset = new Vector2();
|
||||||
const delta = new Vector2();
|
|
||||||
const marker = new Vector2();
|
|
||||||
let initialRect = draggable.current!.getBoundingClientRect();
|
let initialRect = draggable.current!.getBoundingClientRect();
|
||||||
let dropIndex = -1;
|
let dropIndex = -1;
|
||||||
|
|
||||||
@@ -34,48 +32,44 @@ export function CompareTankCard({ index, tank }: TankCardProps) {
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
initialRect = draggable.current!.getBoundingClientRect();
|
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("pointermove", handlePointerMove);
|
||||||
window.addEventListener("pointerup", handlePointerUp);
|
window.addEventListener("pointerup", handlePointerUp);
|
||||||
}
|
}
|
||||||
function handlePointerMove(event: PointerEvent) {
|
function handlePointerMove(event: PointerEvent) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
current.set(event.clientX, event.clientY);
|
// Slot i sits on the right edge of the row's i-th cell: the corner, then each card
|
||||||
delta.copy(current).sub(initial);
|
const cells = header.current!.parentElement!.children;
|
||||||
insertionMarkers.forEach(({ element }) => {
|
let closestRect = cells[0].getBoundingClientRect();
|
||||||
element.style.opacity = "0";
|
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";
|
header.current!.dataset.dragging = "true";
|
||||||
draggable.current!.style.left = `${initialRect.left + delta.x}px`;
|
offset.set(event.clientX, event.clientY).sub(initial);
|
||||||
draggable.current!.style.top = `${initialRect.top + delta.y}px`;
|
draggable.current!.style.left = `${initialRect.left + offset.x}px`;
|
||||||
|
draggable.current!.style.top = `${initialRect.top + offset.y}px`;
|
||||||
}
|
}
|
||||||
function handlePointerUp(event: PointerEvent) {
|
function handlePointerUp(event: PointerEvent) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
delete header.current!.dataset.dragging;
|
delete header.current!.dataset.dragging;
|
||||||
|
showInsertionMarker(compareInsertionMarker.current!, undefined);
|
||||||
insertionMarkers.forEach(({ element }) => {
|
|
||||||
element.style.opacity = "0";
|
|
||||||
});
|
|
||||||
|
|
||||||
window.removeEventListener("pointermove", handlePointerMove);
|
window.removeEventListener("pointermove", handlePointerMove);
|
||||||
window.removeEventListener("pointerup", handlePointerUp);
|
window.removeEventListener("pointerup", handlePointerUp);
|
||||||
@@ -119,8 +113,6 @@ export function CompareTankCard({ index, tank }: TankCardProps) {
|
|||||||
<Text className={styles.name}>{unwrap(tank.name!)}</Text>
|
<Text className={styles.name}>{unwrap(tank.name!)}</Text>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<CompareInsertionMarker index={index + 1} />
|
|
||||||
</Table.ColumnHeader>
|
</Table.ColumnHeader>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
<!-- Keeps the members and the url in sync, so the url is always shareable -->
|
||||||
|
<script>
|
||||||
|
import { parse, stringify } from "urlon";
|
||||||
|
import { api } from "../api/dynamic";
|
||||||
|
import { tankToCompareMember } from "../core/blitzkit/tankToCompareMember";
|
||||||
|
import {
|
||||||
|
CompareEphemeral,
|
||||||
|
type CompareMember,
|
||||||
|
} from "../stores/compareEphemeral";
|
||||||
|
|
||||||
|
const tankDefinitions = await api.tanks();
|
||||||
|
|
||||||
|
// Tanks come from the url on load...
|
||||||
|
const state = new URLSearchParams(window.location.search).get("state");
|
||||||
|
|
||||||
|
if (state !== null) {
|
||||||
|
const tanks: number[] = parse(state);
|
||||||
|
|
||||||
|
CompareEphemeral.mutate((draft) => {
|
||||||
|
draft.members = tanks
|
||||||
|
.filter((id) => id in tankDefinitions.tanks)
|
||||||
|
.map((id) => tankDefinitions.tanks[id])
|
||||||
|
.map(tankToCompareMember);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// ...and are written back whenever they change
|
||||||
|
function writeURL(members: CompareMember[]) {
|
||||||
|
const search = new URLSearchParams(window.location.search);
|
||||||
|
|
||||||
|
search.set("state", stringify(members.map(({ state }) => state.tank)));
|
||||||
|
|
||||||
|
window.history.replaceState(
|
||||||
|
{},
|
||||||
|
"",
|
||||||
|
`${window.location.pathname}?${search.toString()}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
writeURL(CompareEphemeral.state.members);
|
||||||
|
CompareEphemeral.on((state) => state.members, writeURL);
|
||||||
|
</script>
|
||||||
@@ -42,14 +42,3 @@
|
|||||||
text-align: left;
|
text-align: left;
|
||||||
}
|
}
|
||||||
|
|
||||||
.header {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
gap: var(--space-2);
|
|
||||||
}
|
|
||||||
|
|
||||||
.body {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
gap: var(--space-4);
|
|
||||||
}
|
|
||||||
@@ -1,17 +1,17 @@
|
|||||||
import { Dialog as _ } from "radix-ui";
|
import { Dialog as _ } from "radix-ui";
|
||||||
import type { ComponentProps } from "react";
|
|
||||||
import { classNames } from "../../ui/classNames";
|
|
||||||
import { composeRadixComponents } from "../../ui/compose";
|
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";
|
import styles from "./index.module.css";
|
||||||
|
|
||||||
// Groups a title and description
|
// The extra parts live in their own components, shared by every dialog-like surface
|
||||||
function Header({ className, ...props }: ComponentProps<"div">) {
|
export const Dialog = {
|
||||||
return <div className={classNames(styles.header, className)} {...props} />;
|
...composeRadixComponents(_, styles),
|
||||||
}
|
|
||||||
|
|
||||||
// Stacks the content that follows the header
|
Header: DialogHeader,
|
||||||
function Body({ className, ...props }: ComponentProps<"div">) {
|
Body: DialogBody,
|
||||||
return <div className={classNames(styles.body, className)} {...props} />;
|
Actions: DialogActions,
|
||||||
}
|
Field: DialogField,
|
||||||
|
};
|
||||||
export const Dialog = { ...composeRadixComponents(_, styles), Header, Body };
|
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
.actions {
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-end;
|
||||||
|
gap: var(--space-3);
|
||||||
|
|
||||||
|
margin-top: var(--space-3);
|
||||||
|
}
|
||||||
@@ -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 <div className={classNames(styles.actions, className)} {...props} />;
|
||||||
|
}
|
||||||
+1
-2
@@ -1,6 +1,5 @@
|
|||||||
.top {
|
.body {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: center;
|
|
||||||
gap: var(--space-4);
|
gap: var(--space-4);
|
||||||
}
|
}
|
||||||
@@ -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 <div className={classNames(styles.body, className)} {...props} />;
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
.field {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: var(--space-3);
|
||||||
|
}
|
||||||
@@ -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 (
|
||||||
|
<div className={classNames(styles.field, className)} {...props}>
|
||||||
|
<Text lowContrast>{label}</Text>
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
.header {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: var(--space-2);
|
||||||
|
}
|
||||||
@@ -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 <div className={classNames(styles.header, className)} {...props} />;
|
||||||
|
}
|
||||||
@@ -8,10 +8,9 @@ import { CaretLeftIcon, Link2Icon, PersonIcon } from "@radix-ui/react-icons";
|
|||||||
import { debounce } from "lodash-es";
|
import { debounce } from "lodash-es";
|
||||||
import { useCallback, useRef, useState } from "react";
|
import { useCallback, useRef, useState } from "react";
|
||||||
import { stringify } from "urlon";
|
import { stringify } from "urlon";
|
||||||
import type { embedConfigurations } from "../../../constants/embeds";
|
import type { embedConfigurations } from "../../../config/embeds";
|
||||||
import { useStrings } from "../../../hooks/useStrings";
|
import { useStrings } from "../../../hooks/useStrings";
|
||||||
import { EmbedState, type EmbedStateStore } from "../../../stores/embedState";
|
import { EmbedState, type EmbedStateStore } from "../../../stores/embedState";
|
||||||
import { AlertDialog } from "../../AlertDialog";
|
|
||||||
import { Button } from "../../Button";
|
import { Button } from "../../Button";
|
||||||
import { CopyButton } from "../../CopyButton";
|
import { CopyButton } from "../../CopyButton";
|
||||||
import { Dialog } from "../../Dialog";
|
import { Dialog } from "../../Dialog";
|
||||||
@@ -51,7 +50,7 @@ export function GenerateURL({ embed }: GenerateURLProps) {
|
|||||||
setSearching(false);
|
setSearching(false);
|
||||||
setResults(results);
|
setResults(results);
|
||||||
}, 500),
|
}, 500),
|
||||||
[]
|
[],
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleChange = useCallback(() => {
|
const handleChange = useCallback(() => {
|
||||||
@@ -130,13 +129,13 @@ export function GenerateURL({ embed }: GenerateURLProps) {
|
|||||||
</div>
|
</div>
|
||||||
</Dialog.Body>
|
</Dialog.Body>
|
||||||
|
|
||||||
<AlertDialog.Actions>
|
<Dialog.Actions>
|
||||||
<Dialog.Close asChild>
|
<Dialog.Close asChild>
|
||||||
<Button color="red" variant="outline">
|
<Button color="red" variant="outline">
|
||||||
{generateStrings.cancel}
|
{generateStrings.cancel}
|
||||||
</Button>
|
</Button>
|
||||||
</Dialog.Close>
|
</Dialog.Close>
|
||||||
</AlertDialog.Actions>
|
</Dialog.Actions>
|
||||||
</Dialog.Content>
|
</Dialog.Content>
|
||||||
</Dialog.Portal>
|
</Dialog.Portal>
|
||||||
</Dialog.Root>
|
</Dialog.Root>
|
||||||
@@ -154,7 +153,7 @@ export function GenerateURL({ embed }: GenerateURLProps) {
|
|||||||
</Dialog.Description>
|
</Dialog.Description>
|
||||||
</Dialog.Header>
|
</Dialog.Header>
|
||||||
|
|
||||||
<AlertDialog.Actions>
|
<Dialog.Actions>
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
@@ -193,7 +192,7 @@ export function GenerateURL({ embed }: GenerateURLProps) {
|
|||||||
<Link2Icon />
|
<Link2Icon />
|
||||||
{generateStrings.success.copy}
|
{generateStrings.success.copy}
|
||||||
</CopyButton>
|
</CopyButton>
|
||||||
</AlertDialog.Actions>
|
</Dialog.Actions>
|
||||||
</Dialog.Content>
|
</Dialog.Content>
|
||||||
</Dialog.Portal>
|
</Dialog.Portal>
|
||||||
</Dialog.Root>
|
</Dialog.Root>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { useEffect, useRef } from "react";
|
import { useEffect, useRef } from "react";
|
||||||
import { embedPreviews } from "../../../constants/embeds";
|
import { embedPreviews } from "../../../config/embeds";
|
||||||
import { classNames } from "../../../ui/classNames";
|
import { classNames } from "../../../ui/classNames";
|
||||||
import { useEmbedStateCurry } from "../../../stores/embedState/utilities";
|
import { useEmbedStateCurry } from "../../../stores/embedState/utilities";
|
||||||
import styles from "./index.module.css";
|
import styles from "./index.module.css";
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import locales from "@blitzkit/i18n/locales.json";
|
|||||||
import { ReloadIcon } from "@radix-ui/react-icons";
|
import { ReloadIcon } from "@radix-ui/react-icons";
|
||||||
import { useEffect, useMemo, useState } from "react";
|
import { useEffect, useMemo, useState } from "react";
|
||||||
import { api } from "../../api/dynamic";
|
import { api } from "../../api/dynamic";
|
||||||
import { breakdownConfig } from "../../constants/embeds";
|
import { breakdownConfig } from "../../config/embeds";
|
||||||
import { awaitableAverageDefinitions } from "../../core/awaitables/averageDefinitions";
|
import { awaitableAverageDefinitions } from "../../core/awaitables/averageDefinitions";
|
||||||
import { useStrings } from "../../hooks/useStrings";
|
import { useStrings } from "../../hooks/useStrings";
|
||||||
import { EmbedBreakdown } from "../../stores/embedBreakdown";
|
import { EmbedBreakdown } from "../../stores/embedBreakdown";
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
import { api } from "../api/dynamic";
|
import { api } from "../api/dynamic";
|
||||||
import { tools } from "../constants/tools";
|
import { tools } from "../config/tools";
|
||||||
import { Heading } from "./Heading";
|
import { Heading } from "./Heading";
|
||||||
import { Section } from "./Section";
|
import { Section } from "./Section";
|
||||||
import ToolCard from "./ToolCard.astro";
|
import ToolCard from "./ToolCard.astro";
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
import { api } from "../api/dynamic";
|
import { api } from "../api/dynamic";
|
||||||
import { tools } from "../constants/tools";
|
import { tools } from "../config/tools";
|
||||||
import { Heading } from "./Heading";
|
import { Heading } from "./Heading";
|
||||||
import { Section } from "./Section";
|
import { Section } from "./Section";
|
||||||
import ToolCard from "./ToolCard.astro";
|
import ToolCard from "./ToolCard.astro";
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
import { api } from "../api/dynamic";
|
import { api } from "../api/dynamic";
|
||||||
import { tools } from "../constants/tools";
|
import { tools } from "../config/tools";
|
||||||
import { Heading } from "./Heading";
|
import { Heading } from "./Heading";
|
||||||
import { Section } from "./Section";
|
import { Section } from "./Section";
|
||||||
import ToolCard from "./ToolCard.astro";
|
import ToolCard from "./ToolCard.astro";
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
import { api } from "../api/dynamic";
|
import { api } from "../api/dynamic";
|
||||||
import { tools } from "../constants/tools";
|
import { tools } from "../config/tools";
|
||||||
import { Heading } from "./Heading";
|
import { Heading } from "./Heading";
|
||||||
import { Section } from "./Section";
|
import { Section } from "./Section";
|
||||||
import ToolCard from "./ToolCard.astro";
|
import ToolCard from "./ToolCard.astro";
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
import { api } from "../api/dynamic";
|
import { api } from "../api/dynamic";
|
||||||
import { tools } from "../constants/tools";
|
import { tools } from "../config/tools";
|
||||||
import { Heading } from "./Heading";
|
import { Heading } from "./Heading";
|
||||||
import { Section } from "./Section";
|
import { Section } from "./Section";
|
||||||
import ToolCard from "./ToolCard.astro";
|
import ToolCard from "./ToolCard.astro";
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
/* Spans the whole slot; its padding keeps the bar off the slot's edges */
|
||||||
|
.marker {
|
||||||
|
position: fixed;
|
||||||
|
z-index: 1;
|
||||||
|
|
||||||
|
box-sizing: border-box;
|
||||||
|
padding: var(--space-4) 0;
|
||||||
|
transform: translateX(-50%);
|
||||||
|
|
||||||
|
pointer-events: none;
|
||||||
|
opacity: 0;
|
||||||
|
|
||||||
|
&[data-visible="true"] {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bar {
|
||||||
|
width: var(--space-1);
|
||||||
|
height: 100%;
|
||||||
|
|
||||||
|
border-radius: var(--radius-max);
|
||||||
|
background-color: var(--accent-12);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
import type { Ref } from "react";
|
||||||
|
import styles from "./index.module.css";
|
||||||
|
|
||||||
|
interface InsertionMarkerProps {
|
||||||
|
ref: Ref<HTMLDivElement>;
|
||||||
|
}
|
||||||
|
|
||||||
|
// One shared bar, positioned by whatever is being dragged since only it knows where it would land
|
||||||
|
export function InsertionMarker({ ref }: InsertionMarkerProps) {
|
||||||
|
return (
|
||||||
|
<div ref={ref} className={styles.marker}>
|
||||||
|
<div className={styles.bar} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -3,7 +3,7 @@ import { alias } from "@blitzkit/core";
|
|||||||
import { GearIcon } from "@radix-ui/react-icons";
|
import { GearIcon } from "@radix-ui/react-icons";
|
||||||
import { api } from "../api/dynamic";
|
import { api } from "../api/dynamic";
|
||||||
import { getLocaleOptions } from "../core/i18n/getLocaleOptions";
|
import { getLocaleOptions } from "../core/i18n/getLocaleOptions";
|
||||||
import { tools, type Tool } from "../constants/tools";
|
import { tools, type Tool } from "../config/tools";
|
||||||
import type { LocaleAcceptorProps } from "../hooks/useLocale";
|
import type { LocaleAcceptorProps } from "../hooks/useLocale";
|
||||||
import { Logo } from "../icons/Logo";
|
import { Logo } from "../icons/Logo";
|
||||||
import { LinkI18nWrapper } from "./LinkI18nWrapper";
|
import { LinkI18nWrapper } from "./LinkI18nWrapper";
|
||||||
|
|||||||
@@ -14,3 +14,4 @@
|
|||||||
border-radius: var(--space-4);
|
border-radius: var(--space-4);
|
||||||
outline: var(--outline-interactive) !important;
|
outline: var(--outline-interactive) !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,5 +1,17 @@
|
|||||||
import { Popover as _ } from "radix-ui";
|
import { Popover as _ } from "radix-ui";
|
||||||
import { composeRadixComponents } from "../../ui/compose";
|
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";
|
import styles from "./index.module.css";
|
||||||
|
|
||||||
export const Popover = composeRadixComponents(_, styles);
|
// The extra parts live in their own components, shared by every dialog-like surface
|
||||||
|
export const Popover = {
|
||||||
|
...composeRadixComponents(_, styles),
|
||||||
|
|
||||||
|
Header: DialogHeader,
|
||||||
|
Body: DialogBody,
|
||||||
|
Actions: DialogActions,
|
||||||
|
Field: DialogField,
|
||||||
|
};
|
||||||
@@ -2,7 +2,6 @@ import { CameraIcon, CopyIcon, DownloadIcon } from "@radix-ui/react-icons";
|
|||||||
import { Jimp } from "jimp";
|
import { Jimp } from "jimp";
|
||||||
import { useCallback, type RefObject } from "react";
|
import { useCallback, type RefObject } from "react";
|
||||||
import { useStrings } from "../../hooks/useStrings";
|
import { useStrings } from "../../hooks/useStrings";
|
||||||
import { AlertDialog } from "../AlertDialog";
|
|
||||||
import { Button, type ButtonProps } from "../Button";
|
import { Button, type ButtonProps } from "../Button";
|
||||||
import { Dialog } from "../Dialog";
|
import { Dialog } from "../Dialog";
|
||||||
import { IconButton } from "../IconButton";
|
import { IconButton } from "../IconButton";
|
||||||
@@ -71,7 +70,7 @@ export function ScreenshotButton({ canvas, name, children, ...props }: Props) {
|
|||||||
</Dialog.Description>
|
</Dialog.Description>
|
||||||
</Dialog.Header>
|
</Dialog.Header>
|
||||||
|
|
||||||
<AlertDialog.Actions>
|
<Dialog.Actions>
|
||||||
<Dialog.Close asChild>
|
<Dialog.Close asChild>
|
||||||
<Button color="red" variant="outline">
|
<Button color="red" variant="outline">
|
||||||
{strings.common.screenshot.cancel}
|
{strings.common.screenshot.cancel}
|
||||||
@@ -116,7 +115,7 @@ export function ScreenshotButton({ canvas, name, children, ...props }: Props) {
|
|||||||
{strings.common.screenshot.download}
|
{strings.common.screenshot.download}
|
||||||
</Button>
|
</Button>
|
||||||
</Dialog.Close>
|
</Dialog.Close>
|
||||||
</AlertDialog.Actions>
|
</Dialog.Actions>
|
||||||
</Dialog.Content>
|
</Dialog.Content>
|
||||||
</Dialog.Portal>
|
</Dialog.Portal>
|
||||||
</Dialog.Root>
|
</Dialog.Root>
|
||||||
|
|||||||
@@ -40,7 +40,11 @@ function Root({ children, className, ...props }: RootProps) {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<table ref={table} className={styles.table}>
|
<table
|
||||||
|
ref={table}
|
||||||
|
className={classNames(styles.table, className)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
{children}
|
{children}
|
||||||
</table>
|
</table>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -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 { literals } from "@blitzkit/i18n/src/literals";
|
||||||
import type { TankDefinition } from "@blitzkit/protos";
|
import type { TankDefinition } from "@blitzkit/protos";
|
||||||
import fuzzysort from "fuzzysort";
|
import fuzzysort from "fuzzysort";
|
||||||
@@ -108,7 +108,7 @@ function Content({ onSelect, onSelectAll }: TankSearchResultsProps) {
|
|||||||
tankopediaSort.by === null ||
|
tankopediaSort.by === null ||
|
||||||
!sortableCharacteristics.has(tankopediaSort.by)
|
!sortableCharacteristics.has(tankopediaSort.by)
|
||||||
) {
|
) {
|
||||||
const byMeta = metaSortTank([...filtered], gameDefinitions);
|
const byMeta = metaSortTanks([...filtered], gameDefinitions);
|
||||||
|
|
||||||
return tankopediaSort.direction === SortDirection.Ascending
|
return tankopediaSort.direction === SortDirection.Ascending
|
||||||
? byMeta
|
? byMeta
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
import { UpdateIcon } from "@radix-ui/react-icons";
|
import { UpdateIcon } from "@radix-ui/react-icons";
|
||||||
import { Button, Flex, Heading } from "@radix-ui/themes";
|
import { Button, Flex, Heading } from "@radix-ui/themes";
|
||||||
import { useEffect, useRef } from "react";
|
import { useEffect, useRef } from "react";
|
||||||
import { SKIN_NUMBER } from "../../../../../../constants/skinNumber";
|
import { SKIN_NUMBER } from "../../../../../../config/skinNumber";
|
||||||
import { api } from "../../../../../../core/blitzkit/api";
|
import { api } from "../../../../../../core/blitzkit/api";
|
||||||
import { useLocale } from "../../../../../../hooks/useLocale";
|
import { useLocale } from "../../../../../../hooks/useLocale";
|
||||||
import { Duel } from "../../../../../../stores/duel";
|
import { Duel } from "../../../../../../stores/duel";
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { alias } from "@blitzkit/core";
|
|||||||
import { PauseIcon, PlayIcon } from "@radix-ui/react-icons";
|
import { PauseIcon, PlayIcon } from "@radix-ui/react-icons";
|
||||||
import { uniqBy } from "lodash-es";
|
import { uniqBy } from "lodash-es";
|
||||||
import { api } from "../../api/dynamic";
|
import { api } from "../../api/dynamic";
|
||||||
import { SKIN_NUMBER } from "../../constants/skinNumber";
|
import { SKIN_NUMBER } from "../../config/skinNumber";
|
||||||
import { useAbsoluteDisplay } from "../../hooks/useAbsoluteDisplay";
|
import { useAbsoluteDisplay } from "../../hooks/useAbsoluteDisplay";
|
||||||
import { useDuelModules } from "../../hooks/useDuelModules";
|
import { useDuelModules } from "../../hooks/useDuelModules";
|
||||||
import { hasSkinAnimations } from "../../hooks/useSkin";
|
import { hasSkinAnimations } from "../../hooks/useSkin";
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { TankClass, TankDefinition, TankType } from "@blitzkit/protos";
|
|||||||
import { amberDark, blueDark } from "@radix-ui/colors";
|
import { amberDark, blueDark } from "@radix-ui/colors";
|
||||||
import { times } from "lodash-es";
|
import { times } from "lodash-es";
|
||||||
import type { ComponentProps } from "react";
|
import type { ComponentProps } from "react";
|
||||||
import { breakdownConfig } from "../../constants/embeds";
|
import { breakdownConfig } from "../../config/embeds";
|
||||||
import { useUnwrapper } from "../../hooks/useUnwrapper";
|
import { useUnwrapper } from "../../hooks/useUnwrapper";
|
||||||
import { embedRadius, embedSpace } from "../../stores/embedState/tokens";
|
import { embedRadius, embedSpace } from "../../stores/embedState/tokens";
|
||||||
import { useEmbedStateCurry } from "../../stores/embedState/utilities";
|
import { useEmbedStateCurry } from "../../stores/embedState/utilities";
|
||||||
|
|||||||
@@ -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 (
|
|
||||||
<CopyButton
|
|
||||||
variant="outline"
|
|
||||||
copy={() =>
|
|
||||||
`${location.origin}/tier-list?${generateTierListParams(rows)}`
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<Share2Icon />
|
|
||||||
{strings.website.tools.tier_list.buttons.share}
|
|
||||||
</CopyButton>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -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 (
|
|
||||||
<Flex justify="center" gap="2">
|
|
||||||
<Button
|
|
||||||
color="red"
|
|
||||||
onClick={() => {
|
|
||||||
TierList.mutate((draft) => {
|
|
||||||
Object.assign(draft, TierList.initial);
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<ReloadIcon />
|
|
||||||
{strings.website.tools.tier_list.buttons.reset}
|
|
||||||
</Button>
|
|
||||||
|
|
||||||
<Share />
|
|
||||||
</Flex>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -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<HTMLInputElement>(null);
|
|
||||||
const [open, setOpen] = useState(false);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Table.RowHeaderCell
|
|
||||||
width="0"
|
|
||||||
style={{ backgroundColor: Var(rowStyle.color) }}
|
|
||||||
>
|
|
||||||
<Popover.Root open={open} onOpenChange={setOpen}>
|
|
||||||
<Popover.Trigger>
|
|
||||||
<Heading>
|
|
||||||
<Flex direction="column" align="center" gap="2">
|
|
||||||
{name}
|
|
||||||
|
|
||||||
<IconButton variant="solid" color="gray" highContrast>
|
|
||||||
<Pencil2Icon />
|
|
||||||
</IconButton>
|
|
||||||
</Flex>
|
|
||||||
</Heading>
|
|
||||||
</Popover.Trigger>
|
|
||||||
|
|
||||||
<Popover.Content>
|
|
||||||
<Flex direction="column" gap="2">
|
|
||||||
<TextField.Root
|
|
||||||
variant="classic"
|
|
||||||
placeholder="Tier name"
|
|
||||||
ref={input}
|
|
||||||
defaultValue={name}
|
|
||||||
onKeyDown={(event) => {
|
|
||||||
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);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<TextField.Slot>
|
|
||||||
<Pencil1Icon />
|
|
||||||
</TextField.Slot>
|
|
||||||
</TextField.Root>
|
|
||||||
|
|
||||||
<Flex gap="1" width="100%">
|
|
||||||
<Popover.Close
|
|
||||||
onClick={() => {
|
|
||||||
if (!input.current) return;
|
|
||||||
|
|
||||||
input.current.value = name;
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Button variant="outline" color="red" style={{ flex: 1 }}>
|
|
||||||
<Cross1Icon />
|
|
||||||
Cancel
|
|
||||||
</Button>
|
|
||||||
</Popover.Close>
|
|
||||||
|
|
||||||
<Button
|
|
||||||
style={{ flex: 1 }}
|
|
||||||
onClick={() => {
|
|
||||||
if (!input.current) return;
|
|
||||||
|
|
||||||
input.current.blur();
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<CheckIcon />
|
|
||||||
Apply
|
|
||||||
</Button>
|
|
||||||
</Flex>
|
|
||||||
</Flex>
|
|
||||||
</Popover.Content>
|
|
||||||
</Popover.Root>
|
|
||||||
</Table.RowHeaderCell>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -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<HTMLTableRowElement>(null);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!row.current) return;
|
|
||||||
|
|
||||||
tierListRowElements.add(row.current);
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
if (!row.current) return;
|
|
||||||
|
|
||||||
tierListRowElements.delete(row.current);
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Table.Row ref={row} data-index={index}>
|
|
||||||
<Header index={index} />
|
|
||||||
|
|
||||||
<Table.Cell>
|
|
||||||
<Flex wrap="wrap" height="100%">
|
|
||||||
{tanks.map((id, tankIndex) => {
|
|
||||||
const tank = tankDefinitions.tanks[id];
|
|
||||||
return (
|
|
||||||
<TierListTile
|
|
||||||
isPlaced
|
|
||||||
key={id}
|
|
||||||
tank={tank}
|
|
||||||
rowIndex={index}
|
|
||||||
tileIndex={tankIndex}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</Flex>
|
|
||||||
</Table.Cell>
|
|
||||||
</Table.Row>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -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<HTMLTableRowElement>();
|
|
||||||
export const tierListCardElements = tierListRows.map(
|
|
||||||
() => new Set<HTMLDivElement>(),
|
|
||||||
);
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
import { Table } from '@radix-ui/themes';
|
|
||||||
import { TierListRow } from '../Row';
|
|
||||||
import { tierListRows } from './constants';
|
|
||||||
|
|
||||||
export function TierListTable() {
|
|
||||||
return (
|
|
||||||
<Table.Root variant="surface" mb="6">
|
|
||||||
<Table.Body>
|
|
||||||
{tierListRows.map((_, index) => (
|
|
||||||
<TierListRow index={index} key={index} />
|
|
||||||
))}
|
|
||||||
</Table.Body>
|
|
||||||
</Table.Root>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -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<HTMLDivElement>(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<HTMLSpanElement>) => {
|
|
||||||
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 (
|
|
||||||
<Box
|
|
||||||
p="2"
|
|
||||||
ref={card}
|
|
||||||
data-tile-index={props.isPlaced ? props.tileIndex : undefined}
|
|
||||||
data-tile-id={props.tank.id}
|
|
||||||
onPointerDown={handlePointerDown}
|
|
||||||
style={{ cursor: "grab", touchAction: "none" }}
|
|
||||||
>
|
|
||||||
<TankCard noLink tank={props.tank} />
|
|
||||||
</Box>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -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 (
|
|
||||||
<TankCardWrapper>
|
|
||||||
{sorted.slice(0, loadedTiles).map((tank) => (
|
|
||||||
<TierListTile key={tank.id} tank={tank} />
|
|
||||||
))}
|
|
||||||
|
|
||||||
{times(Math.min(PREVIEW_COUNT, sorted.length - loadedTiles), (index) => {
|
|
||||||
return (
|
|
||||||
<TankCardSkeleton
|
|
||||||
key={index}
|
|
||||||
onIntersection={() => {
|
|
||||||
setLoadedTiles((state) => Math.min(state + 2, sorted.length));
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</TankCardWrapper>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -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;
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
.controls {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
gap: var(--space-3);
|
||||||
|
}
|
||||||
@@ -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 (
|
||||||
|
<div className={styles.controls}>
|
||||||
|
<Button
|
||||||
|
variant="soft"
|
||||||
|
color="red"
|
||||||
|
onClick={() => {
|
||||||
|
TierList.set(TierList.initial);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<ReloadIcon />
|
||||||
|
{strings.tier_list.reset}
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
{/* The url is kept in sync with the rows */}
|
||||||
|
<CopyButton variant="soft" copy={() => location.href}>
|
||||||
|
<Share2Icon />
|
||||||
|
{strings.tier_list.share}
|
||||||
|
</CopyButton>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
.tanks {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
@@ -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 (
|
||||||
|
<Table.Row data-row={index}>
|
||||||
|
<TierListRowHeader index={index} row={row} />
|
||||||
|
|
||||||
|
<Table.Cell className={styles.tanks} data-tier-cell>
|
||||||
|
<TankCardWrapper className={styles.wrapper} data-tier-grid>
|
||||||
|
{row.tanks.map((id) => (
|
||||||
|
<TierListTile key={id} id={id} />
|
||||||
|
))}
|
||||||
|
</TankCardWrapper>
|
||||||
|
</Table.Cell>
|
||||||
|
</Table.Row>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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<HTMLDivElement>) {
|
||||||
|
if (event.key === "Enter") apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Popover.Root
|
||||||
|
open={open}
|
||||||
|
onOpenChange={(open) => {
|
||||||
|
if (open) {
|
||||||
|
setName(row.name);
|
||||||
|
setColor(row.color);
|
||||||
|
}
|
||||||
|
|
||||||
|
setOpen(open);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Popover.Trigger asChild>
|
||||||
|
<Table.Cell className={styles.header} data-accent={row.color}>
|
||||||
|
<div className={styles.content}>
|
||||||
|
<Heading size="5" weight="bold">
|
||||||
|
{row.name}
|
||||||
|
</Heading>
|
||||||
|
|
||||||
|
<IconButton variant="solid" color="gray" highContrast size="minor">
|
||||||
|
<Pencil2Icon />
|
||||||
|
</IconButton>
|
||||||
|
</div>
|
||||||
|
</Table.Cell>
|
||||||
|
</Popover.Trigger>
|
||||||
|
|
||||||
|
<Popover.Portal>
|
||||||
|
<Popover.Content>
|
||||||
|
<Popover.Field label={strings.tier_list.edit.label}>
|
||||||
|
<TextField
|
||||||
|
autoFocus="always"
|
||||||
|
placeholder={strings.tier_list.edit.placeholder}
|
||||||
|
value={name}
|
||||||
|
onChange={(event) =>
|
||||||
|
setName((event.target as HTMLInputElement).value)
|
||||||
|
}
|
||||||
|
onKeyDown={handleKeyDown}
|
||||||
|
/>
|
||||||
|
</Popover.Field>
|
||||||
|
|
||||||
|
<Popover.Field label={strings.tier_list.edit.color}>
|
||||||
|
<div className={styles.swatches}>
|
||||||
|
{tierListColors.map((swatch) => (
|
||||||
|
<IconButton
|
||||||
|
key={swatch}
|
||||||
|
color={swatch}
|
||||||
|
size="minor"
|
||||||
|
className={styles.swatch}
|
||||||
|
data-selected={swatch === color}
|
||||||
|
onClick={() => setColor(swatch)}
|
||||||
|
>
|
||||||
|
<CheckIcon />
|
||||||
|
</IconButton>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</Popover.Field>
|
||||||
|
|
||||||
|
<Popover.Actions>
|
||||||
|
<Popover.Close asChild>
|
||||||
|
<Button variant="outline" color="red">
|
||||||
|
<Cross1Icon />
|
||||||
|
{strings.tier_list.edit.cancel}
|
||||||
|
</Button>
|
||||||
|
</Popover.Close>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
variant="soft"
|
||||||
|
color="red"
|
||||||
|
disabled={rowCount === 1}
|
||||||
|
onClick={remove}
|
||||||
|
>
|
||||||
|
<TrashIcon />
|
||||||
|
{strings.tier_list.edit.remove}
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Button onClick={apply}>
|
||||||
|
<CheckIcon />
|
||||||
|
{strings.tier_list.edit.apply}
|
||||||
|
</Button>
|
||||||
|
</Popover.Actions>
|
||||||
|
</Popover.Content>
|
||||||
|
</Popover.Portal>
|
||||||
|
</Popover.Root>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -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%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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 (
|
||||||
|
<>
|
||||||
|
<Table.Root className={styles.table}>
|
||||||
|
<Table.Body ref={tierListTable} className={styles.body}>
|
||||||
|
{rows.map((row, index) => (
|
||||||
|
<TierListRow key={index} index={index} row={row} />
|
||||||
|
))}
|
||||||
|
|
||||||
|
<Table.Row>
|
||||||
|
<Table.Cell colSpan={2} className={styles.add}>
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
className={styles.button}
|
||||||
|
onClick={() => {
|
||||||
|
TierList.mutate((draft) => {
|
||||||
|
draft.rows.push(createTierListRow(draft.rows.length));
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<PlusIcon />
|
||||||
|
{strings.tier_list.add}
|
||||||
|
</Button>
|
||||||
|
</Table.Cell>
|
||||||
|
</Table.Row>
|
||||||
|
</Table.Body>
|
||||||
|
</Table.Root>
|
||||||
|
|
||||||
|
<InsertionMarker ref={tierListInsertionMarker} />
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
.tile {
|
||||||
|
cursor: grab;
|
||||||
|
touch-action: none;
|
||||||
|
|
||||||
|
&[data-dragging="true"] {
|
||||||
|
position: fixed;
|
||||||
|
z-index: 1;
|
||||||
|
|
||||||
|
cursor: grabbing;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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<TierListTileProps>,
|
||||||
|
) {
|
||||||
|
const card = useRef<HTMLDivElement>(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<TierListDropTarget | undefined>(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<HTMLElement>("[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<HTMLElement>("[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<HTMLDivElement>) => {
|
||||||
|
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 <TankCardSkeleton onIntersection={props.onIntersection} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
ref={card}
|
||||||
|
className={styles.tile}
|
||||||
|
data-tank-id={props.id}
|
||||||
|
onPointerDown={handlePointerDown}
|
||||||
|
>
|
||||||
|
<TankCard noLink tank={tankDefinitions.tanks[props.id]} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -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 <TankSearchNoResults />;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<TankCardWrapper>
|
||||||
|
<IncrementalLoader
|
||||||
|
initial={2 ** 6}
|
||||||
|
intermediate={2 ** 4}
|
||||||
|
data={data}
|
||||||
|
Component={TierListTile}
|
||||||
|
/>
|
||||||
|
</TankCardWrapper>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
<!-- Keeps the rows and the url in sync, so the url is always shareable -->
|
||||||
|
<script>
|
||||||
|
import { parse, stringify } from "urlon";
|
||||||
|
import { api } from "../api/dynamic";
|
||||||
|
import { tierListColors } from "../config/tierList";
|
||||||
|
import { TierList } from "../stores/tierList";
|
||||||
|
|
||||||
|
const tankDefinitions = await api.tanks();
|
||||||
|
|
||||||
|
// Rows come from the url on load...
|
||||||
|
const state = new URLSearchParams(window.location.search).get("state");
|
||||||
|
|
||||||
|
if (state !== null) {
|
||||||
|
const rows: TierList["rows"] = parse(state);
|
||||||
|
|
||||||
|
TierList.mutate((draft) => {
|
||||||
|
// Tanks and colors that no longer exist are dropped rather than trusted
|
||||||
|
draft.rows = rows.map((row, index) => {
|
||||||
|
const color = tierListColors.includes(row.color)
|
||||||
|
? row.color
|
||||||
|
: tierListColors[index % tierListColors.length];
|
||||||
|
const tanks = row.tanks.filter((id) => id in tankDefinitions.tanks);
|
||||||
|
|
||||||
|
return { name: row.name, color, tanks };
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// ...and are written back whenever they change
|
||||||
|
function writeURL(rows: TierList["rows"]) {
|
||||||
|
const search = new URLSearchParams(window.location.search);
|
||||||
|
|
||||||
|
search.set("state", stringify(rows));
|
||||||
|
|
||||||
|
window.history.replaceState(
|
||||||
|
{},
|
||||||
|
"",
|
||||||
|
`${window.location.pathname}?${search.toString()}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
writeURL(TierList.state.rows);
|
||||||
|
TierList.on((state) => state.rows, writeURL);
|
||||||
|
</script>
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
---
|
---
|
||||||
import { alias } from "@blitzkit/core";
|
import { alias } from "@blitzkit/core";
|
||||||
import { api } from "../api/dynamic";
|
import { api } from "../api/dynamic";
|
||||||
import type { Tool } from "../constants/tools";
|
import type { Tool } from "../config/tools";
|
||||||
import { Logo } from "../icons/Logo";
|
import { Logo } from "../icons/Logo";
|
||||||
import { Heading } from "./Heading";
|
import { Heading } from "./Heading";
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
---
|
---
|
||||||
import { alias } from "@blitzkit/core";
|
import { alias } from "@blitzkit/core";
|
||||||
import { api } from "../api/dynamic";
|
import { api } from "../api/dynamic";
|
||||||
import type { Tool } from "../constants/tools";
|
import type { Tool } from "../config/tools";
|
||||||
import { Heading } from "./Heading";
|
import { Heading } from "./Heading";
|
||||||
import { LinkI18n } from "./LinkI18n";
|
import { LinkI18n } from "./LinkI18n";
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
---
|
---
|
||||||
import { AstroSeo } from "@astrolib/seo";
|
import { AstroSeo } from "@astrolib/seo";
|
||||||
import { api } from "../api/dynamic";
|
import { api } from "../api/dynamic";
|
||||||
import type { Tool } from "../constants/tools";
|
import type { Tool } from "../config/tools";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
tool: Tool;
|
tool: Tool;
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
import { createRef } from "react";
|
||||||
|
|
||||||
|
// One shared bar showing where a dragged tank would land
|
||||||
|
export const compareInsertionMarker = createRef<HTMLDivElement>();
|
||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -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<HTMLTableSectionElement>();
|
||||||
|
|
||||||
|
// One shared bar showing where a dragged tank would land
|
||||||
|
export const tierListInsertionMarker = createRef<HTMLDivElement>();
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { discordLink } from "../config/socials";
|
import { discordLink } from "./socials";
|
||||||
|
|
||||||
export interface Tool {
|
export interface Tool {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -66,10 +66,9 @@ export const tools: Record<string, Tool> = {
|
|||||||
banner_background_position: "bottom",
|
banner_background_position: "bottom",
|
||||||
},
|
},
|
||||||
tier_list: {
|
tier_list: {
|
||||||
disabled: true,
|
|
||||||
id: "tier_list",
|
id: "tier_list",
|
||||||
slug: "tier-list",
|
slug: "tier-list",
|
||||||
banner_background_position: "bottom",
|
banner_background_position: "top",
|
||||||
},
|
},
|
||||||
embed: {
|
embed: {
|
||||||
id: "embed",
|
id: "embed",
|
||||||
@@ -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;
|
|
||||||
}
|
|
||||||
@@ -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`;
|
||||||
|
}
|
||||||
@@ -7,7 +7,7 @@ import ColorScale from "../components/ColorScale.astro";
|
|||||||
import NavbarCourse from "../components/NavbarCourse.astro";
|
import NavbarCourse from "../components/NavbarCourse.astro";
|
||||||
import NavbarFine from "../components/NavbarFine.astro";
|
import NavbarFine from "../components/NavbarFine.astro";
|
||||||
import SystemTheme from "../components/SystemTheme.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 { LocaleAcceptorProps } from "../hooks/useLocale";
|
||||||
import type { Color } from "../ui/color";
|
import type { Color } from "../ui/color";
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { Link } from "../components/Link";
|
|||||||
import { LinkI18n } from "../components/LinkI18n";
|
import { LinkI18n } from "../components/LinkI18n";
|
||||||
import { Text } from "../components/Text";
|
import { Text } from "../components/Text";
|
||||||
import { discordLink } from "../config/socials";
|
import { discordLink } from "../config/socials";
|
||||||
import { tools } from "../constants/tools";
|
import { tools } from "../config/tools";
|
||||||
import BaseLayout from "../layouts/BaseLayout.astro";
|
import BaseLayout from "../layouts/BaseLayout.astro";
|
||||||
|
|
||||||
// the 404 page is not locale-scoped, so it always renders in the default locale
|
// the 404 page is not locale-scoped, so it always renders in the default locale
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import {
|
|||||||
TOOL_BANNER_HEIGHTS,
|
TOOL_BANNER_HEIGHTS,
|
||||||
ToolBannerSize,
|
ToolBannerSize,
|
||||||
tools,
|
tools,
|
||||||
} from "../../../../../constants/tools";
|
} from "../../../../../config/tools";
|
||||||
import { getStaticPaths as _getStaticPaths } from "../../../_index";
|
import { getStaticPaths as _getStaticPaths } from "../../../_index";
|
||||||
|
|
||||||
interface ToolBannerProps {
|
interface ToolBannerProps {
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
import { Flex, Heading, Text } from "@radix-ui/themes";
|
import { Flex, Heading, Text } from "@radix-ui/themes";
|
||||||
import { PageWrapper } from "../../../../../components/PageWrapper";
|
import { PageWrapper } from "../../../../../components/PageWrapper";
|
||||||
import { mixStaticPaths } from "../../../../../core/blitzkit/mixStaticPaths";
|
import { mixStaticPaths } from "../../../../../core/blitzkit/mixStaticPaths";
|
||||||
import { tools } from "../../../../../constants/tools";
|
import { tools } from "../../../../../config/tools";
|
||||||
import BaseLayout from "../../../../../layouts/BaseLayout.astro";
|
import BaseLayout from "../../../../../layouts/BaseLayout.astro";
|
||||||
import { getStaticPaths as _getStaticPaths } from "../../index.astro";
|
import { getStaticPaths as _getStaticPaths } from "../../index.astro";
|
||||||
import { AUTH_PROVIDER_NAMES, AUTH_PROVIDERS, Authorize } from "./_index";
|
import { AUTH_PROVIDER_NAMES, AUTH_PROVIDERS, Authorize } from "./_index";
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
---
|
---
|
||||||
import { Section } from "../../../../components/Section";
|
import { Section } from "../../../../components/Section";
|
||||||
import ToolBanner from "../../../../components/ToolBanner.astro";
|
import ToolBanner from "../../../../components/ToolBanner.astro";
|
||||||
import { tools } from "../../../../constants/tools";
|
import { tools } from "../../../../config/tools";
|
||||||
import BaseLayout from "../../../../layouts/BaseLayout.astro";
|
import BaseLayout from "../../../../layouts/BaseLayout.astro";
|
||||||
import { Page } from "./_index";
|
import { Page } from "./_index";
|
||||||
|
|
||||||
|
|||||||
@@ -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 <Content />;
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
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 (
|
|
||||||
<>
|
|
||||||
<Section>
|
|
||||||
<div className={styles.top}>
|
|
||||||
<CompareControls />
|
|
||||||
</div>
|
|
||||||
</Section>
|
|
||||||
|
|
||||||
{members.length > 0 && (
|
|
||||||
<Section overflow>
|
|
||||||
<CompareTable />
|
|
||||||
</Section>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{members.length === 0 && (
|
|
||||||
<Section>
|
|
||||||
<EmptyState
|
|
||||||
title={strings.compare.no_tanks.title}
|
|
||||||
body={strings.compare.no_tanks.body}
|
|
||||||
/>
|
|
||||||
</Section>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,9 +1,12 @@
|
|||||||
---
|
---
|
||||||
import ColorScale from "../../../../components/ColorScale.astro";
|
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 ToolBanner from "../../../../components/ToolBanner.astro";
|
||||||
import { tools } from "../../../../constants/tools";
|
import { tools } from "../../../../config/tools";
|
||||||
import BaseLayout from "../../../../layouts/BaseLayout.astro";
|
import BaseLayout from "../../../../layouts/BaseLayout.astro";
|
||||||
import { Page } from "./_index";
|
|
||||||
|
|
||||||
export { getStaticPaths } from "../index.astro";
|
export { getStaticPaths } from "../index.astro";
|
||||||
|
|
||||||
@@ -15,8 +18,25 @@ const { locale } = Astro.props;
|
|||||||
<ColorScale color="amber" />
|
<ColorScale color="amber" />
|
||||||
<ColorScale color="blue" />
|
<ColorScale color="blue" />
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.controls {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
<BaseLayout tool={tools.compare} accent="pink" {locale}>
|
<BaseLayout tool={tools.compare} accent="pink" {locale}>
|
||||||
<!-- TODO: add svg art for this tool -->
|
<!-- TODO: add svg art for this tool -->
|
||||||
<ToolBanner tool={tools.compare} {locale} />
|
<ToolBanner tool={tools.compare} {locale} />
|
||||||
<Page {locale} client:load />
|
<CompareURLManager />
|
||||||
|
|
||||||
|
<Section>
|
||||||
|
<div class="controls">
|
||||||
|
<CompareControls {locale} client:load />
|
||||||
|
</div>
|
||||||
|
</Section>
|
||||||
|
|
||||||
|
<Section overflow>
|
||||||
|
<CompareTable {locale} client:load />
|
||||||
|
</Section>
|
||||||
</BaseLayout>
|
</BaseLayout>
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
import { CheckIcon, StarFilledIcon } from "@radix-ui/react-icons";
|
import { CheckIcon, StarFilledIcon } from "@radix-ui/react-icons";
|
||||||
import { Badge } from "../../../components/Badge";
|
import { Badge } from "../../../components/Badge";
|
||||||
import ColorScale from "../../../components/ColorScale.astro";
|
import ColorScale from "../../../components/ColorScale.astro";
|
||||||
import { tools } from "../../../constants/tools";
|
import { tools } from "../../../config/tools";
|
||||||
import BaseLayout from "../../../layouts/BaseLayout.astro";
|
import BaseLayout from "../../../layouts/BaseLayout.astro";
|
||||||
import type { Color } from "../../../ui/color";
|
import type { Color } from "../../../ui/color";
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
import CreditsPromo from "../../../../components/CreditsPromo.astro";
|
import CreditsPromo from "../../../../components/CreditsPromo.astro";
|
||||||
import { tools } from "../../../../constants/tools";
|
import { tools } from "../../../../config/tools";
|
||||||
import ToolLayout from "../../../../layouts/ToolLayout.astro";
|
import ToolLayout from "../../../../layouts/ToolLayout.astro";
|
||||||
|
|
||||||
export { getStaticPaths } from "../index.astro";
|
export { getStaticPaths } from "../index.astro";
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
---
|
---
|
||||||
import { readFile } from "fs/promises";
|
import { readFile } from "fs/promises";
|
||||||
import { mixStaticPaths } from "../../../../../../core/blitzkit/mixStaticPaths";
|
import { mixStaticPaths } from "../../../../../../core/blitzkit/mixStaticPaths";
|
||||||
import { tools } from "../../../../../../constants/tools";
|
import { tools } from "../../../../../../config/tools";
|
||||||
import BaseLayout from "../../../../../../layouts/BaseLayout.astro";
|
import BaseLayout from "../../../../../../layouts/BaseLayout.astro";
|
||||||
import { getStaticPaths as _getStaticPaths } from "../../../index.astro";
|
import { getStaticPaths as _getStaticPaths } from "../../../index.astro";
|
||||||
import { Page } from "./_index";
|
import { Page } from "./_index";
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { MagicWandIcon, StarFilledIcon } from "@radix-ui/react-icons";
|
|||||||
import { Flex, Heading, Link } from "@radix-ui/themes";
|
import { Flex, Heading, Link } from "@radix-ui/themes";
|
||||||
import { compareVersions } from "compare-versions";
|
import { compareVersions } from "compare-versions";
|
||||||
import { PageWrapper } from "../../../../../components/PageWrapper";
|
import { PageWrapper } from "../../../../../components/PageWrapper";
|
||||||
import { tools } from "../../../../../constants/tools";
|
import { tools } from "../../../../../config/tools";
|
||||||
import BaseLayout from "../../../../../layouts/BaseLayout.astro";
|
import BaseLayout from "../../../../../layouts/BaseLayout.astro";
|
||||||
|
|
||||||
export { getStaticPaths } from "../../index.astro";
|
export { getStaticPaths } from "../../index.astro";
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ import { Text } from "../../../../../components/Text";
|
|||||||
import {
|
import {
|
||||||
embedConfigurations,
|
embedConfigurations,
|
||||||
extractEmbedConfigDefaults,
|
extractEmbedConfigDefaults,
|
||||||
} from "../../../../../constants/embeds";
|
} from "../../../../../config/embeds";
|
||||||
import {
|
import {
|
||||||
LocaleProvider,
|
LocaleProvider,
|
||||||
type LocaleAcceptorProps,
|
type LocaleAcceptorProps,
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@ import {
|
|||||||
embedConfigurations,
|
embedConfigurations,
|
||||||
embedRenderers,
|
embedRenderers,
|
||||||
extractEmbedConfigDefaults,
|
extractEmbedConfigDefaults,
|
||||||
} from "../../../../../../constants/embeds";
|
} from "../../../../../../config/embeds";
|
||||||
import {
|
import {
|
||||||
LocaleProvider,
|
LocaleProvider,
|
||||||
type LocaleAcceptorProps,
|
type LocaleAcceptorProps,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
---
|
---
|
||||||
import { mixStaticPaths } from "../../../../../astro/mixStaticPaths";
|
import { mixStaticPaths } from "../../../../../astro/mixStaticPaths";
|
||||||
import { embedConfigurations } from "../../../../../constants/embeds";
|
import { embedConfigurations } from "../../../../../config/embeds";
|
||||||
import { tools } from "../../../../../constants/tools";
|
import { tools } from "../../../../../config/tools";
|
||||||
import BaseLayout from "../../../../../layouts/BaseLayout.astro";
|
import BaseLayout from "../../../../../layouts/BaseLayout.astro";
|
||||||
import { getStaticPaths as _getStaticPaths } from "../index.astro";
|
import { getStaticPaths as _getStaticPaths } from "../index.astro";
|
||||||
import { Page } from "./_index";
|
import { Page } from "./_index";
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { Link } from "../../../../components/Link";
|
|||||||
import { LinkI18n } from "../../../../components/LinkI18n";
|
import { LinkI18n } from "../../../../components/LinkI18n";
|
||||||
import { Text } from "../../../../components/Text";
|
import { Text } from "../../../../components/Text";
|
||||||
import { discordLink } from "../../../../config/socials";
|
import { discordLink } from "../../../../config/socials";
|
||||||
import { embedConfigurations } from "../../../../constants/embeds";
|
import { embedConfigurations } from "../../../../config/embeds";
|
||||||
import {
|
import {
|
||||||
type LocaleAcceptorProps,
|
type LocaleAcceptorProps,
|
||||||
LocaleProvider,
|
LocaleProvider,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
import ToolBanner from "../../../../components/ToolBanner.astro";
|
import ToolBanner from "../../../../components/ToolBanner.astro";
|
||||||
import { tools } from "../../../../constants/tools";
|
import { tools } from "../../../../config/tools";
|
||||||
import BaseLayout from "../../../../layouts/BaseLayout.astro";
|
import BaseLayout from "../../../../layouts/BaseLayout.astro";
|
||||||
import { Page } from "./_index";
|
import { Page } from "./_index";
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
import ColorScale from "../../../../components/ColorScale.astro";
|
import ColorScale from "../../../../components/ColorScale.astro";
|
||||||
import { tools } from "../../../../constants/tools";
|
import { tools } from "../../../../config/tools";
|
||||||
import BaseLayout from "../../../../layouts/BaseLayout.astro";
|
import BaseLayout from "../../../../layouts/BaseLayout.astro";
|
||||||
import { Page } from "./_index";
|
import { Page } from "./_index";
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import HomeGames from "../../../components/HomeGames.astro";
|
|||||||
import HomePlayers from "../../../components/HomePlayers.astro";
|
import HomePlayers from "../../../components/HomePlayers.astro";
|
||||||
import HomeTanks from "../../../components/HomeTanks.astro";
|
import HomeTanks from "../../../components/HomeTanks.astro";
|
||||||
import HomeTechnical from "../../../components/HomeTechnical.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 BaseLayout from "../../../layouts/BaseLayout.astro";
|
||||||
import { getStaticPaths as _getStaticPaths } from "../_index";
|
import { getStaticPaths as _getStaticPaths } from "../_index";
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
import ToolOpenGraph from "../../../../components/ToolOpenGraph.astro";
|
import ToolOpenGraph from "../../../../components/ToolOpenGraph.astro";
|
||||||
import { tools } from "../../../../constants/tools";
|
import { tools } from "../../../../config/tools";
|
||||||
import BaseLayout from "../../../../layouts/BaseLayout.astro";
|
import BaseLayout from "../../../../layouts/BaseLayout.astro";
|
||||||
import { Page } from "./_index";
|
import { Page } from "./_index";
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
---
|
---
|
||||||
import ColorScale from "../../../../components/ColorScale.astro";
|
import ColorScale from "../../../../components/ColorScale.astro";
|
||||||
import ToolBanner from "../../../../components/ToolBanner.astro";
|
import ToolBanner from "../../../../components/ToolBanner.astro";
|
||||||
import { tools } from "../../../../constants/tools";
|
import { tools } from "../../../../config/tools";
|
||||||
import BaseLayout from "../../../../layouts/BaseLayout.astro";
|
import BaseLayout from "../../../../layouts/BaseLayout.astro";
|
||||||
import { Page } from "./_index";
|
import { Page } from "./_index";
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
import ToolOpenGraph from "../../../../components/ToolOpenGraph.astro";
|
import ToolOpenGraph from "../../../../components/ToolOpenGraph.astro";
|
||||||
import { tools } from "../../../../constants/tools";
|
import { tools } from "../../../../config/tools";
|
||||||
import BaseLayout from "../../../../layouts/BaseLayout.astro";
|
import BaseLayout from "../../../../layouts/BaseLayout.astro";
|
||||||
import { Page } from "./_index.tsx";
|
import { Page } from "./_index.tsx";
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
import { tools } from "../../../../constants/tools";
|
import { tools } from "../../../../config/tools";
|
||||||
import ToolLayout from "../../../../layouts/ToolLayout.astro";
|
import ToolLayout from "../../../../layouts/ToolLayout.astro";
|
||||||
import type { getStaticPaths } from "../index.astro";
|
import type { getStaticPaths } from "../index.astro";
|
||||||
import { Page } from "./_index";
|
import { Page } from "./_index";
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { api } from "../../../../../api/dynamic";
|
|||||||
import { mixStaticPaths } from "../../../../../astro/mixStaticPaths";
|
import { mixStaticPaths } from "../../../../../astro/mixStaticPaths";
|
||||||
import ColorRanks from "../../../../../components/ColorRanks.astro";
|
import ColorRanks from "../../../../../components/ColorRanks.astro";
|
||||||
import ColorScale from "../../../../../components/ColorScale.astro";
|
import ColorScale from "../../../../../components/ColorScale.astro";
|
||||||
import { tools } from "../../../../../constants/tools";
|
import { tools } from "../../../../../config/tools";
|
||||||
import BaseLayout from "../../../../../layouts/BaseLayout.astro";
|
import BaseLayout from "../../../../../layouts/BaseLayout.astro";
|
||||||
import { getStaticPaths as _getStaticPaths } from "../index.astro";
|
import { getStaticPaths as _getStaticPaths } from "../index.astro";
|
||||||
import { Loadout, Sandbox } from "./_index";
|
import { Loadout, Sandbox } from "./_index";
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { TankSearchBar } from "../../../../components/TankSearchBar";
|
|||||||
import { TankSearchFilters } from "../../../../components/TankSearchFilters";
|
import { TankSearchFilters } from "../../../../components/TankSearchFilters";
|
||||||
import { TankSearchResults } from "../../../../components/TankSearchResults";
|
import { TankSearchResults } from "../../../../components/TankSearchResults";
|
||||||
import ToolBanner from "../../../../components/ToolBanner.astro";
|
import ToolBanner from "../../../../components/ToolBanner.astro";
|
||||||
import { tools } from "../../../../constants/tools";
|
import { tools } from "../../../../config/tools";
|
||||||
import BaseLayout from "../../../../layouts/BaseLayout.astro";
|
import BaseLayout from "../../../../layouts/BaseLayout.astro";
|
||||||
|
|
||||||
export { getStaticPaths } from "../index.astro";
|
export { getStaticPaths } from "../index.astro";
|
||||||
|
|||||||
Loaded 100 of 108 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user