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,9 +55,29 @@ const Preference = ({ label, children, ...props }: { label: string; children: Re
props, props,
)} )}
> >
<P>{label}</P> <View {...css({ flexDirection: "row", alignItems: "center" })}>
<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>
);
};
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} {children}
</View> </View>
</Container>
); );
}; };
@ -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,12 +75,16 @@
"login": "Login" "login": "Login"
}, },
"settings": { "settings": {
"general": {
"label": "General",
"theme": { "theme": {
"label": "Theme", "label": "Theme",
"description": "Set the theme of your application",
"auto": "System", "auto": "System",
"light": "Light", "light": "Light",
"dark": "Dark" "dark": "Dark"
} }
}
}, },
"player": { "player": {
"back": "Back", "back": "Back",

View File

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