frontend: add saving of settings state. move logout button in navigation. add close button to settings dialog.

This commit is contained in:
Kentai Radiquum 2024-04-28 01:18:40 +05:00
parent 4f680ca717
commit 93982a061c
Signed by: Radiquum
GPG key ID: 858E8EE696525EED
4 changed files with 78 additions and 23 deletions

View file

@ -71,7 +71,12 @@ export const App = (props) => {
setColorPicker={setColorPicker}
/>
)}
{settingsPopup && <Settings />}
{settingsPopup && (
<Settings
settingsPopup={settingsPopup}
setSettingsPopup={setSettingsPopup}
/>
)}
</div>
<main className="responsive">{props.children}</main>
</body>

View file

@ -77,6 +77,15 @@ export const NavigationRail = (props) => {
);
})}
{userStore.isAuth && (
<button
className="circle transparent"
onClick={() => userStore.logout()}
>
<i>logout</i>
</button>
)}
<span className="max"></span>
<button
className="circle transparent"
@ -91,17 +100,6 @@ export const NavigationRail = (props) => {
>
<i>palette</i>
</button>
{userStore.isAuth ? (
<button
className="circle transparent"
onClick={() => userStore.logout()}
>
<i>logout</i>
</button>
) : (
""
)}
</nav>
);
};

View file

@ -1,5 +1,8 @@
"use client";
import { useUserStore } from "@/app/store/user-store";
import { useSettingsStore } from "@/app/store/settings-store";
function deleteAllSettings() {
localStorage.removeItem("mode");
localStorage.removeItem("theme");
@ -9,7 +12,10 @@ function deleteSearchHistory() {
localStorage.removeItem("searches");
}
export default function Settings() {
export default function Settings(props) {
const userStore = useUserStore();
const settingsStore = useSettingsStore();
return (
<>
<dialog
@ -17,16 +23,28 @@ export default function Settings() {
style={{ blockSize: "unset" }}
>
<h5>Настройки</h5>
<nav className="wrap">
<div className="max">
<h6 className="small">сохранение в истории просмотров</h6>
</div>
<label className="switch">
<input type="checkbox" />
<span></span>
</label>
</nav>
<li className="small-divider"></li>
{userStore.isAuth && (
<>
<nav className="wrap">
<div className="max">
<h6 className="small">сохранение в истории просмотров</h6>
</div>
<label className="switch">
<input
type="checkbox"
checked={settingsStore.saveToHistory}
onChange={() =>
settingsStore.setSettings({
saveToHistory: !settingsStore.saveToHistory,
})
}
/>
<span></span>
</label>
</nav>
<li className="small-divider"></li>
</>
)}
<nav className="wrap small-space">
<button className="red" onClick={() => deleteAllSettings()}>
<i>delete_forever</i>
@ -37,6 +55,15 @@ export default function Settings() {
<span>Удалить историю поиска</span>
</button>
</nav>
<div className="medium-divider"></div>
<nav>
<button
className={`circle small transparent `}
onClick={() => props.setSettingsPopup(!props.settingsPopup)}
>
<i>close</i>
</button>
</nav>
</dialog>
</>
);

View file

@ -0,0 +1,25 @@
"use client";
import { create } from "zustand";
import { persist, createJSONStorage } from "zustand/middleware";
function saveSettings(dict) {
localStorage.setItem("settings", JSON.stringify(dict));
}
function loadSettings() {
return JSON.parse(localStorage.getItem("settings"));
}
export const useSettingsStore = create(
persist(
(set, get) => ({
saveToHistory: true,
setSettings: (dict) => {
set(dict);
},
}),
{
name: "settings",
},
),
);