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/chat date divider #478

Merged
merged 2 commits into from
Mar 27, 2024
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
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 All @@ -29,15 +30,29 @@
const prevScrollPosition = scrollRef.current.scrollTop;
loadMore()
.then(() => scrollRef.current?.scrollTo(0, prevScrollPosition))
.catch(console.error);

Check warning on line 33 in packages/web/src/components/organisms/ChatSection.tsx

View workflow job for this annotation

GitHub Actions / Lint and Format (18.x, 8.x)

Unexpected console statement
}, [loadMore, inView, loading, hasMore]);

return (
<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})`;
};
Loading