Save theme in local storage

This commit is contained in:
1ilit
2023-09-19 15:51:43 +03:00
parent f774699bfb
commit a51d5cf03d
3 changed files with 20 additions and 2 deletions

View File

@@ -490,6 +490,21 @@ export default function Editor(props) {
socket.on("user-connected", onUserConnected);
socket.on("user-disconnected", onUserDisconnected);
const theme = localStorage.getItem("theme");
if (theme === "dark") {
setSettings((prev) => ({ ...prev, mode: "dark" }));
const body = document.body;
if (body.hasAttribute("theme-mode")) {
body.setAttribute("theme-mode", "dark");
}
} else {
setSettings((prev) => ({ ...prev, mode: "light" }));
const body = document.body;
if (body.hasAttribute("theme-mode")) {
body.setAttribute("theme-mode", "light");
}
}
return () => {
socket.off("connect", onConnect);
socket.off("recieve-message", onRecieve);