migrate settings

This commit is contained in:
tresabhi committed 2026-11-22 13:58:17 -06:00
1 parent 8dd412ed32
commit 1b50f0bcdd
25 files changed
+335 -237

No files matched your search

+24 -62
View File
@@ -4,6 +4,13 @@
"settings": "Settings"
},
"settings": {
"language": "Language",
"device_language": "Device language",
"auto_load_models": "Auto-load models",
"developer_mode": "Developer mode"
},
"mixer": {
"screenshot": "Screenshot",
"randomize": "Randomize"
@@ -477,60 +484,23 @@
},
"tools": {
"home": {
"name": "Home"
},
"tanks": {
"name": "Tankopedia"
},
"avatars": {
"name": "Avatars"
},
"backgrounds": {
"name": "Backgrounds"
},
"api": {
"name": "API"
},
"players": {
"name": "Players"
},
"compare": {
"name": "Compare"
},
"performance": {
"name": "Performance"
},
"playlist": {
"name": "Playlist"
},
"mixer": {
"name": "Mixer"
},
"session": {
"name": "Session"
},
"guesser": {
"name": "Guesser"
},
"changelogs": {
"name": "Changelogs"
},
"settings": {
"name": "Settings"
},
"tier_list": {
"name": "Tier list"
},
"embed": {
"name": "Embed"
},
"more": {
"name": "More"
},
"credits": {
"name": "Credits"
}
"home": "Home",
"tanks": "Tankopedia",
"avatars": "Avatars",
"backgrounds": "Backgrounds",
"api": "API",
"players": "Players",
"compare": "Compare",
"performance": "Performance",
"playlist": "Playlist",
"mixer": "Mixer",
"session": "Session",
"guesser": "Guesser",
"changelogs": "Changelogs",
"tier_list": "Tier list",
"embed": "Embed",
"more": "More",
"credits": "Credits"
},
"home": {
@@ -789,14 +759,6 @@
"body": "Where would you like to go?"
},
"settings": {
"title": "Settings",
"description": "Change BlitzKit settings",
"dev_mode": "Development mode",
"auto_load_models": "Auto-load models",
"language": "Language"
},
"common": {
"copy_button": {
"copied": "Copied!"
@@ -11,7 +11,7 @@
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 2;
z-index: 1;
display: flex;
flex-direction: column;
@@ -1,5 +1,9 @@
import { ContextMenu as _ } from "radix-ui";
import { composeRadixComponents } from "../../ui/compose";
import { Discriminator } from "../DropdownMenu";
import styles from "./index.module.css";
export const ContextMenu = composeRadixComponents(_, styles);
export const ContextMenu = {
...composeRadixComponents(_, styles),
Discriminator,
};
@@ -11,7 +11,7 @@
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 2;
z-index: 1;
display: flex;
flex-direction: column;
@@ -49,7 +49,7 @@
}
.body {
--scroller-curtain-color: var(--gray-2);
flex: 1;
display: flex;
flex-direction: column;
gap: var(--space-4);
}
@@ -2,7 +2,6 @@ import { Dialog as _ } from "radix-ui";
import type { ComponentProps } from "react";
import { classNames } from "../../ui/classNames";
import { composeRadixComponents } from "../../ui/compose";
import { Scroller, ScrollerOrientation } from "../Scroller";
import styles from "./index.module.css";
// Groups a title and description
@@ -10,15 +9,9 @@ function Header({ className, ...props }: ComponentProps<"div">) {
return <div className={classNames(styles.header, className)} {...props} />;
}
// Scrolls the content that follows the header
function Body({ className, ...props }: ComponentProps<typeof Scroller>) {
return (
<Scroller
orientation={ScrollerOrientation.Vertical}
className={classNames(styles.body, className)}
{...props}
/>
);
// Stacks the content that follows the header
function Body({ className, ...props }: ComponentProps<"div">) {
return <div className={classNames(styles.body, className)} {...props} />;
}
export const Dialog = { ...composeRadixComponents(_, styles), Header, Body };
@@ -98,6 +98,11 @@
}
}
.discriminator {
display: inline;
margin-left: auto;
}
.ItemIndicator {
position: absolute;
left: 0;
@@ -1,5 +1,17 @@
import { DropdownMenu as _ } from "radix-ui";
import type { ComponentProps } from "react";
import { classNames } from "../../ui/classNames";
import { composeRadixComponents } from "../../ui/compose";
import styles from "./index.module.css";
export const DropdownMenu = composeRadixComponents(_, styles);
// Trailing text pushed to the right of an item, like flags or shortcuts
export function Discriminator({ className, ...props }: ComponentProps<"span">) {
return (
<span className={classNames(styles.discriminator, className)} {...props} />
);
}
export const DropdownMenu = {
...composeRadixComponents(_, styles),
Discriminator,
};
@@ -2,12 +2,6 @@
width: fit-content;
}
.search {
display: flex;
flex-direction: column;
gap: var(--space-4);
}
.results {
display: flex;
justify-content: center;
@@ -89,46 +89,44 @@ export function GenerateURL({ embed }: GenerateURLProps) {
</Dialog.Header>
<Dialog.Body>
<div className={styles.search}>
<TextField
placeholder={strings.common.search.hint_players}
ref={input}
onChange={handleChange}
>
<PersonIcon />
</TextField>
<TextField
placeholder={strings.common.search.hint_players}
ref={input}
onChange={handleChange}
>
<PersonIcon />
</TextField>
<div className={styles.results}>
{searching && (
<Text lowContrast className={styles.searching}>
<Spinner />
{strings.common.search.searching}
</Text>
)}
<div className={styles.results}>
{searching && (
<Text lowContrast className={styles.searching}>
<Spinner />
{strings.common.search.searching}
</Text>
)}
{!searching && results.length === 0 && (
<Text lowContrast>{strings.common.search.no_results}</Text>
)}
{!searching && results.length === 0 && (
<Text lowContrast>{strings.common.search.no_results}</Text>
)}
{!searching && results.length > 0 && (
<SearchResults.Root>
{results.map((result) => (
<SearchResults.Item
key={`${result.region}-${result.account_id}`}
text={result.nickname}
discriminator={
strings.common.regions.short[result.region]
}
onClick={() => {
setCopyUser(result);
setCopyDialogOpen(true);
setSearchDialogOpen(false);
}}
/>
))}
</SearchResults.Root>
)}
</div>
{!searching && results.length > 0 && (
<SearchResults.Root>
{results.map((result) => (
<SearchResults.Item
key={`${result.region}-${result.account_id}`}
text={result.nickname}
discriminator={
strings.common.regions.short[result.region]
}
onClick={() => {
setCopyUser(result);
setCopyDialogOpen(true);
setSearchDialogOpen(false);
}}
/>
))}
</SearchResults.Root>
)}
</div>
</Dialog.Body>
@@ -1,27 +1,17 @@
<script>
import locales from "@blitzkit/i18n/locales.json";
import { getBestLocale } from "../core/i18n/getBestLocale";
import { getCurrentPathLocale } from "../core/i18n/getCurrentPathLocale";
import { navigateToLocale } from "../core/i18n/navigateToLocale";
const pathname = window.location.pathname;
const hasPreference = localStorage.getItem("preferred-locale") !== null;
const bestLocale = getBestLocale();
const currentLocale =
locales.supported.find(
({ locale }) =>
pathname === `/${locale}` || pathname.startsWith(`/${locale}/`),
)?.locale ?? locales.default;
const currentLocale = getCurrentPathLocale();
if (
bestLocale !== currentLocale &&
(hasPreference || currentLocale === locales.default)
) {
const rawPath =
currentLocale === locales.default
? pathname
: pathname.slice(`/${currentLocale}`.length) || "/";
window.location.pathname = `${
bestLocale === locales.default ? "" : `/${bestLocale}`
}${rawPath}`;
navigateToLocale(bestLocale);
}
</script>
@@ -0,0 +1,76 @@
import { CaretDownIcon, DotFilledIcon, GlobeIcon } from "@radix-ui/react-icons";
import { useState } from "react";
import { getBestLocale } from "../../core/i18n/getBestLocale";
import type { LocaleOption } from "../../core/i18n/getLocaleOptions";
import { navigateToLocale } from "../../core/i18n/navigateToLocale";
import { useLocale } from "../../hooks/useLocale";
import { useStrings } from "../../hooks/useStrings";
import { Select } from "../Select";
export interface LocaleSelectProps {
options: LocaleOption[];
}
export function LocaleSelect({ options }: LocaleSelectProps) {
const locale = useLocale();
const strings = useStrings();
const [value] = useState(
() =>
`${localStorage.getItem("preferred-locale") === null ? null : locale}`,
);
return (
<Select.Root
value={value}
onValueChange={(value) => {
if (value === "null") {
localStorage.removeItem("preferred-locale");
navigateToLocale(getBestLocale());
} else {
localStorage.setItem("preferred-locale", value);
navigateToLocale(value);
}
}}
>
<Select.Trigger>
<Select.Value />
<Select.Icon>
<CaretDownIcon />
</Select.Icon>
</Select.Trigger>
<Select.Portal>
<Select.Content>
<Select.Viewport>
<Select.Item value="null">
<Select.ItemIndicator>
<DotFilledIcon />
</Select.ItemIndicator>
<Select.ItemText>
{strings.settings.device_language}
<GlobeIcon />
</Select.ItemText>
</Select.Item>
<Select.Separator />
{options.map(({ locale, flag, name }) => (
<Select.Item key={locale} value={locale}>
<Select.ItemIndicator>
<DotFilledIcon />
</Select.ItemIndicator>
<Select.ItemText>
{name}
<Select.Discriminator>{flag}</Select.Discriminator>
</Select.ItemText>
</Select.Item>
))}
</Select.Viewport>
</Select.Content>
</Select.Portal>
</Select.Root>
);
}
@@ -2,11 +2,13 @@
import { alias } from "@blitzkit/core";
import { CaretUpIcon, GearIcon } from "@radix-ui/react-icons";
import { api } from "../api/dynamic";
import { getLocaleOptions } from "../core/i18n/getLocaleOptions";
import { Logo } from "../icons/Logo";
import { LinkI18nWrapper } from "./LinkI18nWrapper";
import { filtered, type Props as NavbarFineProps } from "./NavbarFine.astro";
import NavbarMobileAutoHide from "./NavbarMobileAutoHide.astro";
import { Scroller, ScrollerOrientation } from "./Scroller";
import { SettingsDialog } from "./SettingsDialog";
import { Text } from "./Text";
export type Props = NavbarFineProps & {
@@ -16,6 +18,7 @@ export type Props = NavbarFineProps & {
const { locale, tool, solid = false } = Astro.props;
const strings = await api.strings(locale);
const localeOptions = await getLocaleOptions();
---
<style>
@@ -229,7 +232,7 @@ const strings = await api.strings(locale);
/>
<Text className="name">
{strings.tools[tool.id as keyof typeof strings.tools].name}
{strings.tools[tool.id as keyof typeof strings.tools]}
</Text>
</div>
</LinkI18nWrapper>
@@ -254,15 +257,15 @@ const strings = await api.strings(locale);
)}
<Text className="name">
{strings.tools[tool.id as keyof typeof strings.tools].name}
{strings.tools[tool.id as keyof typeof strings.tools]}
</Text>
<CaretUpIcon className="icon" />
</div>
<LinkI18nWrapper {locale} href="/settings">
<SettingsDialog {locale} {localeOptions} client:load>
<GearIcon className="icon" />
</LinkI18nWrapper>
</SettingsDialog>
</div>
</nav>
@@ -2,12 +2,16 @@
import { alias } from "@blitzkit/core";
import { GearIcon } from "@radix-ui/react-icons";
import { api } from "../api/dynamic";
import { getLocaleOptions } from "../core/i18n/getLocaleOptions";
import { tools, type Tool } from "../constants/tools";
import type { LocaleAcceptorProps } from "../hooks/useLocale";
import { Logo } from "../icons/Logo";
import { LinkI18nWrapper } from "./LinkI18nWrapper";
import { SettingsDialog } from "./SettingsDialog";
import { Text } from "./Text";
// TODO: combine all navbar after adding NavbarCourseLandscape
export type Props = LocaleAcceptorProps & {
tool: Tool;
};
@@ -15,6 +19,7 @@ export type Props = LocaleAcceptorProps & {
const { locale } = Astro.props;
const strings = await api.strings(locale);
const localeOptions = await getLocaleOptions();
export const filtered = Object.values(tools).filter(
(tool) => !tool.href && !tool.hide_in_navbar && !tool.disabled,
@@ -184,7 +189,7 @@ export const filtered = Object.values(tools).filter(
/>
<Text className="name">
{strings.tools[tool.id as keyof typeof strings.tools].name}
{strings.tools[tool.id as keyof typeof strings.tools]}
</Text>
</div>
</LinkI18nWrapper>
@@ -192,11 +197,11 @@ export const filtered = Object.values(tools).filter(
))}
</div>
<LinkI18nWrapper {locale} href="/settings">
<SettingsDialog {locale} {localeOptions} client:load>
<div class="named-link">
<GearIcon className="icon" />
<Text className="name">{strings.navbar.settings}</Text>
</div>
</LinkI18nWrapper>
</SettingsDialog>
</div>
</nav>
@@ -1,8 +1,12 @@
import { Select as _ } from "radix-ui";
import { composeRadixComponents } from "../../ui/compose";
import { Discriminator } from "../DropdownMenu";
import styles from "./index.module.css";
// TODO: for select, context menu, and dropdown menus, use scroller curtains
export const Select = composeRadixComponents(_, styles, {
Content: { position: "popper", align: "center" },
});
export const Select = {
...composeRadixComponents(_, styles, {
Content: { position: "popper", align: "center" },
}),
Discriminator,
};
@@ -0,0 +1,11 @@
.trigger {
display: contents;
cursor: pointer;
}
.row {
display: flex;
align-items: center;
justify-content: space-between;
gap: var(--space-3);
}
@@ -0,0 +1,76 @@
import type { ReactNode } from "react";
import type { LocaleOption } from "../../core/i18n/getLocaleOptions";
import { withLocale } from "../../hocs/withLocale";
import { useStrings } from "../../hooks/useStrings";
import { App } from "../../stores/app";
import { Dialog } from "../Dialog";
import { LocaleSelect } from "../LocaleSelect";
import { Switch } from "../Switch";
import { Text } from "../Text";
import styles from "./index.module.css";
interface SettingsDialogProps {
children: ReactNode;
localeOptions: LocaleOption[];
}
export const SettingsDialog = withLocale(
({ children, localeOptions }: SettingsDialogProps) => {
const strings = useStrings();
const developerMode = App.useDeferred(
(state) => state.developerMode,
false,
);
const autoLoadModels = App.useDeferred(
(state) => state.autoLoadModels,
true,
);
return (
<Dialog.Root>
<Dialog.Trigger className={styles.trigger}>{children}</Dialog.Trigger>
<Dialog.Portal>
<Dialog.Overlay />
<Dialog.Content>
<Dialog.Header>
<Dialog.Title>{strings.navbar.settings}</Dialog.Title>
</Dialog.Header>
<Dialog.Body>
<div className={styles.row}>
<Text>{strings.settings.language}</Text>
<LocaleSelect options={localeOptions} />
</div>
<div className={styles.row}>
<Text>{strings.settings.auto_load_models}</Text>
<Switch
checked={autoLoadModels}
onCheckedChange={(checked) => {
App.mutate((draft) => {
draft.autoLoadModels = checked;
});
}}
/>
</div>
<div className={styles.row}>
<Text>{strings.settings.developer_mode}</Text>
<Switch
checked={developerMode}
onCheckedChange={(checked) => {
App.mutate((draft) => {
draft.developerMode = checked;
});
}}
/>
</div>
</Dialog.Body>
</Dialog.Content>
</Dialog.Portal>
</Dialog.Root>
);
},
);
@@ -12,7 +12,7 @@ interface Props {
const { tool, locale } = Astro.props;
const strings = await api.strings(locale);
const toolStrings = strings.tools[tool.id as keyof typeof strings.tools];
const name = strings.tools[tool.id as keyof typeof strings.tools];
---
<style>
@@ -107,7 +107,7 @@ const toolStrings = strings.tools[tool.id as keyof typeof strings.tools];
<div class="centered">
<Heading weight="bold" size="2">
{toolStrings.name}
{name}
</Heading>
<Logo className="logo" />
@@ -13,7 +13,7 @@ interface Props {
const { locale, tool, minor } = Astro.props;
const strings = await api.strings(locale);
const toolStrings = strings.tools[tool.id as keyof typeof strings.tools];
const name = strings.tools[tool.id as keyof typeof strings.tools];
---
<style>
@@ -103,7 +103,7 @@ const toolStrings = strings.tools[tool.id as keyof typeof strings.tools];
<div class="content" data-minor={minor}>
<div class="wrapper">
<Heading size={minor ? "3" : "2"} weight="medium">
{toolStrings.name}
{name}
</Heading>
</div>
</div>
@@ -10,12 +10,11 @@ interface Props {
const { locale, tool } = Astro.props;
const strings = await api.strings(locale);
const toolStrings = strings.tools[tool.id as keyof typeof strings.tools];
const title = strings.tools[tool.id as keyof typeof strings.tools];
---
<AstroSeo
title={toolStrings.name}
description={toolStrings.seo_description}
{title}
canonical={Astro.url.href}
openGraph={{
url: Astro.url.href,
@@ -24,9 +23,8 @@ const toolStrings = strings.tools[tool.id as keyof typeof strings.tools];
url: `${Astro.url.origin}/assets/images/tools/${tool.id}.webp`,
},
],
title: toolStrings.name,
description: toolStrings.seo_description,
site_name: "BlitzKit",
title,
site_name: strings.common.name,
}}
twitter={{ cardType: "summary_large_image" }}
/>
-5
View File
@@ -90,11 +90,6 @@ export const tools: Record<string, Tool> = {
id: "changelogs",
banner_background_position: "bottom",
},
settings: {
id: "settings",
banner_background_position: "center",
hide_in_navbar: true,
},
credits: {
disabled: true,
id: "credits",
@@ -0,0 +1,12 @@
import locales from "@blitzkit/i18n/locales.json";
export function getCurrentPathLocale() {
const pathname = window.location.pathname;
return (
locales.supported.find(
({ locale }) =>
pathname === `/${locale}` || pathname.startsWith(`/${locale}/`),
)?.locale ?? locales.default
);
}
@@ -0,0 +1,20 @@
import locales from "@blitzkit/i18n/locales.json";
import { api } from "../../api/dynamic";
export interface LocaleOption {
locale: string;
flag: string;
name: string;
}
// each locale is named in its own language; run at build time so clients never fetch every locale's strings
export async function getLocaleOptions() {
return Promise.all(
locales.supported.map(async ({ locale, flag }) => {
const strings = await api.strings(locale);
const name = (strings.common.locales as Record<string, string>)[locale];
return { locale, flag, name } satisfies LocaleOption;
}),
);
}
@@ -0,0 +1,16 @@
import locales from "@blitzkit/i18n/locales.json";
import { getCurrentPathLocale } from "./getCurrentPathLocale";
// keeps the current page, swapping only the locale prefix
export function navigateToLocale(locale: string) {
const pathname = window.location.pathname;
const currentLocale = getCurrentPathLocale();
const rawPath =
currentLocale === locales.default
? pathname
: pathname.slice(`/${currentLocale}`.length) || "/";
window.location.pathname = `${
locale === locales.default ? "" : `/${locale}`
}${rawPath}`;
}
@@ -1,13 +0,0 @@
---
import { tools } from "../../../../constants/tools";
import BaseLayout from "../../../../layouts/BaseLayout.astro";
import { Page } from "./_index";
export { getStaticPaths } from "../index.astro";
const { locale } = Astro.props;
---
<BaseLayout tool={tools.settings} {locale}>
<Page {locale} client:load />
</BaseLayout>
@@ -1,63 +0,0 @@
import { Flex, Switch, Text } from "@radix-ui/themes";
import { LocaleSwitcher } from "../../../../components/LocaleSwitcher";
import { PageWrapper } from "../../../../components/PageWrapper";
import {
LocaleProvider,
useLocale,
type LocaleAcceptorProps,
} from "../../../../hooks/useLocale";
import { App } from "../../../../stores/app";
export function Page({ locale }: LocaleAcceptorProps) {
return (
<LocaleProvider locale={locale}>
<Content locale={locale} />
</LocaleProvider>
);
}
function Content({ locale }: LocaleAcceptorProps) {
const developerMode = App.useDeferred((state) => state.developerMode, false);
const autoLoadModels = App.useDeferred(
(state) => state.autoLoadModels,
true,
);
const { strings } = useLocale();
return (
<PageWrapper justify="center" align="center">
<Flex gap="3" direction="column" width="100%" maxWidth="20rem">
<Flex align="center" gap="2" justify="between">
<Text>{strings.website.settings.dev_mode}</Text>
<Switch
variant="classic"
checked={developerMode}
onCheckedChange={(checked) =>
App.mutate((draft) => {
draft.developerMode = checked;
})
}
/>
</Flex>
<Flex align="center" gap="2" justify="between">
<Text>{strings.website.settings.auto_load_models}</Text>
<Switch
variant="classic"
checked={autoLoadModels}
onCheckedChange={(checked) =>
App.mutate((draft) => {
draft.autoLoadModels = checked;
})
}
/>
</Flex>
<Flex align="center" gap="2" justify="between">
<Text>{strings.website.settings.language}</Text>
<LocaleSwitcher locale={locale} />
</Flex>
</Flex>
</PageWrapper>
);
}