Skip to content

Commit

Permalink
[FE] FIX: 토글 버튼으로 화면 모드 설정한 상태에서 기기 설정으로 모드 변경시 토글 버튼을 두번 클릭해야 값이 변경되…
Browse files Browse the repository at this point in the history
…는 버그 해결 #1649
  • Loading branch information
gykoh42 committed Jul 22, 2024
1 parent 392abb3 commit 35ef96c
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions frontend/src/Cabinet/components/Common/DarkModeToggleSwitch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,27 @@ const DarkModeToggleSwitch = ({ id }: ToggleSwitchInterface) => {

const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const newToggleType =
toggleType === DisplayStyleToggleType.LIGHT
darkMode === DisplayStyleType.LIGHT
? DisplayStyleToggleType.DARK
: DisplayStyleToggleType.LIGHT;
setColorsAndLocalStorage(newToggleType);
};

useEffect(() => {
darkModeQuery.addEventListener("change", (event) =>
setDarkMode(
event.matches ? DisplayStyleType.DARK : DisplayStyleType.LIGHT
)
);
}, []);
const darkModeListener = (event: MediaQueryListEvent) => {
const newDisplayStyle = event.matches
? DisplayStyleType.DARK
: DisplayStyleType.LIGHT;
setDarkMode(newDisplayStyle);
if (toggleType === DisplayStyleToggleType.DEVICE) {
setDarkMode(newDisplayStyle);
}
};

darkModeQuery.addEventListener("change", darkModeListener);

return () => darkModeQuery.removeEventListener("change", darkModeListener);
}, [darkModeQuery, toggleType]);

useEffect(() => {
document.body.setAttribute("display-style", darkMode);
Expand Down

0 comments on commit 35ef96c

Please sign in to comment.