Skip to content

Commit

Permalink
Merge pull request #478 from sparcs-kaist/feat/chat-date-divider
Browse files Browse the repository at this point in the history
feat/chat date divider
  • Loading branch information
yumincho authored Mar 27, 2024
2 parents 3ff72ec + 0ee3b89 commit 7032f83
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
23 changes: 19 additions & 4 deletions packages/web/src/components/organisms/ChatSection.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import React, { useEffect } from "react";
import styled from "@emotion/styled";
import { useInView } from "react-intersection-observer";

import { Text } from "@biseo/web/components/atoms";
import { formatDate } from "@biseo/web/utils/format";
import { Divider, Text } from "@biseo/web/components/atoms";
import {
ChatHeader,
ChatInput,
Message,
} from "@biseo/web/components/molecules";
import { margin, round, padding, center, text } from "@biseo/web/styles";
import { useChat } from "@biseo/web/services";

const Container = styled.div`
Expand Down Expand Up @@ -36,8 +37,22 @@ export const ChatSection: React.FC = () => {
<Container>
<ChatHeader title="스레드" />
<Message.List ref={scrollRef}>
{messages.map(message => (
<Message key={message.id} message={message} />
{messages.map((message, index) => (
<>
<Message key={message.id} message={message} />
{formatDate(messages[index + 1]?.createdAt) !==
formatDate(message.createdAt) && (
<div
css={[round.xl, padding(8), center, text.body, text.gray500]}
>
<Divider />
<span css={[margin(8), `white-space: nowrap`]}>
{formatDate(message.createdAt)}
</span>
<Divider />
</div>
)}
</>
))}
{hasMore && (
<Text ref={ref} variant="body" color="gray400">
Expand Down
11 changes: 11 additions & 0 deletions packages/web/src/utils/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,14 @@ export const formatTime = (isoString: string) => {

return `${ampm} ${displayHours}:${displayMinutes}`;
};

export const formatDate = (isoString: string) => {
const time = new Date(isoString);

const year = time.getFullYear();
const month = time.getMonth() + 1;
const date = time.getDate();
const day = ["일", "월", "화", "수", "목", "금", "토"][time.getDay()];

return `${year}${month}${date}일 (${day})`;
};

0 comments on commit 7032f83

Please sign in to comment.