Cleanup settings page

This commit is contained in:
Zoe Roux 2024-01-10 17:41:17 +01:00
parent b4281188d4
commit 329b6fc67e
4 changed files with 69 additions and 22 deletions

View File

@ -33,8 +33,10 @@ declare module "react" {
): (props: P & React.RefAttributes<T>) => React.ReactElement | null; ): (props: P & React.RefAttributes<T>) => React.ReactElement | null;
} }
export type Icon =ComponentType<SvgProps>;
type IconProps = { type IconProps = {
icon: ComponentType<SvgProps>; icon: Icon;
color?: Breakpoint<string>; color?: Breakpoint<string>;
size?: YoshikiStyle<number | string>; size?: YoshikiStyle<number | string>;
}; };

View File

@ -19,14 +19,27 @@
*/ */
import { QueryIdentifier, QueryPage, User, UserP, setUserTheme, useUserTheme } from "@kyoo/models"; import { QueryIdentifier, QueryPage, User, UserP, setUserTheme, useUserTheme } from "@kyoo/models";
import { Container, P, Select, ts } from "@kyoo/primitives"; import { Container, H1, Icon, P, Select, SubP, imageBorderRadius, ts } from "@kyoo/primitives";
import { DefaultLayout } from "../layout"; import { DefaultLayout } from "../layout";
import { ReactNode } from "react"; import { ReactElement, ReactNode } from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { ScrollView, View } from "react-native"; import { ScrollView, View } from "react-native";
import { useYoshiki } from "yoshiki/native"; import { px, rem, useYoshiki } from "yoshiki/native";
const Preference = ({ label, children, ...props }: { label: string; children: ReactNode }) => { import Theme from "@material-symbols/svg-400/outlined/dark_mode.svg";
const Preference = ({
icon,
label,
description,
children,
...props
}: {
icon: Icon;
label: string;
description: string;
children: ReactNode;
}) => {
const { css } = useYoshiki(); const { css } = useYoshiki();
return ( return (
@ -42,12 +55,32 @@ const Preference = ({ label, children, ...props }: { label: string; children: Re
props, props,
)} )}
> >
<P>{label}</P> <View {...css({ flexDirection: "row", alignItems: "center" })}>
{children} <Icon icon={icon} {...css({ marginX: ts(2) })} />
<View>
<P {...css({ marginBottom: 0 })}>{label}</P>
<SubP>{description}</SubP>
</View>
</View>
<View {...css({ marginX: ts(2) })}>{children}</View>
</View> </View>
); );
}; };
const SettingsContainer = ({ children, title }: { children: ReactElement; title: string }) => {
const { css } = useYoshiki();
return (
<Container>
<H1 {...css({ fontSize: rem(2) })}>{title}</H1>
<View
{...css({ bg: (theme) => theme.variant.background, borderRadius: px(imageBorderRadius) })}
>
{children}
</View>
</Container>
);
};
const query: QueryIdentifier<User> = { const query: QueryIdentifier<User> = {
parser: UserP, parser: UserP,
path: ["auth", "me"], path: ["auth", "me"],
@ -59,17 +92,21 @@ export const SettingsPage: QueryPage = () => {
const theme = useUserTheme("auto"); const theme = useUserTheme("auto");
return ( return (
<ScrollView> <ScrollView>
<Container> <SettingsContainer title={t("settings.general.label")}>
<Preference label={t("settings.theme.label")}> <Preference
icon={Theme}
label={t("settings.general.theme.label")}
description={t("settings.general.theme.description")}
>
<Select <Select
label={t("settings.theme.label")} label={t("settings.general.theme.label")}
value={theme} value={theme}
onValueChange={(value) => setUserTheme(value)} onValueChange={(value) => setUserTheme(value)}
values={["auto", "light", "dark"]} values={["auto", "light", "dark"]}
getLabel={(key) => t(`settings.theme.${key}`)} getLabel={(key) => t(`settings.general.theme.${key}`)}
/> />
</Preference> </Preference>
</Container> </SettingsContainer>
</ScrollView> </ScrollView>
); );
}; };

View File

@ -75,11 +75,15 @@
"login": "Login" "login": "Login"
}, },
"settings": { "settings": {
"theme": { "general": {
"label": "Theme", "label": "General",
"auto": "System", "theme": {
"light": "Light", "label": "Theme",
"dark": "Dark" "description": "Set the theme of your application",
"auto": "System",
"light": "Light",
"dark": "Dark"
}
} }
}, },
"player": { "player": {

View File

@ -75,11 +75,15 @@
"login": "Connexion" "login": "Connexion"
}, },
"settings": { "settings": {
"theme": { "general": {
"label": "Thème", "label": "General",
"auto": "Système", "theme": {
"light": "Clair", "label": "Thème",
"dark": "Sombre" "description": "Définissez le thème de votre application",
"auto": "Système",
"light": "Clair",
"dark": "Sombre"
}
} }
}, },
"player": { "player": {