Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge branch 'feat/meal', remote-tracking branch 'origin' #80

Merged
merged 4 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,19 @@ jobs:
matrix:
node-version: [18.x]
env:
NEXT_PUBLIC_SERVER_URL: ${{ secrets.NEXT_PUBLIC_SERVER_URL }}
NEXT_PUBLIC_BASE_URL: ${{ secrets.NEXT_PUBLIC_BASE_URL }}
NEXT_PUBLIC_FILE_SERVER_URL: ${{ secrets.NEXT_PUBLIC_FILE_SERVER_URL }}
NEXT_PUBLIC_TEST_DOMAIN_KEYWORD: ${{ secrets.NEXT_PUBLIC_TEST_DOMAIN_KEYWORD }}
NEXT_PUBLIC_MAIN_DOMAIN_KEYWORD: ${{ secrets.NEXT_PUBLIC_MAIN_DOMAIN_KEYWORD }}
NEXT_PUBLIC_DOMAIN: ${{ secrets.NEXT_PUBLIC_DOMAIN }}
NEXT_PUBLIC_TEST_DOMAIN: ${{ secrets.NEXT_PUBLIC_TEST_DOMAIN }}
NEXT_PUBLIC_AUTH_DOMAIN: ${{ secrets.NEXT_PUBLIC_AUTH_DOMAIN }}
NEXT_PUBLIC_OAUTH_URL: ${{ secrets.NEXT_PUBLIC_OAUTH_URL }}
NEXT_PUBLIC_GA_TRACKING_ID: ${{ secrets.NEXT_PUBLIC_GA_TRACKING_ID }}
NEXT_PUBLIC_BANNER_BASE_PATH: ${{ secrets.NEXT_PUBLIC_BANNER_BASE_PATH }}
NEXT_PUBLIC_DEFAULT_BACKGROUND_IMAGE_URL: ${{ secrets.NEXT_PUBLIC_DEFAULT_BACKGROUND_IMAGE_URL }}
NEXT_PUBLIC_DEFAULT_USER_IMAGE: ${{ secrets.NEXT_PUBLIC_DEFAULT_USER_IMAGE }}
NEXT_PUBLIC_USER_IMAGE_URL: ${{ secrets.NEXT_PUBLIC_USER_IMAGE_URL }}

steps:
- uses: actions/checkout@v3
Expand All @@ -25,7 +37,20 @@ jobs:
- name: create env file
run: |
touch .env
echo NEXT_PUBLIC_SERVER_URL=${{ secrets.NEXT_PUBLIC_SERVER_URL }} >> .env
echo NEXT_PUBLIC_BASE_URL=${{ secrets.NEXT_PUBLIC_BASE_URL }} >> .env
echo NEXT_PUBLIC_BASE_URL=${{ secrets.NEXT_PUBLIC_BASE_URL }} >> .env
echo NEXT_PUBLIC_FILE_SERVER_URL=${{ secrets.NEXT_PUBLIC_FILE_SERVER_URL }} >> .env
echo NEXT_PUBLIC_TEST_DOMAIN_KEYWORD=${{ secrets.NEXT_PUBLIC_TEST_DOMAIN_KEYWORD }} >> .env
echo NEXT_PUBLIC_MAIN_DOMAIN_KEYWORD=${{ secrets.NEXT_PUBLIC_MAIN_DOMAIN_KEYWORD }} >> .env
echo NEXT_PUBLIC_DOMAIN=${{ secrets.NEXT_PUBLIC_DOMAIN }} >> .env
echo NEXT_PUBLIC_TEST_DOMAIN=${{ secrets.NEXT_PUBLIC_TEST_DOMAIN }} >> .env
echo NEXT_PUBLIC_AUTH_DOMAIN=${{ secrets.NEXT_PUBLIC_AUTH_DOMAIN }} >> .env
echo NEXT_PUBLIC_OAUTH_URL=${{ secrets.NEXT_PUBLIC_OAUTH_URL }} >> .env
echo NEXT_PUBLIC_GA_TRACKING_ID=${{ secrets.NEXT_PUBLIC_GA_TRACKING_ID }} >> .env
echo NEXT_PUBLIC_BANNER_BASE_PATH=${{ secrets.NEXT_PUBLIC_BANNER_BASE_PATH }} >> .env
echo NEXT_PUBLIC_DEFAULT_BACKGROUND_IMAGE_URL=${{ secrets.NEXT_PUBLIC_DEFAULT_BACKGROUND_IMAGE_URL }} >> .env
echo NEXT_PUBLIC_DEFAULT_USER_IMAGE=${{ secrets.NEXT_PUBLIC_DEFAULT_USER_IMAGE }} >> .env
echo NEXT_PUBLIC_USER_IMAGE_URL=${{ secrets.NEXT_PUBLIC_USER_IMAGE_URL }} >> .env

- run: yarn
- run: yarn build
Expand Down
1 change: 1 addition & 0 deletions src/apis/httpClient/httpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,5 @@ export default {
admin: new HttpClient("api/bamboo/admin", axiosConfig),
like: new HttpClient("api/likes/update", axiosConfig),
image: new HttpClient("api/image/save", axiosConfig),
meal: new HttpClient("api/meal", axiosConfig),
};
21 changes: 21 additions & 0 deletions src/assets/data/emptyMealList.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { IMealList } from "@/interfaces";

const emptyMealList: IMealList = {
data: {
MORNING: {
content: "",
cal: 0,
},
LUNCH: {
content: "",
cal: 0,
},
DINNER: {
content: "",
cal: 0,
},
},
keys: [],
};

export default emptyMealList;
1 change: 1 addition & 0 deletions src/assets/data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export { default as emptyClassInfo } from "./emptyClassInfo";
export { default as emptyClassLevel } from "./emptyClassLevel";
export { default as emptyTimetable } from "./emptyTimetable";
export { default as emptyInputPost } from "./emptyInputPost";
export { default as emptyMealList } from "./emptyMealList";
1 change: 1 addition & 0 deletions src/constants/key.constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const KEY = {
RECOMMENT: "useRecomment",
BAMBOO: "useBamboo",
BAMBOO_ADMIN: "useBambooAdmin",
MEAL: "useMeal",
} as const;

export default KEY;
14 changes: 14 additions & 0 deletions src/helpers/getMealName.helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const getMealName = (mealName: string) => {
switch (mealName) {
case "MORNING":
return "조식";
case "LUNCH":
return "중식";
case "DINNER":
return "석식";
default:
return mealName;
}
};

export default getMealName;
1 change: 1 addition & 0 deletions src/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export { default as getWriteContentLabel } from "./getWriteContentLabel.helper";
export { default as checkPostValid } from "./checkPostValid.helper";
export { default as checkTextOverflow } from "./checkTextOverflow.helper";
export { default as getTextDepth } from "./getTextDepth.helper";
export { default as getMealName } from "./getMealName.helper";
20 changes: 20 additions & 0 deletions src/hooks/useDate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,22 @@ const useDate = () => {
return formattedDate;
};

const getMealDate = () => {
return dayjs().format("YYMMDD");
};

const getDayOfWeek = (date: string) => {
return dayjs(date, "YYMMDD").locale("ko").format("dddd");
};

const getMealDateTitle = (date: string) => {
return dayjs(date, "YYMMDD").locale("ko").format("M월 D일 dddd");
};

const setMealDate = (date: string, day: number) => {
return dayjs(date, "YYMMDD").add(day, "day").format("YYMMDD");
};

const getNowWeekDay = ({ type }: DateType) => {
const today = dayjs().day();

Expand Down Expand Up @@ -107,6 +123,10 @@ const useDate = () => {
formatDate,
getHMSDate,
getDate,
getDayOfWeek,
getMealDate,
getMealDateTitle,
setMealDate,
getNowWeekDay,
translateDay,
getDiffDayTime,
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export type { default as IClassInfo } from "./classInfo.interface";
export type { default as IClassLevel } from "./classLevel.interface";
export type { default as IEmojiState } from "./emoji.interface";
export type { default as IMealList } from "./mealList.interface";
export type { default as IMealListItem } from "./mealListItem.interface";
export type { default as IMealListItem } from "./meal.interface";
export type { default as IModalState } from "./modal.interface";
export type { default as IPost } from "./post.interface";
export type { default as IPostQuery } from "./postQuery.interface";
Expand Down
4 changes: 4 additions & 0 deletions src/interfaces/meal.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default interface IMeal {
content: string;
cal: number;
}
7 changes: 6 additions & 1 deletion src/interfaces/mealList.interface.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import IMeal from "./meal.interface";

export default interface MealListType {
mealList: Array<object>;
data: {
[meal: string]: IMeal;
};
keys: Array<string>;
}
6 changes: 0 additions & 6 deletions src/interfaces/mealListItem.interface.ts

This file was deleted.

98 changes: 91 additions & 7 deletions src/page/meal/index.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,69 @@
import React from "react";
import styled from "styled-components";
import { Aside } from "@/components/common";
import { emptyMealList } from "@/assets/data";
import { IMealList } from "@/interfaces";
import { color, flex, font } from "@/styles";
import { Column } from "@/components/Flex";
import { font } from "@/styles";
import MealSlider from "./layouts/MealSlider";
import useDate from "@/hooks/useDate";
import MealListItem from "./layouts/MealListItem";
import { useMealQuery } from "./services/query.service";

const MealPage = () => {
const { getMealDate, getDayOfWeek, setMealDate, getMealDateTitle } =
useDate();
const [currentDate, setCurrentDate] = React.useState(getMealDate());
const [mealList, setMealList] = React.useState<IMealList>(emptyMealList);
const { refetch } = useMealQuery({ date: currentDate });

React.useEffect(() => {
const handleSetDateKeyDown = (e: KeyboardEvent) => {
if (e.key === "ArrowLeft")
setCurrentDate((p) => {
if (getDayOfWeek(p) === "월요일") return setMealDate(p, -3);
return setMealDate(p, -1);
});
if (e.key === "ArrowRight")
setCurrentDate((p) => {
if (getDayOfWeek(p) === "금요일") return setMealDate(p, 3);
return setMealDate(p, 1);
});
};

window.addEventListener("keydown", handleSetDateKeyDown);
return () => {
window.removeEventListener("keydown", handleSetDateKeyDown);
};
// eslint-disable-next-line
}, []);

React.useEffect(() => {
refetch().then(({ data }) => {
if (data.keys) return setMealList(data);
return setMealList(emptyMealList);
});
// eslint-disable-next-line
}, [currentDate]);

return (
<Layout>
<Container>
<Column gap="8px" width="67%">
<Column gap="8px">
<Title />
<MealSlider />
<Description />
</Column>
<Aside />
<MealDate>{getMealDateTitle(currentDate)}</MealDate>
<MealList>
{mealList.keys.map((mealName) => (
<MealListItem
key={mealName}
mealName={mealName}
meal={mealList.data[mealName]}
/>
))}
{!mealList.keys.length && (
<NoMealText>{getMealDateTitle(currentDate)}</NoMealText>
)}
</MealList>
</Container>
</Layout>
);
Expand All @@ -26,7 +77,8 @@ const Layout = styled.div`

const Container = styled.div`
width: 76%;
display: flex;
${flex.COLUMN};
gap: 12px;
`;

const Title = styled.span`
Expand All @@ -36,4 +88,36 @@ const Title = styled.span`
}
`;

const Description = styled.span`
color: ${color.gray};
&:after {
content: "좌우 화살표 방향키를 탭해 날짜를 조정해보세요.";
}
`;

const MealList = styled.div`
display: flex;
justify-content: space-between;
align-items: center;
height: 60vh;
gap: 30px;
`;

const MealDate = styled.span`
width: 100%;
${flex.CENTER};
${font.H4};
`;

const NoMealText = styled.span`
width: 100%;
${flex.CENTER};
${font.p2};
color: ${color.gray};

&:after {
content: "에 등록된 급식이 없어요.";
}
`;

export default MealPage;
39 changes: 39 additions & 0 deletions src/page/meal/layouts/BlinkerBox.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { color, flex } from "@/styles";
import React from "react";
import styled from "styled-components";

const BlinkerBox = () => {
return (
<Container>
<Red />
<Yellow />
<Green />
</Container>
);
};

const Container = styled.div`
${flex.VERTICAL};
gap: 6px;
margin-right: auto;
`;

const Circle = styled.div`
width: 12px;
height: 12px;
border-radius: 25px;
`;

const Red = styled(Circle)`
background-color: ${color.primary_red};
`;

const Yellow = styled(Circle)`
background-color: ${color.primary_yellow};
`;

const Green = styled(Circle)`
background-color: ${color.primary_mint};
`;

export default BlinkerBox;
Loading