mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-06-21 03:54:14 -05:00
20 lines
599 B
TypeScript
20 lines
599 B
TypeScript
import { SETTINGS_TAB_SLUGS, type SettingsTabSlug } from "./settings-constants";
|
|
|
|
const PUBLIC_TABS = new Set<SettingsTabSlug>(["locale", "theme"]);
|
|
|
|
export function defaultTab(isLoggedIn: boolean): SettingsTabSlug {
|
|
return isLoggedIn ? "match-profile" : "theme";
|
|
}
|
|
|
|
export function resolveActiveTab(
|
|
raw: string | null,
|
|
isLoggedIn: boolean,
|
|
): SettingsTabSlug {
|
|
if (raw && (SETTINGS_TAB_SLUGS as readonly string[]).includes(raw)) {
|
|
const slug = raw as SettingsTabSlug;
|
|
if (!isLoggedIn && !PUBLIC_TABS.has(slug)) return defaultTab(false);
|
|
return slug;
|
|
}
|
|
return defaultTab(isLoggedIn);
|
|
}
|