Skip to content

Commit

Permalink
[FE] FIX: isDeviceDarkMode 생성 & 적용 #1649
Browse files Browse the repository at this point in the history
  • Loading branch information
jnkeniaem committed Dec 19, 2024
1 parent 15bba7a commit fb0c171
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { useEffect } from "react";
import { useRecoilValue } from "recoil";
import { displayStyleState } from "@/Cabinet/recoil/atoms";
import DisplayStyleCard from "@/Cabinet/components/Card/DisplayStyleCard/DisplayStyleCard";
import { updateBodyDisplayStyle } from "@/Cabinet/components/Card/DisplayStyleCard/displayStyleInitializer";
import {
isDeviceDarkMode,
updateBodyDisplayStyle,
} from "@/Cabinet/components/Card/DisplayStyleCard/displayStyleInitializer";
import {
DisplayStyleToggleType,
DisplayStyleType,
Expand All @@ -27,7 +30,7 @@ export const getInitialDisplayStyle = (
};

const DisplayStyleCardContainer = () => {
const darkModeQuery = window.matchMedia("(prefers-color-scheme: dark)");
const darkModeQuery = isDeviceDarkMode();
const toggleType = useRecoilValue(displayStyleState);

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ export const updateBodyDisplayStyle = (style: DisplayStyleType) => {
document.body.setAttribute("display-style", style);
};

export const isDeviceDarkMode = () => {
return window.matchMedia("(prefers-color-scheme: dark)");
};

(function () {
const isClient = typeof window !== "undefined";
if (isClient) {
const darkModeQuery = window.matchMedia("(prefers-color-scheme: dark)");
const darkModeQuery = isDeviceDarkMode();

const colorMode = getInitialDisplayStyle(
getDisplayStyleFromLocalStorage(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { updateLocalStorageDisplayStyleToggle } from "@/Cabinet/components/Card/
import { getInitialDisplayStyle } from "@/Cabinet/components/Card/DisplayStyleCard/DisplayStyleCard.container";
import {
getDisplayStyleFromLocalStorage,
isDeviceDarkMode,
updateBodyDisplayStyle,
} from "@/Cabinet/components/Card/DisplayStyleCard/displayStyleInitializer";
import { ReactComponent as MoonIcon } from "@/Cabinet/assets/images/moonIcon.svg";
Expand All @@ -18,7 +19,7 @@ import {
const DarkModeToggleSwitch = ({ id }: { id: string }) => {
const [displayStyleToggle, setDisplayStyleToggle] =
useRecoilState(displayStyleState);
const darkModeQuery = window.matchMedia("(prefers-color-scheme: dark)");
const darkModeQuery = isDeviceDarkMode();
const [displayStyleType, setDisplayStyleType] = useState<DisplayStyleType>(
() => {
return getInitialDisplayStyle(
Expand Down

0 comments on commit fb0c171

Please sign in to comment.