Add account settings box

This commit is contained in:
Zoe Roux 2024-01-10 18:02:21 +01:00
parent 329b6fc67e
commit a374e23821
3 changed files with 75 additions and 7 deletions

View File

@ -18,15 +18,26 @@
* along with Kyoo. If not, see <https://www.gnu.org/licenses/>. * along with Kyoo. If not, see <https://www.gnu.org/licenses/>.
*/ */
import { QueryIdentifier, QueryPage, User, UserP, setUserTheme, useUserTheme } from "@kyoo/models"; import {
import { Container, H1, Icon, P, Select, SubP, imageBorderRadius, ts } from "@kyoo/primitives"; QueryIdentifier,
QueryPage,
User,
UserP,
setUserTheme,
useAccount,
useUserTheme,
} from "@kyoo/models";
import { Container, H1, HR, Icon, P, Select, SubP, imageBorderRadius, ts } from "@kyoo/primitives";
import { DefaultLayout } from "../layout"; import { DefaultLayout } from "../layout";
import { ReactElement, ReactNode } from "react"; import { Children, 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 { px, rem, useYoshiki } from "yoshiki/native"; import { px, rem, useYoshiki } from "yoshiki/native";
import Theme from "@material-symbols/svg-400/outlined/dark_mode.svg"; import Theme from "@material-symbols/svg-400/outlined/dark_mode.svg";
import Username from "@material-symbols/svg-400/outlined/badge.svg";
import Mail from "@material-symbols/svg-400/outlined/mail.svg";
import Password from "@material-symbols/svg-400/outlined/password.svg";
const Preference = ({ const Preference = ({
icon, icon,
@ -38,7 +49,7 @@ const Preference = ({
icon: Icon; icon: Icon;
label: string; label: string;
description: string; description: string;
children: ReactNode; children?: ReactNode;
}) => { }) => {
const { css } = useYoshiki(); const { css } = useYoshiki();
@ -67,7 +78,13 @@ const Preference = ({
); );
}; };
const SettingsContainer = ({ children, title }: { children: ReactElement; title: string }) => { const SettingsContainer = ({
children,
title,
}: {
children: ReactElement | ReactElement[];
title: string;
}) => {
const { css } = useYoshiki(); const { css } = useYoshiki();
return ( return (
<Container> <Container>
@ -75,7 +92,12 @@ const SettingsContainer = ({ children, title }: { children: ReactElement; title:
<View <View
{...css({ bg: (theme) => theme.variant.background, borderRadius: px(imageBorderRadius) })} {...css({ bg: (theme) => theme.variant.background, borderRadius: px(imageBorderRadius) })}
> >
{children} {Children.map(children, (x, i) => (
<>
{i !== 0 && <HR {...css({ marginY: ts(1) })} />}
{x}
</>
))}
</View> </View>
</Container> </Container>
); );
@ -90,8 +112,9 @@ export const SettingsPage: QueryPage = () => {
const { t } = useTranslation(); const { t } = useTranslation();
const theme = useUserTheme("auto"); const theme = useUserTheme("auto");
const account = useAccount();
return ( return (
<ScrollView> <ScrollView contentContainerStyle={{ gap: ts(4) }}>
<SettingsContainer title={t("settings.general.label")}> <SettingsContainer title={t("settings.general.label")}>
<Preference <Preference
icon={Theme} icon={Theme}
@ -107,6 +130,25 @@ export const SettingsPage: QueryPage = () => {
/> />
</Preference> </Preference>
</SettingsContainer> </SettingsContainer>
{account && (
<SettingsContainer title={t("settings.account.label")}>
<Preference
icon={Username}
label={t("settings.account.username.label")}
description={account.username}
></Preference>
<Preference
icon={Mail}
label={t("settings.account.email.label")}
description={account.email}
></Preference>
<Preference
icon={Password}
label={t("settings.account.password.label")}
description={t("settings.account.password.description")}
></Preference>
</SettingsContainer>
)}
</ScrollView> </ScrollView>
); );
}; };

View File

@ -84,6 +84,19 @@
"light": "Light", "light": "Light",
"dark": "Dark" "dark": "Dark"
} }
},
"account": {
"label": "Account",
"username": {
"label": "Username"
},
"email": {
"label": "Email"
},
"password": {
"label": "Password",
"description": "Change your password"
}
} }
}, },
"player": { "player": {

View File

@ -84,6 +84,19 @@
"light": "Clair", "light": "Clair",
"dark": "Sombre" "dark": "Sombre"
} }
},
"account": {
"label": "Compte",
"username": {
"label": "Nom d'utilisateur"
},
"email": {
"label": "Email"
},
"password": {
"label": "Mot de passe",
"description": "Changer de mot de passe"
}
} }
}, },
"player": { "player": {