Skip to content

Commit

Permalink
DDay
Browse files Browse the repository at this point in the history
  • Loading branch information
hhhello0507 committed Jan 15, 2025
1 parent 9e1e8af commit a64c477
Show file tree
Hide file tree
Showing 4 changed files with 195 additions and 100 deletions.
2 changes: 1 addition & 1 deletion src/component/template/Template1.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {templateFontSizeRecord} from "@remote/value/Template";
import GuestCommentsTemplate from "@src/component/template/component/GuestCommentsTemplate";
import {increaseFontSize} from "@util/html.util";
import CongratulationsTemplate from "@src/component/template/component/CongratulationsTemplate";
import WeddingDayTemplate from "@src/component/template/component/WeddingDayTemplate";
import WeddingDayTemplate from "@src/component/template/component/weddingday/WeddingDayTemplate";
import LocationTemplate from "@src/component/template/component/LocationTemplate";
import PreviewTemplate from "@src/component/template/component/PreviewTemplate";
import GalleryTemplate from "@src/component/template/component/GalleryTemplate";
Expand Down
11 changes: 9 additions & 2 deletions src/component/template/component/VideoTemplate.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, {useEffect, useRef} from 'react';
import Video from "@remote/value/Video";
import {Column} from "@designsystem/component/flexLayout";
import Text from "@designsystem/component/text";
Expand All @@ -20,7 +20,10 @@ function VideoTemplate(
<Text size={20} weight={300} color={colors.g600}>VIDEO</Text>
<Text size={16} weight={300} color={colors.g600}>{video.videoTitle}</Text>
</Column>
<iframe src={video.videoUrl}></iframe>
<S.iframe
height={250} title={video.videoTitle}
src={'https://www.youtube.com/embed/le4s2kMQWP4'}
></S.iframe>
</S.container>
);
}
Expand All @@ -33,6 +36,10 @@ const S = {
gap: 40px;
align-items: stretch;
background: ${colors.white};
`,
iframe: styled.iframe`
display: flex;
object-fit: cover;
`
}

Expand Down
171 changes: 171 additions & 0 deletions src/component/template/component/weddingday/DDay.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
import React, {useEffect, useState} from 'react';
import {Column, Row} from "@designsystem/component/flexLayout";
import Text from "@designsystem/component/text";
import colors from "@designsystem/foundation/colors";
import Icon, {IconType} from "@designsystem/foundation/icon";
import styled from "styled-components";
import WeddingSchedule from "@remote/value/WeddingSchedule";
import BaseInfo from "@remote/value/BaseInfo";

export type DDayStyle = 'style1' | 'style2';
type RemainTime = {
days: number;
hours: number;
minutes: number;
seconds: number;
}

interface DDayProps {
baseInfo: BaseInfo;
weddingSchedule: WeddingSchedule;
dDayStyle: DDayStyle;
}

function DDay(
{
baseInfo,
weddingSchedule,
dDayStyle
}: DDayProps
) {

const [remainingTime, setRemainingTime] = useState<RemainTime>({
days: 0,
hours: 0,
minutes: 0,
seconds: 0,
});

const weddingDate = weddingSchedule.weddingDate;
const date = weddingDate ? parseDate(weddingDate) : null; // 입력 날짜 파싱

useEffect(() => {
const calculateRemainingTime = () => {
if (!date) return;

const now = new Date();
const timeDiff = date.getTime() - now.getTime();

// 시간 차가 음수일 경우 결혼식이 이미 지났다는 의미
if (timeDiff <= 0) {
setRemainingTime({days: 0, hours: 0, minutes: 0, seconds: 0});
return;
}

setRemainingTime({
days: Math.floor(timeDiff / (1000 * 60 * 60 * 24)), // 남은 일수
hours: Math.floor((timeDiff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)),
minutes: Math.floor((timeDiff % (1000 * 60 * 60)) / (1000 * 60)),
seconds: Math.floor((timeDiff % (1000 * 60)) / 1000)
});
};

calculateRemainingTime();
const interval = setInterval(calculateRemainingTime, 1000);

return () => {
clearInterval(interval);
};
}, [weddingDate]);

return (
<Column gap={24} $alignItems={'center'}>
<RemainTimeComponent
dDayStyle={dDayStyle}
remainingTime={remainingTime}
/>
<Row gap={4}>
<Text size={14} weight={300}>{baseInfo.groomName}</Text>
<Icon
type={IconType.HeartFill}
size={16}
color={colors.black}
/>
<Text size={14} weight={300}>{baseInfo.brideName}의 결혼식이</Text>
<Text size={14} weight={300}
color={colors.p800}>{remainingTime.days}</Text>
<Text size={14} weight={300}>일 남았습니다.</Text>
</Row>
</Column>
);
}

function RemainTimeComponent(
{
dDayStyle,
remainingTime
}: {
dDayStyle: DDayStyle,
remainingTime: RemainTime
}
) {
switch (dDayStyle) {
case 'style1':
return (
<Row gap={12} $alignItems={'center'} style={{paddingLeft: 50, paddingRight: 50}}>
<S.dateCell>
<Text size={12} weight={400} color={colors.g300}>DAYS</Text>
<Text size={24} weight={300} color={colors.g600}>{remainingTime.days}</Text>
</S.dateCell>
<S.dateCell>
<Text size={12} weight={400} color={colors.g300}>HOUR</Text>
<Text size={24} weight={300} color={colors.g600}>{remainingTime.hours}</Text>
</S.dateCell>
<S.dateCell>
<Text size={12} weight={400} color={colors.g300}>MIN</Text>
<Text size={24} weight={300} color={colors.g600}>{remainingTime.minutes}</Text>
</S.dateCell>
<S.dateCell>
<Text size={12} weight={400} color={colors.g300}>SEC</Text>
<Text size={24} weight={300} color={colors.g600}>{remainingTime.seconds}</Text>
</S.dateCell>
</Row>
)
case 'style2':
return (
<Row $alignItems={'flex-end'}>
<Column gap={4} $alignItems={'center'}>
<Text size={12} weight={400} color={colors.g300}>SEC</Text>
<Text size={24} weight={300} color={colors.g600}>{remainingTime.days}</Text>
</Column>
<Text size={24} weight={300} color={colors.g600} style={{width: 28, textAlign: 'center'}}>:</Text>
<Column gap={4} $alignItems={'center'}>
<Text size={12} weight={400} color={colors.g300}>HOUR</Text>
<Text size={24} weight={300} color={colors.g600}>{remainingTime.hours}</Text>
</Column>
<Text size={24} weight={300} color={colors.g600} style={{width: 28, textAlign: 'center'}}>:</Text>
<Column gap={4} $alignItems={'center'}>
<Text size={12} weight={400} color={colors.g300}>MIN</Text>
<Text size={24} weight={300} color={colors.g600}>{remainingTime.minutes}</Text>
</Column>
<Text size={24} weight={300} color={colors.g600} style={{width: 28, textAlign: 'center'}}>:</Text>
<Column gap={4} $alignItems={'center'}>
<Text size={12} weight={400} color={colors.g300}>SEC</Text>
<Text size={24} weight={300} color={colors.g600}>{remainingTime.seconds}</Text>
</Column>
</Row>
)
}
}

const S = {
dateCell: styled.div`
display: flex;
width: 64px;
padding: 17px 16px 16px 16px;
flex-direction: column;
justify-content: center;
align-items: center;
border-radius: 8px;
gap: 4px;
background: ${colors.white};
box-shadow: 0 3px 8px 0 rgba(0, 0, 0, 0.16);
`
}

function parseDate(dateString: string): Date {
const [year, month, day] = dateString.split('-').map(Number);
return new Date(year, month - 1, day); // month는 0부터 시작하므로 1을 빼줍니다.
}

export default DDay;
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import React, {useEffect, useState} from 'react';
import React from 'react';
import Text from "@designsystem/component/text";
import colors from "@designsystem/foundation/colors";
import {Column, Row} from "@designsystem/component/flexLayout";
import {Column} from "@designsystem/component/flexLayout";
import HorizontalDivider from "@designsystem/component/horizontalDivider";
import Icon, {IconType} from "@designsystem/foundation/icon";
import styled from "styled-components";
import WeddingSchedule from "@remote/value/WeddingSchedule";
import BaseInfo from "@remote/value/BaseInfo";

import DDay from "@src/component/template/component/weddingday/DDay";

interface WeddingDayProps {
baseInfo: BaseInfo;
Expand All @@ -20,45 +19,10 @@ function WeddingDayTemplate(
weddingSchedule,
}: WeddingDayProps
) {
const [remainingTime, setRemainingTime] = useState({
days: 0,
hours: 0,
minutes: 0,
seconds: 0,
});

const weddingDate = weddingSchedule.weddingDate;
const date = weddingDate ? parseDate(weddingDate) : null; // 입력 날짜 파싱
const calendar = date ? getCalendar(date) : null;

useEffect(() => {
const calculateRemainingTime = () => {
if (!date) return;

const now = new Date();
const timeDiff = date.getTime() - now.getTime();

// 시간 차가 음수일 경우 결혼식이 이미 지났다는 의미
if (timeDiff <= 0) {
setRemainingTime({days: 0, hours: 0, minutes: 0, seconds: 0});
return;
}

setRemainingTime({
days: Math.floor(timeDiff / (1000 * 60 * 60 * 24)), // 남은 일수
hours: Math.floor((timeDiff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)),
minutes: Math.floor((timeDiff % (1000 * 60 * 60)) / (1000 * 60)),
seconds: Math.floor((timeDiff % (1000 * 60)) / 1000)
});
};

calculateRemainingTime();
const interval = setInterval(calculateRemainingTime, 1000);

return () => {
clearInterval(interval);
};
}, [weddingDate]);
const calendar = date ? getCalendar(date) : null;

return (
<S.root>
Expand Down Expand Up @@ -107,46 +71,11 @@ function WeddingDayTemplate(
</Column>
)}
{weddingSchedule.dDay && (
<Column gap={24} $alignItems={'center'}>
<Row gap={12} $alignItems={'center'} style={{paddingLeft: 50, paddingRight: 50}}>
<S.dateCell>
<Text size={12} weight={400} color={colors.g300}>DAYS</Text>
<Text size={24} weight={300} color={colors.g600}>
{remainingTime.days}
</Text>
</S.dateCell>
<S.dateCell>
<Text size={12} weight={400} color={colors.g300}>HOUR</Text>
<Text size={24} weight={300} color={colors.g600}>
{remainingTime.hours}
</Text>
</S.dateCell>
<S.dateCell>
<Text size={12} weight={400} color={colors.g300}>MIN</Text>
<Text size={24} weight={300} color={colors.g600}>
{remainingTime.minutes}
</Text>
</S.dateCell>
<S.dateCell>
<Text size={12} weight={400} color={colors.g300}>SEC</Text>
<Text size={24} weight={300} color={colors.g600}>
{remainingTime.seconds}
</Text>
</S.dateCell>
</Row>
<Row gap={4}>
<Text size={14} weight={300}>{baseInfo.groomName}</Text>
<Icon
type={IconType.HeartFill}
size={16}
color={colors.black}
/>
<Text size={14} weight={300}>{baseInfo.brideName}의 결혼식이</Text>
<Text size={14} weight={300}
color={colors.p800}>{remainingTime.days}</Text>
<Text size={14} weight={300}>일 남았습니다.</Text>
</Row>
</Column>
<DDay
baseInfo={baseInfo}
weddingSchedule={weddingSchedule}
dDayStyle={'style1'}
/>
)}
</S.root>
);
Expand Down Expand Up @@ -201,26 +130,9 @@ const S = {
}
}
}
`,
dateCell: styled.div`
display: flex;
width: 64px;
padding: 17px 16px 16px 16px;
flex-direction: column;
justify-content: center;
align-items: center;
border-radius: 8px;
gap: 4px;
background: ${colors.white};
box-shadow: 0 3px 8px 0 rgba(0, 0, 0, 0.16);
`
};

function parseDate(dateString: string): Date {
const [year, month, day] = dateString.split('-').map(Number);
return new Date(year, month - 1, day); // month는 0부터 시작하므로 1을 빼줍니다.
}

function getCalendar(date: Date) {
const year = date.getFullYear();
const month = date.getMonth();
Expand Down Expand Up @@ -269,4 +181,9 @@ function getCalendar(date: Date) {
);
}

function parseDate(dateString: string): Date {
const [year, month, day] = dateString.split('-').map(Number);
return new Date(year, month - 1, day); // month는 0부터 시작하므로 1을 빼줍니다.
}

export default WeddingDayTemplate;

0 comments on commit a64c477

Please sign in to comment.