refactor account store + much smoother collection listing updates

This commit is contained in:
daniel31x13
2024-07-30 23:19:29 -04:00
parent d1ed33b532
commit 5c5dd967c4
31 changed files with 260 additions and 259 deletions
+4 -12
View File
@@ -1,6 +1,5 @@
import SettingsLayout from "@/layouts/SettingsLayout";
import { useState, useEffect } from "react";
import useAccountStore from "@/store/account";
import SubmitButton from "@/components/SubmitButton";
import { toast } from "react-hot-toast";
import Checkbox from "@/components/Checkbox";
@@ -8,12 +7,14 @@ import useLocalSettingsStore from "@/store/localSettings";
import { useTranslation } from "next-i18next";
import getServerSideProps from "@/lib/client/getServerSideProps"; // Import getServerSideProps for server-side data fetching
import { LinksRouteTo } from "@prisma/client";
import { useUpdateUser, useUser } from "@/hooks/store/users";
export default function Appearance() {
const { t } = useTranslation();
const { updateSettings } = useLocalSettingsStore();
const [submitLoader, setSubmitLoader] = useState(false);
const { account, updateAccount } = useAccountStore();
const { data: account = [] } = useUser();
const updateUser = useUpdateUser();
const [user, setUser] = useState(account);
const [preventDuplicateLinks, setPreventDuplicateLinks] = useState<boolean>(
@@ -73,17 +74,8 @@ export default function Appearance() {
const submit = async () => {
setSubmitLoader(true);
const load = toast.loading(t("applying_changes"));
await updateUser.mutateAsync({ ...user });
const response = await updateAccount({ ...user });
toast.dismiss(load);
if (response.ok) {
toast.success(t("settings_applied"));
} else {
toast.error(response.data as string);
}
setSubmitLoader(false);
};