2024-09-14 11:55:37 +00:00
|
|
|
import { For, Show, type ParentComponent } from "solid-js";
|
2024-07-22 13:57:04 +00:00
|
|
|
import Scaffold from "../material/Scaffold.js";
|
|
|
|
import {
|
|
|
|
AppBar,
|
|
|
|
Divider,
|
|
|
|
IconButton,
|
|
|
|
List,
|
|
|
|
ListItem,
|
|
|
|
ListItemButton,
|
2024-09-26 09:23:40 +00:00
|
|
|
ListItemIcon,
|
2024-07-22 13:57:04 +00:00
|
|
|
ListItemSecondaryAction,
|
|
|
|
ListItemText,
|
|
|
|
ListSubheader,
|
2024-09-26 09:23:40 +00:00
|
|
|
NativeSelect,
|
2024-07-22 13:57:04 +00:00
|
|
|
Switch,
|
|
|
|
Toolbar,
|
|
|
|
} from "@suid/material";
|
2024-09-14 11:55:37 +00:00
|
|
|
import {
|
|
|
|
Close as CloseIcon,
|
2024-09-26 11:36:46 +00:00
|
|
|
Logout,
|
2024-09-26 09:23:40 +00:00
|
|
|
Public as PublicIcon,
|
2024-09-14 11:55:37 +00:00
|
|
|
Refresh as RefreshIcon,
|
2024-09-26 09:23:40 +00:00
|
|
|
Translate as TranslateIcon,
|
2024-09-14 11:55:37 +00:00
|
|
|
} from "@suid/icons-material";
|
2024-07-22 13:57:04 +00:00
|
|
|
import { useNavigate } from "@solidjs/router";
|
|
|
|
import { Title } from "../material/typography.jsx";
|
|
|
|
import { css } from "solid-styled";
|
|
|
|
import { useSignedInProfiles } from "../masto/acct.js";
|
|
|
|
import { signOut, type Account } from "../accounts/stores.js";
|
2024-09-26 09:23:40 +00:00
|
|
|
import { format, intlFormat } from "date-fns";
|
2024-07-23 00:28:47 +00:00
|
|
|
import { useStore } from "@nanostores/solid";
|
|
|
|
import { $settings } from "./stores.js";
|
2024-09-14 11:55:37 +00:00
|
|
|
import { useRegisterSW } from "virtual:pwa-register/solid";
|
2024-09-26 09:23:40 +00:00
|
|
|
import {
|
|
|
|
autoMatchLangTag,
|
|
|
|
autoMatchRegion,
|
|
|
|
createStringResource,
|
|
|
|
SUPPORTED_LANGS,
|
|
|
|
SUPPORTED_REGIONS,
|
|
|
|
useDateFnLocale,
|
|
|
|
} from "../platform/i18n.jsx";
|
2024-09-26 11:36:46 +00:00
|
|
|
import { resolveTemplate, translator, type Template } from "@solid-primitives/i18n";
|
|
|
|
|
|
|
|
type Strings = {
|
|
|
|
["lang.auto"]: Template<{detected: string}>
|
|
|
|
} & Record<string, string | undefined>
|
2024-07-22 13:57:04 +00:00
|
|
|
|
|
|
|
const Settings: ParentComponent = () => {
|
2024-09-26 09:23:40 +00:00
|
|
|
const [strings] = createStringResource(
|
2024-09-26 11:36:46 +00:00
|
|
|
(code) =>
|
|
|
|
import(`./i18n/${code}.json`) as Promise<{
|
|
|
|
default: Strings;
|
|
|
|
}>,
|
|
|
|
() => import(`./i18n/lang-names.json`)
|
2024-09-26 09:23:40 +00:00
|
|
|
);
|
|
|
|
const t = translator(strings, resolveTemplate);
|
2024-07-22 13:57:04 +00:00
|
|
|
const navigate = useNavigate();
|
2024-07-23 00:28:47 +00:00
|
|
|
const settings$ = useStore($settings);
|
2024-09-14 11:55:37 +00:00
|
|
|
const {
|
|
|
|
needRefresh: [needRefresh],
|
|
|
|
} = useRegisterSW();
|
2024-09-26 09:23:40 +00:00
|
|
|
const dateFnLocale = useDateFnLocale();
|
2024-07-22 13:57:04 +00:00
|
|
|
|
|
|
|
const [profiles] = useSignedInProfiles();
|
|
|
|
|
|
|
|
const doSignOut = (acct: Account) => {
|
|
|
|
signOut((a) => a.site === acct.site && a.accessToken === acct.accessToken);
|
|
|
|
};
|
|
|
|
|
|
|
|
css`
|
|
|
|
ul {
|
|
|
|
padding: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.setting-list {
|
2024-07-24 06:27:20 +00:00
|
|
|
padding-bottom: calc(var(--safe-area-inset-bottom, 0px) + 16px);
|
2024-07-22 13:57:04 +00:00
|
|
|
}
|
|
|
|
`;
|
|
|
|
return (
|
|
|
|
<Scaffold
|
|
|
|
topbar={
|
|
|
|
<AppBar position="static">
|
2024-09-14 11:55:37 +00:00
|
|
|
<Toolbar
|
|
|
|
variant="dense"
|
|
|
|
sx={{ paddingTop: "var(--safe-area-inset-top, 0px)" }}
|
|
|
|
>
|
2024-08-13 07:08:29 +00:00
|
|
|
<IconButton color="inherit" onClick={[navigate, -1]} disableRipple>
|
2024-07-22 13:57:04 +00:00
|
|
|
<CloseIcon />
|
|
|
|
</IconButton>
|
2024-09-26 09:23:40 +00:00
|
|
|
<Title>{t("Settings")}</Title>
|
2024-07-22 13:57:04 +00:00
|
|
|
</Toolbar>
|
|
|
|
</AppBar>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<List class="setting-list" use:solid-styled>
|
|
|
|
<li>
|
|
|
|
<ul>
|
2024-09-26 09:23:40 +00:00
|
|
|
<ListSubheader>{t("Accounts")}</ListSubheader>
|
2024-09-26 11:36:46 +00:00
|
|
|
<ListItemButton disabled>
|
2024-09-26 09:23:40 +00:00
|
|
|
<ListItemText>{t("All Notifications")}</ListItemText>
|
2024-07-22 13:57:04 +00:00
|
|
|
<ListItemSecondaryAction>
|
2024-09-26 11:36:46 +00:00
|
|
|
<Switch value={false} disabled/>
|
2024-07-22 13:57:04 +00:00
|
|
|
</ListItemSecondaryAction>
|
2024-09-26 11:36:46 +00:00
|
|
|
</ListItemButton>
|
2024-09-14 11:55:37 +00:00
|
|
|
<Divider />
|
2024-09-26 11:36:46 +00:00
|
|
|
<ListItemButton disabled>
|
2024-09-26 09:23:40 +00:00
|
|
|
<ListItemText>{t("Sign in...")}</ListItemText>
|
2024-09-26 11:36:46 +00:00
|
|
|
</ListItemButton>
|
2024-09-14 11:55:37 +00:00
|
|
|
<Divider />
|
2024-07-22 13:57:04 +00:00
|
|
|
</ul>
|
|
|
|
<For each={profiles()}>
|
|
|
|
{({ account: acct, inf }) => (
|
|
|
|
<ul data-site={acct.site} data-username={inf?.username}>
|
|
|
|
<ListSubheader>{`@${inf?.username ?? "..."}@${new URL(acct.site).host}`}</ListSubheader>
|
2024-09-26 11:36:46 +00:00
|
|
|
<ListItemButton disabled>
|
|
|
|
<ListItemText>{t("Notifications")}</ListItemText>
|
2024-07-22 13:57:04 +00:00
|
|
|
<ListItemSecondaryAction>
|
2024-09-26 11:36:46 +00:00
|
|
|
<Switch value={false} disabled/>
|
2024-07-22 13:57:04 +00:00
|
|
|
</ListItemSecondaryAction>
|
2024-09-26 11:36:46 +00:00
|
|
|
</ListItemButton>
|
2024-09-14 11:55:37 +00:00
|
|
|
<Divider />
|
2024-07-22 13:57:04 +00:00
|
|
|
<ListItemButton onClick={[doSignOut, acct]}>
|
2024-09-26 11:36:46 +00:00
|
|
|
<ListItemIcon>
|
|
|
|
<Logout/>
|
|
|
|
</ListItemIcon>
|
|
|
|
<ListItemText>{t("Sign out")}</ListItemText>
|
2024-07-22 13:57:04 +00:00
|
|
|
</ListItemButton>
|
2024-09-14 11:55:37 +00:00
|
|
|
<Divider />
|
2024-07-22 13:57:04 +00:00
|
|
|
</ul>
|
|
|
|
)}
|
|
|
|
</For>
|
|
|
|
</li>
|
|
|
|
<li>
|
2024-09-26 09:23:40 +00:00
|
|
|
<ListSubheader>{t("Reading")}</ListSubheader>
|
2024-09-26 11:36:46 +00:00
|
|
|
<ListItemButton
|
2024-09-14 11:55:37 +00:00
|
|
|
onClick={(e) =>
|
|
|
|
$settings.setKey(
|
|
|
|
"prefetchTootsDisabled",
|
|
|
|
!settings$().prefetchTootsDisabled,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
>
|
2024-09-26 09:23:40 +00:00
|
|
|
<ListItemText secondary={t("Prefetch Toots.2nd")}>
|
|
|
|
{t("Prefetch Toots")}
|
2024-07-22 13:57:04 +00:00
|
|
|
</ListItemText>
|
|
|
|
<ListItemSecondaryAction>
|
2024-09-14 11:55:37 +00:00
|
|
|
<Switch checked={!settings$().prefetchTootsDisabled} />
|
2024-07-22 13:57:04 +00:00
|
|
|
</ListItemSecondaryAction>
|
2024-09-26 11:36:46 +00:00
|
|
|
</ListItemButton>
|
2024-09-14 11:55:37 +00:00
|
|
|
<Divider />
|
2024-07-22 13:57:04 +00:00
|
|
|
</li>
|
|
|
|
<li>
|
2024-09-26 09:23:40 +00:00
|
|
|
<ListSubheader>{t("This Application")}</ListSubheader>
|
|
|
|
<ListItem>
|
|
|
|
<ListItemIcon>
|
|
|
|
<TranslateIcon />
|
|
|
|
</ListItemIcon>
|
|
|
|
<ListItemText>{t("Language")}</ListItemText>
|
|
|
|
<ListItemSecondaryAction>
|
|
|
|
<NativeSelect
|
|
|
|
value={settings$().language || "xauto"}
|
|
|
|
onChange={(e) => {
|
|
|
|
$settings.setKey(
|
|
|
|
"language",
|
|
|
|
e.currentTarget.value === "xauto"
|
|
|
|
? undefined
|
|
|
|
: e.currentTarget.value,
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<option value={"xauto"}>
|
|
|
|
{t("lang.auto", {
|
2024-09-26 11:36:46 +00:00
|
|
|
detected: t("lang." + autoMatchLangTag()) ?? autoMatchLangTag(),
|
2024-09-26 09:23:40 +00:00
|
|
|
})}
|
|
|
|
</option>
|
|
|
|
<For each={SUPPORTED_LANGS}>
|
|
|
|
{(code) => <option value={code}>{t("lang." + code)}</option>}
|
|
|
|
</For>
|
|
|
|
</NativeSelect>
|
|
|
|
</ListItemSecondaryAction>
|
|
|
|
</ListItem>
|
|
|
|
<Divider />
|
|
|
|
<ListItem>
|
|
|
|
<ListItemIcon>
|
|
|
|
<PublicIcon />
|
|
|
|
</ListItemIcon>
|
|
|
|
<ListItemText>{t("Region")}</ListItemText>
|
|
|
|
<ListItemSecondaryAction>
|
|
|
|
<NativeSelect
|
|
|
|
value={settings$().region}
|
|
|
|
onChange={(e) => {
|
|
|
|
$settings.setKey(
|
|
|
|
"region",
|
|
|
|
e.currentTarget.value === "xauto"
|
|
|
|
? undefined
|
|
|
|
: e.currentTarget.value,
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<option value={"xauto"}>
|
|
|
|
{t("region.auto", {
|
2024-09-26 11:36:46 +00:00
|
|
|
detected: t("region." + autoMatchRegion()) ?? autoMatchRegion(),
|
2024-09-26 09:23:40 +00:00
|
|
|
})}
|
|
|
|
</option>
|
|
|
|
<For each={SUPPORTED_REGIONS}>
|
|
|
|
{(code) => (
|
|
|
|
<option value={code}>{t("region." + code)}</option>
|
|
|
|
)}
|
|
|
|
</For>
|
|
|
|
</NativeSelect>
|
|
|
|
</ListItemSecondaryAction>
|
|
|
|
</ListItem>
|
|
|
|
<Divider />
|
2024-07-22 13:57:04 +00:00
|
|
|
<ListItem>
|
2024-09-26 09:23:40 +00:00
|
|
|
<ListItemText secondary={t("About Tutu.2nd")}>
|
|
|
|
{t("About Tutu")}
|
2024-07-22 13:57:04 +00:00
|
|
|
</ListItemText>
|
|
|
|
</ListItem>
|
2024-09-14 11:55:37 +00:00
|
|
|
<Divider />
|
2024-07-22 13:57:04 +00:00
|
|
|
<ListItem>
|
|
|
|
<ListItemText
|
2024-09-26 09:23:40 +00:00
|
|
|
secondary={t("version", {
|
|
|
|
packageVersion: import.meta.env.PACKAGE_VERSION,
|
|
|
|
builtAt: format(
|
|
|
|
import.meta.env.BUILT_AT,
|
|
|
|
t("datefmt") || "yyyy/MM/dd",
|
|
|
|
{ locale: dateFnLocale() },
|
|
|
|
),
|
|
|
|
buildMode: import.meta.env.MODE,
|
|
|
|
})}
|
2024-07-22 13:57:04 +00:00
|
|
|
>
|
2024-09-26 09:23:40 +00:00
|
|
|
{needRefresh() ? t("updates.ready") : t("updates.no")}
|
2024-07-22 13:57:04 +00:00
|
|
|
</ListItemText>
|
2024-09-14 11:55:37 +00:00
|
|
|
<Show when={needRefresh()}>
|
|
|
|
<ListItemSecondaryAction>
|
2024-09-26 09:23:40 +00:00
|
|
|
<IconButton
|
|
|
|
aria-label="Restart Now"
|
|
|
|
onClick={() => window.location.reload()}
|
|
|
|
>
|
2024-09-14 11:55:37 +00:00
|
|
|
<RefreshIcon />
|
|
|
|
</IconButton>
|
|
|
|
</ListItemSecondaryAction>
|
|
|
|
</Show>
|
2024-07-22 13:57:04 +00:00
|
|
|
</ListItem>
|
2024-09-14 11:55:37 +00:00
|
|
|
<Divider />
|
2024-07-22 13:57:04 +00:00
|
|
|
</li>
|
|
|
|
</List>
|
|
|
|
</Scaffold>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Settings;
|