2023-11-18 19:27:19 +01:00
|
|
|
import classNames from "classnames";
|
2023-11-18 17:28:10 +01:00
|
|
|
import { useEffect } from "react";
|
|
|
|
import { useAsyncFn } from "react-use";
|
2023-10-27 21:51:14 +02:00
|
|
|
|
2023-11-18 17:28:10 +01:00
|
|
|
import { getSessions } from "@/backend/accounts/sessions";
|
2023-10-25 18:05:40 +02:00
|
|
|
import { WideContainer } from "@/components/layout/WideContainer";
|
2023-11-18 17:28:10 +01:00
|
|
|
import { Heading1 } from "@/components/utils/Text";
|
|
|
|
import { useBackendUrl } from "@/hooks/auth/useBackendUrl";
|
2023-11-18 19:27:19 +01:00
|
|
|
import { useIsMobile } from "@/hooks/useIsMobile";
|
2023-11-18 17:28:10 +01:00
|
|
|
import { AccountActionsPart } from "@/pages/settings/AccountActionsPart";
|
|
|
|
import { AccountEditPart } from "@/pages/settings/AccountEditPart";
|
2023-11-18 19:27:19 +01:00
|
|
|
import { CaptionsPart } from "@/pages/settings/CaptionsPart";
|
2023-11-18 17:28:10 +01:00
|
|
|
import { DeviceListPart } from "@/pages/settings/DeviceListPart";
|
|
|
|
import { RegisterCalloutPart } from "@/pages/settings/RegisterCalloutPart";
|
|
|
|
import { SidebarPart } from "@/pages/settings/SidebarPart";
|
|
|
|
import { ThemePart } from "@/pages/settings/ThemePart";
|
|
|
|
import { AccountWithToken, useAuthStore } from "@/stores/auth";
|
|
|
|
import { useThemeStore } from "@/stores/theme";
|
2023-10-25 18:05:40 +02:00
|
|
|
|
|
|
|
import { SubPageLayout } from "./layouts/SubPageLayout";
|
2023-11-18 20:55:46 +01:00
|
|
|
import { LocalePart } from "./settings/LocalePart";
|
2023-10-25 18:05:40 +02:00
|
|
|
|
|
|
|
function SettingsLayout(props: { children: React.ReactNode }) {
|
2023-11-18 19:27:19 +01:00
|
|
|
const { isMobile } = useIsMobile();
|
|
|
|
|
2023-10-25 18:05:40 +02:00
|
|
|
return (
|
|
|
|
<WideContainer ultraWide>
|
2023-11-18 19:27:19 +01:00
|
|
|
<div
|
|
|
|
className={classNames(
|
|
|
|
"grid gap-12",
|
|
|
|
isMobile ? "grid-cols-1" : "lg:grid-cols-[260px,1fr]"
|
|
|
|
)}
|
|
|
|
>
|
2023-11-18 17:28:10 +01:00
|
|
|
<SidebarPart />
|
2023-10-27 21:51:14 +02:00
|
|
|
<div className="space-y-16">{props.children}</div>
|
2023-10-25 18:05:40 +02:00
|
|
|
</div>
|
|
|
|
</WideContainer>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-11-18 17:28:10 +01:00
|
|
|
export function AccountSettings(props: { account: AccountWithToken }) {
|
|
|
|
const url = useBackendUrl();
|
|
|
|
const { account } = props;
|
|
|
|
const [sessionsResult, execSessions] = useAsyncFn(() => {
|
|
|
|
return getSessions(url, account);
|
|
|
|
}, [account, url]);
|
|
|
|
useEffect(() => {
|
|
|
|
execSessions();
|
|
|
|
}, [execSessions]);
|
2023-10-27 21:51:14 +02:00
|
|
|
|
|
|
|
return (
|
2023-11-18 17:28:10 +01:00
|
|
|
<>
|
|
|
|
<AccountEditPart />
|
|
|
|
<DeviceListPart
|
|
|
|
error={!!sessionsResult.error}
|
|
|
|
loading={sessionsResult.loading}
|
|
|
|
sessions={sessionsResult.value ?? []}
|
|
|
|
onChange={execSessions}
|
|
|
|
/>
|
|
|
|
<AccountActionsPart />
|
|
|
|
</>
|
2023-10-27 21:51:14 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-10-25 18:05:40 +02:00
|
|
|
export function SettingsPage() {
|
2023-11-18 17:28:10 +01:00
|
|
|
const activeTheme = useThemeStore((s) => s.theme);
|
|
|
|
const setTheme = useThemeStore((s) => s.setTheme);
|
|
|
|
const user = useAuthStore();
|
|
|
|
|
2023-10-25 18:05:40 +02:00
|
|
|
return (
|
|
|
|
<SubPageLayout>
|
|
|
|
<SettingsLayout>
|
2023-11-18 19:27:19 +01:00
|
|
|
<div id="settings-account">
|
|
|
|
<Heading1 border className="!mb-0">
|
|
|
|
Account
|
|
|
|
</Heading1>
|
|
|
|
{user.account ? (
|
|
|
|
<AccountSettings account={user.account} />
|
|
|
|
) : (
|
|
|
|
<RegisterCalloutPart />
|
|
|
|
)}
|
|
|
|
</div>
|
2023-11-18 20:55:46 +01:00
|
|
|
<div id="settings-locale">
|
|
|
|
<LocalePart />
|
|
|
|
</div>
|
2023-11-18 19:27:19 +01:00
|
|
|
<div id="settings-appearance">
|
|
|
|
<ThemePart active={activeTheme} setTheme={setTheme} />
|
|
|
|
</div>
|
|
|
|
<div id="settings-captions">
|
|
|
|
<CaptionsPart />
|
|
|
|
</div>
|
2023-10-25 18:05:40 +02:00
|
|
|
</SettingsLayout>
|
|
|
|
</SubPageLayout>
|
|
|
|
);
|
|
|
|
}
|