el.xwx.moe/pages/settings/appearance.tsx

111 lines
3.5 KiB
TypeScript
Raw Normal View History

import SettingsLayout from "@/layouts/SettingsLayout";
import { useState, useEffect } from "react";
import useAccountStore from "@/store/account";
import { AccountSettings } from "@/types/global";
import { toast } from "react-hot-toast";
import React from "react";
2023-11-24 06:50:16 -06:00
import useLocalSettingsStore from "@/store/localSettings";
2023-10-18 23:09:28 -05:00
export default function Appearance() {
2023-12-01 13:00:52 -06:00
const { updateSettings } = useLocalSettingsStore();
const submit = async () => {
setSubmitLoader(true);
const load = toast.loading("Applying...");
const response = await updateAccount({
...user,
});
toast.dismiss(load);
if (response.ok) {
toast.success("Settings Applied!");
} else toast.error(response.data as string);
setSubmitLoader(false);
};
const [submitLoader, setSubmitLoader] = useState(false);
const { account, updateAccount } = useAccountStore();
const [user, setUser] = useState<AccountSettings>(
!objectIsEmpty(account)
? account
: ({
// @ts-ignore
id: null,
name: "",
username: "",
email: "",
emailVerified: null,
blurredFavicons: null,
image: "",
isPrivate: true,
// @ts-ignore
createdAt: null,
whitelistedUsers: [],
} as unknown as AccountSettings)
);
function objectIsEmpty(obj: object) {
return Object.keys(obj).length === 0;
}
useEffect(() => {
if (!objectIsEmpty(account)) setUser({ ...account });
}, [account]);
return (
<SettingsLayout>
2023-11-20 11:48:41 -06:00
<p className="capitalize text-3xl font-thin inline">Appearance</p>
<div className="divider my-3"></div>
2023-11-20 11:48:41 -06:00
<div className="flex flex-col gap-5">
<div>
<p className="mb-3">Select Theme</p>
<div className="flex gap-3 w-full">
<div
2023-12-17 03:32:33 -06:00
className={`w-full text-center outline-solid outline-neutral-content outline dark:outline-neutral-700 h-28 duration-100 rounded-md flex items-center justify-center cursor-pointer select-none bg-black ${
2023-11-24 06:50:16 -06:00
localStorage.getItem("theme") === "dark"
? "dark:outline-primary text-primary"
2023-11-24 06:50:16 -06:00
: "text-white"
}`}
2023-11-24 06:50:16 -06:00
onClick={() => updateSettings({ theme: "dark" })}
>
2023-12-17 03:32:33 -06:00
<i
className="bi-moon text-6xl"
></i>
<p className="ml-2 text-2xl">Dark</p>
{/* <hr className="my-3 outline-1 outline-neutral-content dark:outline-neutral-700" /> */}
</div>
<div
2023-12-17 03:32:33 -06:00
className={`w-full text-center outline-solid outline-neutral-content outline dark:outline-neutral-700 h-28 duration-100 rounded-md flex items-center justify-center cursor-pointer select-none bg-white ${
2023-11-24 06:50:16 -06:00
localStorage.getItem("theme") === "light"
? "outline-primary text-primary"
2023-11-24 06:50:16 -06:00
: "text-black"
}`}
2023-11-24 06:50:16 -06:00
onClick={() => updateSettings({ theme: "light" })}
>
2023-12-17 03:32:33 -06:00
<i
className="bi-sun text-6xl"
></i>
<p className="ml-2 text-2xl">Light</p>
{/* <hr className="my-3 outline-1 outline-neutral-content dark:outline-neutral-700" /> */}
</div>
</div>
2023-10-18 16:50:55 -05:00
</div>
2023-12-02 12:33:07 -06:00
{/* <SubmitButton
onClick={submit}
loading={submitLoader}
label="Save"
className="mt-2 mx-auto lg:mx-0"
2023-12-02 12:33:07 -06:00
/> */}
2023-10-18 16:50:55 -05:00
</div>
</SettingsLayout>
);
}