mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-11-22 21:53:46 +01:00
migrate settings
This commit is contained in:
25 files changed
+299
-201
No files matched your search
@@ -4,6 +4,13 @@
|
|||||||
"settings": "Settings"
|
"settings": "Settings"
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"settings": {
|
||||||
|
"language": "Language",
|
||||||
|
"device_language": "Device language",
|
||||||
|
"auto_load_models": "Auto-load models",
|
||||||
|
"developer_mode": "Developer mode"
|
||||||
|
},
|
||||||
|
|
||||||
"mixer": {
|
"mixer": {
|
||||||
"screenshot": "Screenshot",
|
"screenshot": "Screenshot",
|
||||||
"randomize": "Randomize"
|
"randomize": "Randomize"
|
||||||
@@ -477,60 +484,23 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
"tools": {
|
"tools": {
|
||||||
"home": {
|
"home": "Home",
|
||||||
"name": "Home"
|
"tanks": "Tankopedia",
|
||||||
},
|
"avatars": "Avatars",
|
||||||
"tanks": {
|
"backgrounds": "Backgrounds",
|
||||||
"name": "Tankopedia"
|
"api": "API",
|
||||||
},
|
"players": "Players",
|
||||||
"avatars": {
|
"compare": "Compare",
|
||||||
"name": "Avatars"
|
"performance": "Performance",
|
||||||
},
|
"playlist": "Playlist",
|
||||||
"backgrounds": {
|
"mixer": "Mixer",
|
||||||
"name": "Backgrounds"
|
"session": "Session",
|
||||||
},
|
"guesser": "Guesser",
|
||||||
"api": {
|
"changelogs": "Changelogs",
|
||||||
"name": "API"
|
"tier_list": "Tier list",
|
||||||
},
|
"embed": "Embed",
|
||||||
"players": {
|
"more": "More",
|
||||||
"name": "Players"
|
"credits": "Credits"
|
||||||
},
|
|
||||||
"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": {
|
||||||
@@ -789,14 +759,6 @@
|
|||||||
"body": "Where would you like to go?"
|
"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": {
|
"common": {
|
||||||
"copy_button": {
|
"copy_button": {
|
||||||
"copied": "Copied!"
|
"copied": "Copied!"
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
top: 50%;
|
top: 50%;
|
||||||
left: 50%;
|
left: 50%;
|
||||||
transform: translate(-50%, -50%);
|
transform: translate(-50%, -50%);
|
||||||
z-index: 2;
|
z-index: 1;
|
||||||
|
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
import { ContextMenu as _ } from "radix-ui";
|
import { ContextMenu as _ } from "radix-ui";
|
||||||
import { composeRadixComponents } from "../../ui/compose";
|
import { composeRadixComponents } from "../../ui/compose";
|
||||||
|
import { Discriminator } from "../DropdownMenu";
|
||||||
import styles from "./index.module.css";
|
import styles from "./index.module.css";
|
||||||
|
|
||||||
export const ContextMenu = composeRadixComponents(_, styles);
|
export const ContextMenu = {
|
||||||
|
...composeRadixComponents(_, styles),
|
||||||
|
Discriminator,
|
||||||
|
};
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
top: 50%;
|
top: 50%;
|
||||||
left: 50%;
|
left: 50%;
|
||||||
transform: translate(-50%, -50%);
|
transform: translate(-50%, -50%);
|
||||||
z-index: 2;
|
z-index: 1;
|
||||||
|
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
@@ -49,7 +49,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.body {
|
.body {
|
||||||
--scroller-curtain-color: var(--gray-2);
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
flex: 1;
|
gap: var(--space-4);
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,6 @@ import { Dialog as _ } from "radix-ui";
|
|||||||
import type { ComponentProps } from "react";
|
import type { ComponentProps } from "react";
|
||||||
import { classNames } from "../../ui/classNames";
|
import { classNames } from "../../ui/classNames";
|
||||||
import { composeRadixComponents } from "../../ui/compose";
|
import { composeRadixComponents } from "../../ui/compose";
|
||||||
import { Scroller, ScrollerOrientation } from "../Scroller";
|
|
||||||
import styles from "./index.module.css";
|
import styles from "./index.module.css";
|
||||||
|
|
||||||
// Groups a title and description
|
// Groups a title and description
|
||||||
@@ -10,15 +9,9 @@ function Header({ className, ...props }: ComponentProps<"div">) {
|
|||||||
return <div className={classNames(styles.header, className)} {...props} />;
|
return <div className={classNames(styles.header, className)} {...props} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scrolls the content that follows the header
|
// Stacks the content that follows the header
|
||||||
function Body({ className, ...props }: ComponentProps<typeof Scroller>) {
|
function Body({ className, ...props }: ComponentProps<"div">) {
|
||||||
return (
|
return <div className={classNames(styles.body, className)} {...props} />;
|
||||||
<Scroller
|
|
||||||
orientation={ScrollerOrientation.Vertical}
|
|
||||||
className={classNames(styles.body, className)}
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Dialog = { ...composeRadixComponents(_, styles), Header, Body };
|
export const Dialog = { ...composeRadixComponents(_, styles), Header, Body };
|
||||||
@@ -98,6 +98,11 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.discriminator {
|
||||||
|
display: inline;
|
||||||
|
margin-left: auto;
|
||||||
|
}
|
||||||
|
|
||||||
.ItemIndicator {
|
.ItemIndicator {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
left: 0;
|
left: 0;
|
||||||
|
|||||||
@@ -1,5 +1,17 @@
|
|||||||
import { DropdownMenu as _ } from "radix-ui";
|
import { DropdownMenu 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 styles from "./index.module.css";
|
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;
|
width: fit-content;
|
||||||
}
|
}
|
||||||
|
|
||||||
.search {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
gap: var(--space-4);
|
|
||||||
}
|
|
||||||
|
|
||||||
.results {
|
.results {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
|||||||
@@ -89,7 +89,6 @@ export function GenerateURL({ embed }: GenerateURLProps) {
|
|||||||
</Dialog.Header>
|
</Dialog.Header>
|
||||||
|
|
||||||
<Dialog.Body>
|
<Dialog.Body>
|
||||||
<div className={styles.search}>
|
|
||||||
<TextField
|
<TextField
|
||||||
placeholder={strings.common.search.hint_players}
|
placeholder={strings.common.search.hint_players}
|
||||||
ref={input}
|
ref={input}
|
||||||
@@ -129,7 +128,6 @@ export function GenerateURL({ embed }: GenerateURLProps) {
|
|||||||
</SearchResults.Root>
|
</SearchResults.Root>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
</Dialog.Body>
|
</Dialog.Body>
|
||||||
|
|
||||||
<AlertDialog.Actions>
|
<AlertDialog.Actions>
|
||||||
|
|||||||
@@ -1,27 +1,17 @@
|
|||||||
<script>
|
<script>
|
||||||
import locales from "@blitzkit/i18n/locales.json";
|
import locales from "@blitzkit/i18n/locales.json";
|
||||||
import { getBestLocale } from "../core/i18n/getBestLocale";
|
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 hasPreference = localStorage.getItem("preferred-locale") !== null;
|
||||||
const bestLocale = getBestLocale();
|
const bestLocale = getBestLocale();
|
||||||
const currentLocale =
|
const currentLocale = getCurrentPathLocale();
|
||||||
locales.supported.find(
|
|
||||||
({ locale }) =>
|
|
||||||
pathname === `/${locale}` || pathname.startsWith(`/${locale}/`),
|
|
||||||
)?.locale ?? locales.default;
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
bestLocale !== currentLocale &&
|
bestLocale !== currentLocale &&
|
||||||
(hasPreference || currentLocale === locales.default)
|
(hasPreference || currentLocale === locales.default)
|
||||||
) {
|
) {
|
||||||
const rawPath =
|
navigateToLocale(bestLocale);
|
||||||
currentLocale === locales.default
|
|
||||||
? pathname
|
|
||||||
: pathname.slice(`/${currentLocale}`.length) || "/";
|
|
||||||
|
|
||||||
window.location.pathname = `${
|
|
||||||
bestLocale === locales.default ? "" : `/${bestLocale}`
|
|
||||||
}${rawPath}`;
|
|
||||||
}
|
}
|
||||||
</script>
|
</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 { alias } from "@blitzkit/core";
|
||||||
import { CaretUpIcon, GearIcon } from "@radix-ui/react-icons";
|
import { CaretUpIcon, GearIcon } from "@radix-ui/react-icons";
|
||||||
import { api } from "../api/dynamic";
|
import { api } from "../api/dynamic";
|
||||||
|
import { getLocaleOptions } from "../core/i18n/getLocaleOptions";
|
||||||
import { Logo } from "../icons/Logo";
|
import { Logo } from "../icons/Logo";
|
||||||
import { LinkI18nWrapper } from "./LinkI18nWrapper";
|
import { LinkI18nWrapper } from "./LinkI18nWrapper";
|
||||||
import { filtered, type Props as NavbarFineProps } from "./NavbarFine.astro";
|
import { filtered, type Props as NavbarFineProps } from "./NavbarFine.astro";
|
||||||
import NavbarMobileAutoHide from "./NavbarMobileAutoHide.astro";
|
import NavbarMobileAutoHide from "./NavbarMobileAutoHide.astro";
|
||||||
import { Scroller, ScrollerOrientation } from "./Scroller";
|
import { Scroller, ScrollerOrientation } from "./Scroller";
|
||||||
|
import { SettingsDialog } from "./SettingsDialog";
|
||||||
import { Text } from "./Text";
|
import { Text } from "./Text";
|
||||||
|
|
||||||
export type Props = NavbarFineProps & {
|
export type Props = NavbarFineProps & {
|
||||||
@@ -16,6 +18,7 @@ export type Props = NavbarFineProps & {
|
|||||||
const { locale, tool, solid = false } = Astro.props;
|
const { locale, tool, solid = false } = Astro.props;
|
||||||
|
|
||||||
const strings = await api.strings(locale);
|
const strings = await api.strings(locale);
|
||||||
|
const localeOptions = await getLocaleOptions();
|
||||||
---
|
---
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
@@ -229,7 +232,7 @@ const strings = await api.strings(locale);
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<Text className="name">
|
<Text className="name">
|
||||||
{strings.tools[tool.id as keyof typeof strings.tools].name}
|
{strings.tools[tool.id as keyof typeof strings.tools]}
|
||||||
</Text>
|
</Text>
|
||||||
</div>
|
</div>
|
||||||
</LinkI18nWrapper>
|
</LinkI18nWrapper>
|
||||||
@@ -254,15 +257,15 @@ const strings = await api.strings(locale);
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
<Text className="name">
|
<Text className="name">
|
||||||
{strings.tools[tool.id as keyof typeof strings.tools].name}
|
{strings.tools[tool.id as keyof typeof strings.tools]}
|
||||||
</Text>
|
</Text>
|
||||||
|
|
||||||
<CaretUpIcon className="icon" />
|
<CaretUpIcon className="icon" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<LinkI18nWrapper {locale} href="/settings">
|
<SettingsDialog {locale} {localeOptions} client:load>
|
||||||
<GearIcon className="icon" />
|
<GearIcon className="icon" />
|
||||||
</LinkI18nWrapper>
|
</SettingsDialog>
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
|
|||||||
@@ -2,12 +2,16 @@
|
|||||||
import { alias } from "@blitzkit/core";
|
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 { tools, type Tool } from "../constants/tools";
|
import { tools, type Tool } from "../constants/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";
|
||||||
|
import { SettingsDialog } from "./SettingsDialog";
|
||||||
import { Text } from "./Text";
|
import { Text } from "./Text";
|
||||||
|
|
||||||
|
// TODO: combine all navbar after adding NavbarCourseLandscape
|
||||||
|
|
||||||
export type Props = LocaleAcceptorProps & {
|
export type Props = LocaleAcceptorProps & {
|
||||||
tool: Tool;
|
tool: Tool;
|
||||||
};
|
};
|
||||||
@@ -15,6 +19,7 @@ export type Props = LocaleAcceptorProps & {
|
|||||||
const { locale } = Astro.props;
|
const { locale } = Astro.props;
|
||||||
|
|
||||||
const strings = await api.strings(locale);
|
const strings = await api.strings(locale);
|
||||||
|
const localeOptions = await getLocaleOptions();
|
||||||
|
|
||||||
export const filtered = Object.values(tools).filter(
|
export const filtered = Object.values(tools).filter(
|
||||||
(tool) => !tool.href && !tool.hide_in_navbar && !tool.disabled,
|
(tool) => !tool.href && !tool.hide_in_navbar && !tool.disabled,
|
||||||
@@ -184,7 +189,7 @@ export const filtered = Object.values(tools).filter(
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<Text className="name">
|
<Text className="name">
|
||||||
{strings.tools[tool.id as keyof typeof strings.tools].name}
|
{strings.tools[tool.id as keyof typeof strings.tools]}
|
||||||
</Text>
|
</Text>
|
||||||
</div>
|
</div>
|
||||||
</LinkI18nWrapper>
|
</LinkI18nWrapper>
|
||||||
@@ -192,11 +197,11 @@ export const filtered = Object.values(tools).filter(
|
|||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<LinkI18nWrapper {locale} href="/settings">
|
<SettingsDialog {locale} {localeOptions} client:load>
|
||||||
<div class="named-link">
|
<div class="named-link">
|
||||||
<GearIcon className="icon" />
|
<GearIcon className="icon" />
|
||||||
<Text className="name">{strings.navbar.settings}</Text>
|
<Text className="name">{strings.navbar.settings}</Text>
|
||||||
</div>
|
</div>
|
||||||
</LinkI18nWrapper>
|
</SettingsDialog>
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
@@ -1,8 +1,12 @@
|
|||||||
import { Select as _ } from "radix-ui";
|
import { Select as _ } from "radix-ui";
|
||||||
import { composeRadixComponents } from "../../ui/compose";
|
import { composeRadixComponents } from "../../ui/compose";
|
||||||
|
import { Discriminator } from "../DropdownMenu";
|
||||||
import styles from "./index.module.css";
|
import styles from "./index.module.css";
|
||||||
|
|
||||||
// TODO: for select, context menu, and dropdown menus, use scroller curtains
|
// TODO: for select, context menu, and dropdown menus, use scroller curtains
|
||||||
export const Select = composeRadixComponents(_, styles, {
|
export const Select = {
|
||||||
|
...composeRadixComponents(_, styles, {
|
||||||
Content: { position: "popper", align: "center" },
|
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 { tool, locale } = Astro.props;
|
||||||
const strings = await api.strings(locale);
|
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>
|
<style>
|
||||||
@@ -107,7 +107,7 @@ const toolStrings = strings.tools[tool.id as keyof typeof strings.tools];
|
|||||||
|
|
||||||
<div class="centered">
|
<div class="centered">
|
||||||
<Heading weight="bold" size="2">
|
<Heading weight="bold" size="2">
|
||||||
{toolStrings.name}
|
{name}
|
||||||
</Heading>
|
</Heading>
|
||||||
|
|
||||||
<Logo className="logo" />
|
<Logo className="logo" />
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ interface Props {
|
|||||||
|
|
||||||
const { locale, tool, minor } = Astro.props;
|
const { locale, tool, minor } = Astro.props;
|
||||||
const strings = await api.strings(locale);
|
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>
|
<style>
|
||||||
@@ -103,7 +103,7 @@ const toolStrings = strings.tools[tool.id as keyof typeof strings.tools];
|
|||||||
<div class="content" data-minor={minor}>
|
<div class="content" data-minor={minor}>
|
||||||
<div class="wrapper">
|
<div class="wrapper">
|
||||||
<Heading size={minor ? "3" : "2"} weight="medium">
|
<Heading size={minor ? "3" : "2"} weight="medium">
|
||||||
{toolStrings.name}
|
{name}
|
||||||
</Heading>
|
</Heading>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -10,12 +10,11 @@ interface Props {
|
|||||||
|
|
||||||
const { locale, tool } = Astro.props;
|
const { locale, tool } = Astro.props;
|
||||||
const strings = await api.strings(locale);
|
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
|
<AstroSeo
|
||||||
title={toolStrings.name}
|
{title}
|
||||||
description={toolStrings.seo_description}
|
|
||||||
canonical={Astro.url.href}
|
canonical={Astro.url.href}
|
||||||
openGraph={{
|
openGraph={{
|
||||||
url: Astro.url.href,
|
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`,
|
url: `${Astro.url.origin}/assets/images/tools/${tool.id}.webp`,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
title: toolStrings.name,
|
title,
|
||||||
description: toolStrings.seo_description,
|
site_name: strings.common.name,
|
||||||
site_name: "BlitzKit",
|
|
||||||
}}
|
}}
|
||||||
twitter={{ cardType: "summary_large_image" }}
|
twitter={{ cardType: "summary_large_image" }}
|
||||||
/>
|
/>
|
||||||
@@ -90,11 +90,6 @@ export const tools: Record<string, Tool> = {
|
|||||||
id: "changelogs",
|
id: "changelogs",
|
||||||
banner_background_position: "bottom",
|
banner_background_position: "bottom",
|
||||||
},
|
},
|
||||||
settings: {
|
|
||||||
id: "settings",
|
|
||||||
banner_background_position: "center",
|
|
||||||
hide_in_navbar: true,
|
|
||||||
},
|
|
||||||
credits: {
|
credits: {
|
||||||
disabled: true,
|
disabled: true,
|
||||||
id: "credits",
|
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>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
Reference in new issue
Block a user