Rename ThemeSwitcher ui component files
This commit is contained in:
+3
-1
@@ -1,4 +1,5 @@
|
|||||||
/*import Button from "../button/button.jsx";
|
/*
|
||||||
|
import Button from "../button/button.jsx";
|
||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import styles from "./ThemeSwitcher.module.css";
|
import styles from "./ThemeSwitcher.module.css";
|
||||||
|
|
||||||
@@ -29,6 +30,7 @@ export default function ThemeSwitcher() {
|
|||||||
<img src={`/icons/theme/${theme}.svg`} alt={`${theme} icon`} className={styles.themeIcon} />
|
<img src={`/icons/theme/${theme}.svg`} alt={`${theme} icon`} className={styles.themeIcon} />
|
||||||
<p>Changer de thème </p>
|
<p>Changer de thème </p>
|
||||||
</Button>
|
</Button>
|
||||||
|
}
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
import Button from "../Button/Button";
|
import Button from "../Button/Button";
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
import Button from "../Button/Button.tsx";
|
|
||||||
import { useState, useEffect } from "react";
|
|
||||||
import styles from "./ThemeSwitcher.module.css";
|
|
||||||
|
|
||||||
|
|
||||||
export default function ThemeSwitcher() {
|
|
||||||
|
|
||||||
const [theme, setTheme] = useState("");
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const t = localStorage.getItem("theme");
|
|
||||||
if(t) setTheme(t);
|
|
||||||
else setTheme("light");
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const switchTheme = () => {
|
|
||||||
|
|
||||||
let newTheme = theme === "light" ? "dark" : "light";
|
|
||||||
|
|
||||||
if(theme === null || theme === "") newTheme = "dark";
|
|
||||||
|
|
||||||
localStorage.setItem("theme", newTheme);
|
|
||||||
setTheme(newTheme);
|
|
||||||
|
|
||||||
window.dispatchEvent(new Event("theme-changed"));
|
|
||||||
};
|
|
||||||
|
|
||||||
return <Button variant={"default"} onClick={switchTheme} className={styles.themeBtn}>
|
|
||||||
<img src={`/icons/theme/${theme}.svg`} alt={`${theme} icon`} className={styles.themeIcon} />
|
|
||||||
<p>Changer de thème </p>
|
|
||||||
</Button>
|
|
||||||
}
|
|
||||||
@@ -2,7 +2,7 @@ import {useContext, useState, ChangeEvent} from "react";
|
|||||||
import Modal from "../../../../components/ui/Modal/Modal";
|
import Modal from "../../../../components/ui/Modal/Modal";
|
||||||
import Button from "../../../../components/ui/Button/Button";
|
import Button from "../../../../components/ui/Button/Button";
|
||||||
import styles from "./SettingsModal.module.css";
|
import styles from "./SettingsModal.module.css";
|
||||||
import ThemeSwitcher from "../../../../components/ui/themeSwitcher/ThemeSwitcher";
|
import ThemeSwitcher from "../../../../components/ui/ThemeSwitcher/ThemeSwitcher";
|
||||||
import {AuthContext} from "../../../../contexts/auth/AuthContext";
|
import {AuthContext} from "../../../../contexts/auth/AuthContext";
|
||||||
import TextInput from "../../../../components/ui/Input/Input";
|
import TextInput from "../../../../components/ui/Input/Input";
|
||||||
import updateUser from "../../../../utils/users/updateUser.js";
|
import updateUser from "../../../../utils/users/updateUser.js";
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import ThemeSwitcher from "../components/ui/themeSwitcher/ThemeSwitcher";
|
import ThemeSwitcher from "../components/ui/ThemeSwitcher/ThemeSwitcher";
|
||||||
import Background from "../components/Background/Background.jsx";
|
import Background from "../components/Background/Background.jsx";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
|||||||
Reference in New Issue
Block a user