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>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,43 @@
|
||||
.bottom-bar {
|
||||
width: 100%;
|
||||
font-size: 0.5em;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5em;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.bottom-bar>*, .bottom-bar>div>* {
|
||||
max-height: 1em;
|
||||
height: 1em;
|
||||
min-height: 1em;
|
||||
gap: 0.25em;
|
||||
}
|
||||
|
||||
.bottom-bar #circle {
|
||||
color: var(--mui-primary-main);
|
||||
}
|
||||
|
||||
.bottom-bar #circle::before {
|
||||
content: " ";
|
||||
}
|
||||
|
||||
.bottom-bar #circle.error {
|
||||
color: var(--mui-error-main);
|
||||
}
|
||||
|
||||
|
||||
.bottom-bar #circle.loaded {
|
||||
color: var(--mui-success-light);
|
||||
}
|
||||
|
||||
.bottom-bar .settings {
|
||||
font-size: 0.75em;
|
||||
padding: 1em 0.5em;
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
.bottom-bar .settings svg {
|
||||
height: 0.5em;
|
||||
width: 0.5em;
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import "./index.css";
|
||||
import { FC, useState } from "react";
|
||||
import { useHAConnection } from "haService/connection";
|
||||
import { Button } from "components/Inputs/Buttons/Button";
|
||||
import SettingsSuggestOutlinedIcon from "@mui/icons-material/SettingsSuggestOutlined";
|
||||
import { useLang } from "lang";
|
||||
import { Modal } from "components/Modal";
|
||||
import { UserProfileEditor, UserProfileProps } from "./UserProfile";
|
||||
|
||||
export type BottomBarProps = UserProfileProps;
|
||||
export const BottomBar: FC<BottomBarProps> = ({ api }) => {
|
||||
const lang = useLang();
|
||||
const ha = useHAConnection();
|
||||
const version = process.env.REACT_APP_BUILD_VERSION ?? "n/a";
|
||||
const [isOpen, setOpen] = useState(false);
|
||||
|
||||
return (
|
||||
<div className="bottom-bar center row">
|
||||
<Modal open={isOpen}>
|
||||
<UserProfileEditor api={api} />
|
||||
<Button onClick={() => setOpen(false)}>{lang.get("CLOSE")}</Button>
|
||||
</Modal>
|
||||
<span id="connection">
|
||||
HA{" "}
|
||||
{ha.status === "loaded"
|
||||
? lang.get("CONNECTED")
|
||||
: ha.status === "error"
|
||||
? lang.get("FAILED")
|
||||
: lang.get("LOADING")}
|
||||
<b id="circle" className={ha.status}>
|
||||
🟢
|
||||
</b>
|
||||
</span>
|
||||
<span>version: {version}</span>
|
||||
<Button className="settings" onClick={() => setOpen(!isOpen)}>
|
||||
<SettingsSuggestOutlinedIcon />
|
||||
settings
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
Reference in new issue
Block a user