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

Feat#5 hyein/calendar #8

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open

Feat#5 hyein/calendar #8

wants to merge 15 commits into from

Conversation

hae2ni
Copy link

@hae2ni hae2ni commented Jul 4, 2023

๐Ÿ”ฅ Related Issues

๐Ÿ’™ ์ž‘์—… ๋‚ด์šฉ

  • ~์š”์ผ + ์‹œ๊ฐ„ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ง€๊ณ  ๋‹ฌ๋ ฅ์— ํ‘œ๊ธฐ๋ฅผ ํ•ด์ฃผ์„ธ์š”.
  • ~ ํ•™์ƒ๋งˆ๋‹ค ๋‹ค๋ฅธ ์ƒ‰๊น”๋กœ ํ‘œ๊ธฐํ•ด์ฃผ์„ธ์š”.
  • ~์‹œ๊ฐ„์ˆœ์„œ๋Œ€๋กœ ํ‘œ๊ธฐํ•ด์ฃผ์„ธ์š”!
  • ~(์‹ฌํ™”) ๋‚ ์งœ๋ฅผ ํด๋ฆญํ•˜๋ฉด ๋‚ ์งœ์™€ ์‹œ๊ฐ„์„ ์ˆ˜์ • or ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ๋„๋ก.

โœ… PR Point

React ์บ˜๋ฆฐ๋” ๊ด€๋ จ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ  ๊ตฌํ˜„ํ•ด ๋ณด์•˜์Šต๋‹ˆ๋‹ค.
๋‹ค๋งŒ, js ๋‚ ์งœ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ธ date fns๋Š” ์‚ฌ์šฉํ–ˆ์Šต๋‹ˆ๋‹ค

์ƒ๋‹จ์— ๋…„, ์›”์„ ํ‘œ๊ธฐํ•˜๊ณ  ๋„˜๊ธฐ๋Š” ๋กœ์ง์ž…๋‹ˆ๋‹ค.

export default function CalendarHeader({ currentMonth, prevMonth, nextMonth }: CalendarHeaderProps) {
  return (
    <HeaderWrapper>
      <PrevMonthButton onClick={prevMonth}>{"<"}</PrevMonthButton>
      <YearMonthWrapper>
        {format(currentMonth, "yyyy")}๋…„ {format(currentMonth, "MM")}์›”
      </YearMonthWrapper>
      <NextMonthButton onClick={nextMonth}> {">"}</NextMonthButton>
    </HeaderWrapper>
  );
}

์ƒ๋‹จ ์š”์ผ ๋กœ์ง์ž…๋‹ˆ๋‹ค.

export default function Week() {
  const DATE: string[] = ["์ผ", "์›”", "ํ™”", "์ˆ˜", "๋ชฉ", "๊ธˆ", "ํ† ", "์ผ"];

  const dateList: JSX.Element[] = DATE.map((day, index) => <DayWrapper key={index}>{day}</DayWrapper>);
  return <WeekWrapper>{dateList}</WeekWrapper>;
}

๋‚ ์งœ๋ฅผ ๋ณด์—ฌ์ฃผ๊ณ , ํ‘œ๊ธฐํ•˜๋Š” ๋กœ์ง์ž…๋‹ˆ๋‹ค.

export default function Days({ currentMonth, selectedDate }: DaysProps) {
  const monthStart = startOfMonth(currentMonth); //date-fns method๋“ค๋กœ ๊ฐ€์ ธ์™”์Šต๋‹ˆ๋‹ค. 
  const monthEnd = endOfMonth(monthStart);
  const startDate = startOfWeek(monthStart);
  const endDate: Date = endOfWeek(monthEnd);
  const scheduleData = SCHEDULE_DATA.map((item) => ({
    ...item,
    date: item.date.map((data) => parse(data, "yyyy.MM.dd", new Date())),
  })); //๊ทธ๋ƒฅ data๋กœ๋Š” date๋ฅผ ์ฝ๊ธฐ๊ฐ€ ์–ด๋ ค์›Œ์„œ `map`์„ ๋Œ๋ ค์„œ ๋ฐ”๊พธ์—ˆ์Šต๋‹ˆ๋‹ค.

  const sortedScheduleData = scheduleData.sort((a, b) => a.time.localeCompare(b.time));
//์‹œ๊ฐ„์ˆœ์œผ๋กœ ์ •๋ ฌํ•˜์˜€์Šต๋‹ˆ๋‹ค!
//์ฐธ๊ณ ๋กœ, 7์›”๋กœ ๋‚ ์งœ ๋ณ€๊ฒฝํ–ˆ์Šต๋‹ˆ๋‹น~

  const rows: React.ReactNode[] = [];
  let days: React.ReactNode[] = [];
  let day: Date = startDate;
  let formattedDate = "";

//๊ทธ ์ฃผ ๋งˆ์ง€๋ง‰ ๋‚ ,,๊ทธ๋‹ˆ๊นŒ 8์›” 5์ผ๊นŒ์ง€ ๋ณด์ด์ž–์•„์—ฌ? ๋‹ฌ๋ ฅ์—์„œ ํ๋ฆฌ๊ฒŒ, ๊ทธ๋•Œ๊นŒ์ง€ ๋ณด์ด๊ฒŒ ์„ค์ •ํ•˜์˜€์Šต๋‹ˆ๋‹ค.
  while (day <= endDate) {
    for (let i = 0; i < 7; i++) {
      formattedDate = format(day, "d");
      const sunDay = isSunday(day); //์ผ์šœ๋งŒ ์ƒ‰์„ ๋นจ๊ฐ„์ƒ‰์œผ๋กœ ๋ฐ”๊ฟ”์•ผ ํ•  ๊ฒƒ ๊ฐ™์•„์„œ์š”!
      const daySchedule = sortedScheduleData.filter((item) => item.date.some((date) => isSameDay(date, day)));
//๋ฐ์ดํ„ฐ์— ๋งž๋Š” ๋‚ ์งœ์— ํ‘œ๊ธฐํ•ด์ฃผ๊ธฐ ์œ„ํ•œ ๋กœ์ง์ž…๋‹ˆ๋‹ค.

//๋‚ ์งœ๋ฅผ ๋ณด์—ฌ์ฃผ๋Š” ๋กœ์ง์ž…๋‹ˆ๋‹น
      days.push(
        <Day key={day.toString()} $issunday={sunDay}>
          <DayText
            $issameday={isSameDay(day, selectedDate)}
            $isnotvalid={format(currentMonth, "M") !== format(day, "M")}>
            {formattedDate}
          </DayText>
          {daySchedule.map((schedule) => (
            <ScheduleWrapper key={schedule.id} $student={schedule.student}>
              {schedule.student} {schedule.time.slice(0, 5)}
            </ScheduleWrapper>
          ))}
        </Day>,
      );
      day = addDays(day, 1);
    }
    rows.push(<DaysWrapper key={day.toString()}>{days}</DaysWrapper>);
    days = [];
  }

  return <Wrapper>{rows}</Wrapper>;
}

์‚ฌ์‹ค ์•„์ง, ์‹ฌํ™”๋ถ€๋ถ„์€ ๋ชป ํ•ด์„œ,,,
์•„๋งˆ ์‹ฌํ™”๋ถ€๋ถ„์€ ๋ฐ์ดํ„ฐ๋ฅผ ๋” ๊ฐ€๊ณตํ•ด์•ผ ํ•  ๊ฒƒ ๊ฐ™์•„์„œ pwa ์ดํ›„ ์‹œ๊ฐ„ ๋‚จ์œผ๋ฉด ์ƒˆ๋กœ์šด ์ด์Šˆ ํŒŒ์„œ ์ง„ํ–‰ํ•  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค!

๐Ÿ˜ก Trouble Shooting

  • ์ปค๋‹ค๋ž€ trouble Shooting์€ ์—†์—ˆ์Šต๋‹ˆ๋‹ค (์•„์ง ์‹ฌํ™”๊ณผ์ œ๋ฅผ ์•ˆ ํ•ด์„œ ์ธ ๊ฒƒ ๊ฐ™์•„์š”)
  • ํ•™์ƒ๋งˆ๋‹ค ๊ณ ์œ ํ•œ ์ƒ‰๊น” ์–ด๋–ป๊ฒŒ ํ•  ๊นŒํ•˜๋‹ค๊ฐ€ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€๊ณตํ•˜์ง€ ์•Š๊ณ , ๊ทธ๋ƒฅ styled-component์˜ switch๋ฌธ์œผ๋กœ ํ•ด์ฃผ์—ˆ์Šต๋‹ˆ๋‹ค. ๋‚˜์ค‘์— ์„œ๋ฒ„์—์„œ ๋žœ๋ค์œผ๋กœ ํ•™์ƒ๋งˆ๋‹ค ๋ถ€์—ฌํ•˜๋Š” ๊ฒŒ ์ข‹์„ ๊ฒƒ ๊ฐ™๊ธด ํ•˜๋”๋ผ๊ตฌ์š”
${({ $student }) => {
    switch ($student) {
      case "์ง€์ˆ˜":
        return `
          background-color: #FFD9F2
        `;
        break;

      case "ํฌ์ •":
        return `
          background-color:#E3D2FA`;
        break;

      case "ํ˜œ์ธ":
        return `
            background-color:#D3F1C1`;
        break;

      case "์„ฑ๊ฒฝ":
        return `
          background-color: #CCF5ED
        `;
        break;

      case "์€๋นˆ":
        return `
          background-color:#EBDDD5 `;
        break;

      default:
        return undefined;
    }
  • ์‚ฌ์‹ค, ์‹œ๊ฐ„ ์ˆœ์œผ๋กœ ๋ณด์—ฌ์ฃผ๊ธฐ ์œ„ํ•ด sort ๋ฉ”์†Œ๋“œ๋ฅผ ์ผ๋Š”๋ฐ ์ด๊ฒŒ ํ™•์‹คํžˆ ๋งž๋Š” ๊ฑด์ง€๋Š” ๋ชจ๋ฅด๊ฒ ์Šต๋‹ˆ๋‹ค. ์ผ๋‹จ ui์ƒ์œผ๋กœ๋Š” ์‹œ๊ฐ„์ƒ์œผ๋กœ ๋ณด์—ฌ์ง‘๋‹ˆ๋‹ค!

  • ์ฒ˜์Œ์— ์บ˜๋ฆฐ๋”๋ถ€๋ถ„์˜ styled-component ์˜ props๋ฅผ ๊ฐ€๊ณตํ•˜๋Š” ๊ณผ์ •์ด ์‰ฝ์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹คใ… ใ… (๊ตฌ๊ธ€๋ง,,์ฑ—ํ”ผํ‹ฐ ์‚ฌ๋ž‘ํ•ด์š” ํ•˜ํ•˜)

interface DayProp {
  $issunday: boolean;
}

const Day = styled.article<DayProp>`
  display: flex;
  align-items: center;
  flex-direction: column;
  height: 5rem;
  width: 30rem;

  ${({ $issunday }) => `
    ${$issunday ? "color: #FCB3A6" : undefined}
  `};
`;

interface DayTextProps {
  $isnotvalid: boolean;
  $issameday: boolean;
}

const DayText = styled.p<DayTextProps>`
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.2rem;
  height: 1.2rem;

  ${({ $isnotvalid, $issameday }) => `
    ${$isnotvalid ? "color: #CED4DA" : ""}
    ${$issameday ? "color: white; background-color: #0DA98E; border-radius: 50%; " : ""}    
  `};
`;

๐Ÿ‘€ ์Šคํฌ๋ฆฐ์ƒท / GIF / ๋งํฌ

image

  • ์•„์ง ์‹ฌํ™”๊ณผ์ œ๊นŒ์ง€ ๊ฐ€์ง€ ๋ชปํ•ด์„œ,,, ์Šคํฌ๋ฆฐ์ƒท์œผ๋กœ ์ฒจ๋ถ€ํ•ฉ๋‹ˆ๋‹ค.

๐Ÿ“š Reference

@hae2ni hae2ni added feat-function ๊ธฐ๋Šฅ๊ตฌํ˜„ํ–ˆ์–ด์š” feat-UI UI ๋งŒ๋“ค์—ˆ์–ด์š” ํ˜œ์ธ ํ˜œ์ธ ๋‹ด๋‹น labels Jul 4, 2023
@hae2ni hae2ni self-assigned this Jul 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat-function ๊ธฐ๋Šฅ๊ตฌํ˜„ํ–ˆ์–ด์š” feat-UI UI ๋งŒ๋“ค์—ˆ์–ด์š” ํ˜œ์ธ ํ˜œ์ธ ๋‹ด๋‹น
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ Hyein ] ์บ˜๋ฆฐ๋” ๊ตฌํ˜„
1 participant