mirror of
https://github.com/Radiquum/AniX.git
synced 2025-04-07 00:34:41 +00:00
frontend: add saving of settings state. move logout button in navigation. add close button to settings dialog.
This commit is contained in:
parent
4f680ca717
commit
93982a061c
4 changed files with 78 additions and 23 deletions
|
@ -71,7 +71,12 @@ export const App = (props) => {
|
||||||
setColorPicker={setColorPicker}
|
setColorPicker={setColorPicker}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{settingsPopup && <Settings />}
|
{settingsPopup && (
|
||||||
|
<Settings
|
||||||
|
settingsPopup={settingsPopup}
|
||||||
|
setSettingsPopup={setSettingsPopup}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
<main className="responsive">{props.children}</main>
|
<main className="responsive">{props.children}</main>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
@ -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>
|
<span className="max"></span>
|
||||||
<button
|
<button
|
||||||
className="circle transparent"
|
className="circle transparent"
|
||||||
|
@ -91,17 +100,6 @@ export const NavigationRail = (props) => {
|
||||||
>
|
>
|
||||||
<i>palette</i>
|
<i>palette</i>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
{userStore.isAuth ? (
|
|
||||||
<button
|
|
||||||
className="circle transparent"
|
|
||||||
onClick={() => userStore.logout()}
|
|
||||||
>
|
|
||||||
<i>logout</i>
|
|
||||||
</button>
|
|
||||||
) : (
|
|
||||||
""
|
|
||||||
)}
|
|
||||||
</nav>
|
</nav>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
|
import { useUserStore } from "@/app/store/user-store";
|
||||||
|
import { useSettingsStore } from "@/app/store/settings-store";
|
||||||
|
|
||||||
function deleteAllSettings() {
|
function deleteAllSettings() {
|
||||||
localStorage.removeItem("mode");
|
localStorage.removeItem("mode");
|
||||||
localStorage.removeItem("theme");
|
localStorage.removeItem("theme");
|
||||||
|
@ -9,7 +12,10 @@ function deleteSearchHistory() {
|
||||||
localStorage.removeItem("searches");
|
localStorage.removeItem("searches");
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function Settings() {
|
export default function Settings(props) {
|
||||||
|
const userStore = useUserStore();
|
||||||
|
const settingsStore = useSettingsStore();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<dialog
|
<dialog
|
||||||
|
@ -17,16 +23,28 @@ export default function Settings() {
|
||||||
style={{ blockSize: "unset" }}
|
style={{ blockSize: "unset" }}
|
||||||
>
|
>
|
||||||
<h5>Настройки</h5>
|
<h5>Настройки</h5>
|
||||||
<nav className="wrap">
|
{userStore.isAuth && (
|
||||||
<div className="max">
|
<>
|
||||||
<h6 className="small">сохранение в истории просмотров</h6>
|
<nav className="wrap">
|
||||||
</div>
|
<div className="max">
|
||||||
<label className="switch">
|
<h6 className="small">сохранение в истории просмотров</h6>
|
||||||
<input type="checkbox" />
|
</div>
|
||||||
<span></span>
|
<label className="switch">
|
||||||
</label>
|
<input
|
||||||
</nav>
|
type="checkbox"
|
||||||
<li className="small-divider"></li>
|
checked={settingsStore.saveToHistory}
|
||||||
|
onChange={() =>
|
||||||
|
settingsStore.setSettings({
|
||||||
|
saveToHistory: !settingsStore.saveToHistory,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<span></span>
|
||||||
|
</label>
|
||||||
|
</nav>
|
||||||
|
<li className="small-divider"></li>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
<nav className="wrap small-space">
|
<nav className="wrap small-space">
|
||||||
<button className="red" onClick={() => deleteAllSettings()}>
|
<button className="red" onClick={() => deleteAllSettings()}>
|
||||||
<i>delete_forever</i>
|
<i>delete_forever</i>
|
||||||
|
@ -37,6 +55,15 @@ export default function Settings() {
|
||||||
<span>Удалить историю поиска</span>
|
<span>Удалить историю поиска</span>
|
||||||
</button>
|
</button>
|
||||||
</nav>
|
</nav>
|
||||||
|
<div className="medium-divider"></div>
|
||||||
|
<nav>
|
||||||
|
<button
|
||||||
|
className={`circle small transparent `}
|
||||||
|
onClick={() => props.setSettingsPopup(!props.settingsPopup)}
|
||||||
|
>
|
||||||
|
<i>close</i>
|
||||||
|
</button>
|
||||||
|
</nav>
|
||||||
</dialog>
|
</dialog>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
25
frontend/app/store/settings-store.js
Normal file
25
frontend/app/store/settings-store.js
Normal 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",
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
Loading…
Add table
Reference in a new issue