settings -> dark/light mode
This commit is contained in:
1 parent
416d88b965
commit
03a735b281
47 files changed
+867
-736
No files matched your search
@@ -0,0 +1,63 @@
|
||||
import Alert from "@mui/material/Alert";
|
||||
import Skeleton from "@mui/material/Skeleton";
|
||||
import { ApiService } from "apiService/core";
|
||||
import { UserProfile } from "apiService/types";
|
||||
import { InputList } from "components/Inputs/InputList";
|
||||
import { useLang } from "lang";
|
||||
import { FC, useState } from "react";
|
||||
import LinearProgress from "@mui/material/LinearProgress";
|
||||
|
||||
export type UserProfileProps = {
|
||||
api: ApiService;
|
||||
};
|
||||
export const UserProfileEditor: FC<UserProfileProps> = ({ api }) => {
|
||||
const [saving, setIsSaving] = useState(false);
|
||||
const profile = api.state.userProfile;
|
||||
const lang = useLang();
|
||||
if (!profile.ready) {
|
||||
return (
|
||||
<div className="user-profile">
|
||||
<Skeleton />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
if (!profile.ok) {
|
||||
return (
|
||||
<div className="user-profile">
|
||||
<Alert color="error">{JSON.stringify(profile.error)}</Alert>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
const update =
|
||||
<K extends keyof UserProfile, D extends UserProfile[K]>(key: K) =>
|
||||
(data: D) => {
|
||||
if (profile.ready) {
|
||||
setIsSaving(true);
|
||||
api
|
||||
.setProfile({
|
||||
...profile.data,
|
||||
[key]: data,
|
||||
})
|
||||
.then(() => {
|
||||
setIsSaving(false);
|
||||
});
|
||||
}
|
||||
};
|
||||
return (
|
||||
<div className="user-profile">
|
||||
<InputList
|
||||
label={lang.get("THEME")}
|
||||
options={["dark", "light"]}
|
||||
current={profile.data.theme}
|
||||
onChange={update("theme")}
|
||||
/>
|
||||
<InputList
|
||||
label={lang.get("LANGUAGE")}
|
||||
options={["eng", "fra"]}
|
||||
current={profile.data.lang}
|
||||
onChange={update("lang")}
|
||||
/>
|
||||
{saving && <LinearProgress />}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
Reference in new issue
Block a user