forked from mirrors/pronouns.cc
refactor: extract dark theme to recoil state
This commit is contained in:
parent
d3eaaaaa9d
commit
07c6bf53a9
2 changed files with 7 additions and 2 deletions
|
@ -5,11 +5,12 @@ import Link from "next/link";
|
||||||
import NavItem from "./NavItem";
|
import NavItem from "./NavItem";
|
||||||
import Logo from "./logo";
|
import Logo from "./logo";
|
||||||
import { useRecoilState } from "recoil";
|
import { useRecoilState } from "recoil";
|
||||||
import { userState } from "../lib/state";
|
import { themeState, userState } from "../lib/state";
|
||||||
import { fetchAPI, APIError, ErrorCode, MeUser } from "../lib/api-fetch";
|
import { fetchAPI, APIError, ErrorCode, MeUser } from "../lib/api-fetch";
|
||||||
|
|
||||||
export default function Navigation() {
|
export default function Navigation() {
|
||||||
const [user, setUser] = useRecoilState(userState);
|
const [user, setUser] = useRecoilState(userState);
|
||||||
|
const [darkTheme, setDarkTheme] = useRecoilState(themeState);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (user) return;
|
if (user) return;
|
||||||
|
@ -28,7 +29,6 @@ export default function Navigation() {
|
||||||
);
|
);
|
||||||
}, [user, setUser]);
|
}, [user, setUser]);
|
||||||
|
|
||||||
const [darkTheme, setDarkTheme] = useState<boolean>(false);
|
|
||||||
const [showMenu, setShowMenu] = useState(false);
|
const [showMenu, setShowMenu] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
|
@ -5,3 +5,8 @@ export const userState = atom<MeUser | null>({
|
||||||
key: "userState",
|
key: "userState",
|
||||||
default: null,
|
default: null,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const themeState = atom<boolean>({
|
||||||
|
key: "themeState",
|
||||||
|
default: false,
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in a new issue