Update App.tsx for theme and text size management, add history icon toggle based on theme

This commit is contained in:
2026-01-31 12:45:26 +01:00
parent b5689658e0
commit 708fe64301

View File

@@ -6,6 +6,7 @@ import { appDataDir } from "@tauri-apps/api/path";
import { listen } from "@tauri-apps/api/event"; import { listen } from "@tauri-apps/api/event";
import { invoke } from "@tauri-apps/api/core"; import { invoke } from "@tauri-apps/api/core";
import historyIcon from "./assets/history.png"; import historyIcon from "./assets/history.png";
import historyIconBright from "./assets/history_b.png";
import { import {
createText, createText,
deleteText, deleteText,
@@ -89,12 +90,25 @@ export default function App() {
bodyRef.current = body; bodyRef.current = body;
}, [body]); }, [body]);
useEffect(() => {
const storedTheme = localStorage.getItem("textdb.theme");
if (storedTheme === "light") {
setTheme("light");
}
const storedSize = Number(localStorage.getItem("textdb.textSize"));
if (!Number.isNaN(storedSize) && storedSize >= 12 && storedSize <= 18) {
setTextSize(storedSize);
}
}, []);
useEffect(() => { useEffect(() => {
document.body.dataset.theme = theme; document.body.dataset.theme = theme;
localStorage.setItem("textdb.theme", theme);
}, [theme]); }, [theme]);
useEffect(() => { useEffect(() => {
document.documentElement.style.setProperty("--base-font-size", `${textSize}px`); document.documentElement.style.setProperty("--base-font-size", `${textSize}px`);
localStorage.setItem("textdb.textSize", String(textSize));
}, [textSize]); }, [textSize]);
const isViewingHistory = viewingVersion !== null; const isViewingHistory = viewingVersion !== null;
@@ -123,6 +137,9 @@ export default function App() {
} }
}, [statusKey]); }, [statusKey]);
const historyIconSrc = theme === "light" ? historyIconBright : historyIcon;
const refreshTexts = useCallback(async () => { const refreshTexts = useCallback(async () => {
setLoadingTexts(true); setLoadingTexts(true);
try { try {
@@ -644,7 +661,7 @@ export default function App() {
title="Settings" title="Settings"
type="button" type="button"
> >
<span aria-hidden="true"></span> <span className="icon-button__glyph icon-button__glyph--large" aria-hidden="true"></span>
</button> </button>
<button <button
className="icon-button icon-button--ghost" className="icon-button icon-button--ghost"
@@ -777,7 +794,7 @@ export default function App() {
title={historyOpen ? "Close history" : "Open history"} title={historyOpen ? "Close history" : "Open history"}
type="button" type="button"
> >
<img src={historyIcon} alt="" className="icon-button__img" /> <img src={historyIconSrc} alt="" className="icon-button__img" />
</button> </button>
</div> </div>
</div> </div>