Skip to content

Commit

Permalink
Merge pull request #1716 from innovationacademy-kr/dev
Browse files Browse the repository at this point in the history
DEV TO MAIN
  • Loading branch information
gykoh42 authored Dec 19, 2024
2 parents c185c90 + 7950681 commit 5381cca
Show file tree
Hide file tree
Showing 15 changed files with 331 additions and 113 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@

- https://cabi.oopy.io/d208e0c9-1022-4c88-be6d-94f191899111

### 수상 내역 🏆

- 이노베이션아카데미 성과 공유 컨퍼런스 2024 **과학기술정보통신부 장관상(🥇대상)** 수상 (2024)
- 이노베이션아카데미 성과 공유 컨퍼런스 2023 **정보통신기획평가원 원장상(🥈최우수상)** 수상 (2023)
- 이노베이션아카데미 성과 공유 컨퍼런스 2022 **이노베이션 아카데미 학장상(🥉우수상)** 수상 (2022)

### 기술적 도전

- 지속할 수 있고, 확장할 수 있는 서비스를 지향하고, 한정된 자원으로 **증가하는 사용자**들에게 양질의 서비스를 제공하기 위해 **Cabi 팀**은 다음과 같이 노력했습니다:
Expand Down
2 changes: 1 addition & 1 deletion config
3 changes: 3 additions & 0 deletions frontend/src/Cabinet/assets/images/moonIcon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions frontend/src/Cabinet/assets/images/sunIcon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const CoinUseLineChart = ({
if (totalCoinUseData === undefined) {
return null;
}

const formattedData = [
{
id: "issuedCoin",
Expand All @@ -39,7 +40,7 @@ const CoinUseLineChart = ({
(data) => data.id === coinToggleType
);

const yMin = Math.min(...filteredData[0].data.map((d) => d.y));
const yMin = 0;
const yMax = Math.max(...filteredData[0].data.map((d) => d.y));

// NOTE : y축 scale을 log로 표현하기 위해 Y scale을 설정
Expand Down
Original file line number Diff line number Diff line change
@@ -1,86 +1,55 @@
import { useEffect, useState } from "react";
import { useEffect } from "react";
import { useRecoilValue } from "recoil";
import { displayStyleState } from "@/Cabinet/recoil/atoms";
import DisplayStyleCard from "@/Cabinet/components/Card/DisplayStyleCard/DisplayStyleCard";
import {
DisplayStyleToggleType,
DisplayStyleType,
} from "@/Cabinet/types/enum/displayStyle.type.enum";
import useDisplayStyleToggle from "@/Cabinet/hooks/useDisplayStyleToggle";
import {
isDeviceDarkMode,
updateBodyDisplayStyle,
} from "@/Cabinet/utils/displayStyleUtils";

// 로컬스토리지의 display-style-toggle 값에 따라 DisplayStyleType 반환
export const getInitialDisplayStyle = (
savedDisplayStyleToggle: DisplayStyleToggleType,
displayStyleToggle: DisplayStyleToggleType,
darkModeQuery: MediaQueryList
) => {
): DisplayStyleType => {
// 라이트 / 다크 버튼
if (savedDisplayStyleToggle === DisplayStyleToggleType.LIGHT)
if (displayStyleToggle === DisplayStyleToggleType.LIGHT) {
return DisplayStyleType.LIGHT;
else if (savedDisplayStyleToggle === DisplayStyleToggleType.DARK)
return DisplayStyleType.DARK;
// 디바이스 버튼
if (darkModeQuery.matches) {
} else if (displayStyleToggle === DisplayStyleToggleType.DARK) {
return DisplayStyleType.DARK;
// 디바이스 버튼
} else {
return darkModeQuery.matches
? DisplayStyleType.DARK
: DisplayStyleType.LIGHT;
}
return DisplayStyleType.LIGHT;
};

const DisplayStyleCardContainer = () => {
const savedDisplayStyleToggle =
(localStorage.getItem("display-style-toggle") as DisplayStyleToggleType) ||
DisplayStyleToggleType.DEVICE;
var darkModeQuery = window.matchMedia("(prefers-color-scheme: dark)");
const initialDisplayStyle = getInitialDisplayStyle(
savedDisplayStyleToggle,
darkModeQuery
);
const [darkMode, setDarkMode] = useState<DisplayStyleType>(
initialDisplayStyle as DisplayStyleType
);
const [toggleType, setToggleType] = useState<DisplayStyleToggleType>(
savedDisplayStyleToggle
);

const setColorsAndLocalStorage = (toggleType: DisplayStyleToggleType) => {
setToggleType(toggleType);
localStorage.setItem("display-style-toggle", toggleType);
};

const handleDisplayStyleButtonClick = (displayStyleToggleType: string) => {
if (toggleType === displayStyleToggleType) return;
setToggleType(
displayStyleToggleType as React.SetStateAction<DisplayStyleToggleType>
);
setColorsAndLocalStorage(displayStyleToggleType as DisplayStyleToggleType);
};
const darkModeQuery = isDeviceDarkMode();
const toggleType = useRecoilValue(displayStyleState);
const { addDarkModeListener } = useDisplayStyleToggle();

useEffect(() => {
darkModeQuery.addEventListener("change", (event) =>
setDarkMode(
event.matches ? DisplayStyleType.DARK : DisplayStyleType.LIGHT
)
const applyDisplayStyle = () => {
const newDarkMode = getInitialDisplayStyle(toggleType, darkModeQuery);
updateBodyDisplayStyle(newDarkMode);
};

applyDisplayStyle();
const removeListener = addDarkModeListener(
darkModeQuery,
applyDisplayStyle
);
}, []);

useEffect(() => {
document.body.setAttribute("display-style", darkMode);
}, [darkMode]);

useEffect(() => {
if (toggleType === DisplayStyleToggleType.LIGHT) {
setDarkMode(DisplayStyleType.LIGHT);
} else if (toggleType === DisplayStyleToggleType.DARK) {
setDarkMode(DisplayStyleType.DARK);
} else {
setDarkMode(
darkModeQuery.matches ? DisplayStyleType.DARK : DisplayStyleType.LIGHT
);
}
return removeListener;
}, [toggleType]);

return (
<DisplayStyleCard
displayStyleToggle={toggleType}
handleDisplayStyleButtonClick={handleDisplayStyleButtonClick}
/>
);
return <DisplayStyleCard />;
};

export default DisplayStyleCardContainer;
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import React from "react";
import { useRecoilState } from "recoil";
import styled from "styled-components";
import { displayStyleState } from "@/Cabinet/recoil/atoms";
import Card from "@/Cabinet/components/Card/Card";
import { CardContentWrapper } from "@/Cabinet/components/Card/CardStyles";
import { ReactComponent as MonitorMobileIcon } from "@/Cabinet/assets/images/monitorMobile.svg";
import { ReactComponent as MoonIcon } from "@/Cabinet/assets/images/moon.svg";
import { ReactComponent as SunIcon } from "@/Cabinet/assets/images/sun.svg";
import { DisplayStyleToggleType } from "@/Cabinet/types/enum/displayStyle.type.enum";

interface DisplayStyleProps {
displayStyleToggle: DisplayStyleToggleType;
handleDisplayStyleButtonClick: (DisplayStyleToggleType: string) => void;
}
import useDisplayStyleToggle from "@/Cabinet/hooks/useDisplayStyleToggle";

interface IToggleItemSeparated {
name: string;
key: string;
key: DisplayStyleToggleType;
icon: React.ComponentType<React.SVGProps<SVGSVGElement>>;
}

Expand All @@ -35,42 +34,48 @@ const toggleList: IToggleItemSeparated[] = [
},
];

const DisplayStyleCard = ({
displayStyleToggle,
handleDisplayStyleButtonClick,
}: DisplayStyleProps) => {
export const updateLocalStorageDisplayStyleToggle = (
toggleType: DisplayStyleToggleType
) => {
localStorage.setItem("display-style-toggle", toggleType);
};

const DisplayStyleCard = () => {
const [toggleType, setToggleType] = useRecoilState(displayStyleState);
const { updateToggleType } = useDisplayStyleToggle();
const handleButtonClick = (key: DisplayStyleToggleType) => {
if (toggleType === key) return;
updateToggleType(key);
};

return (
<>
<DisplayStyleCardWrapper>
<Card
title={"화면 스타일"}
gridArea={"displayStyle"}
width={"350px"}
height={"183px"}
>
<>
<CardContentWrapper>
<ButtonsWrapperStyled>
{toggleList.map((item) => {
const DisplayStyleIcon = item.icon;
return (
<ButtonStyled
key={item.key}
id={`${item.key}`}
isClicked={displayStyleToggle === item.key}
onClick={() => handleDisplayStyleButtonClick(item.key)}
>
{DisplayStyleIcon && <DisplayStyleIcon />}
{item.name}
</ButtonStyled>
);
})}
</ButtonsWrapperStyled>
</CardContentWrapper>
</>
</Card>
</DisplayStyleCardWrapper>
</>
<DisplayStyleCardWrapper>
<Card
title={"화면 스타일"}
gridArea={"displayStyle"}
width={"350px"}
height={"183px"}
>
<CardContentWrapper>
<ButtonsWrapperStyled>
{toggleList.map((item) => {
const DisplayStyleIcon = item.icon;
return (
<ButtonStyled
key={item.key}
id={`${item.key}`}
isClicked={toggleType === item.key}
onClick={() => handleButtonClick(item.key)}
>
<DisplayStyleIcon />
{item.name}
</ButtonStyled>
);
})}
</ButtonsWrapperStyled>
</CardContentWrapper>
</Card>
</DisplayStyleCardWrapper>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ import {
DisplayStyleToggleType,
DisplayStyleType,
} from "@/Cabinet/types/enum/displayStyle.type.enum";
import {
getDisplayStyleFromLocalStorage,
isDeviceDarkMode,
updateBodyDisplayStyle,
} from "@/Cabinet/utils/displayStyleUtils";

(function () {
const isClient = typeof window !== "undefined";
if (isClient) {
const savedDisplayStyleToggle =
(localStorage.getItem(
"display-style-toggle"
) as DisplayStyleToggleType) || DisplayStyleToggleType.DEVICE;

const darkModeQuery = window.matchMedia("(prefers-color-scheme: dark)");
const darkModeQuery = isDeviceDarkMode();

const colorMode = getInitialDisplayStyle(
savedDisplayStyleToggle,
getDisplayStyleFromLocalStorage(),
darkModeQuery
);

Expand All @@ -27,7 +27,7 @@ import {
// 이 코드가 실행중일땐 전역변수가 아직 정의가 안된 상태라 전역변수 대신 hex code 사용

document.addEventListener("DOMContentLoaded", function () {
document.body.setAttribute("display-style", colorMode);
updateBodyDisplayStyle(colorMode);
});
}
})();
Loading

0 comments on commit 5381cca

Please sign in to comment.