Skip to content

Commit

Permalink
Feat: 채팅 메세지 날짜 형식 정의
Browse files Browse the repository at this point in the history
  • Loading branch information
gamjatan9 committed Jul 10, 2024
1 parent 47b0866 commit f5b8e24
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/pages/chatModal/components/chat/ChatMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useChatScroll } from '../../hooks/useChatScroll';
import { ChatProps } from '../..';
import * as S from './styles';
import parseDate from '@/utils/parseDate';
import { formatDate } from '@/utils/formatDateforChat';

const ChatMenu = ({ chatRoomId, galleryNick }: Omit<ChatProps, 'open'>) => {
const [messages, setMessages] = useState<ChatMessageProps[]>([]);
Expand Down Expand Up @@ -60,11 +61,12 @@ const ChatMenu = ({ chatRoomId, galleryNick }: Omit<ChatProps, 'open'>) => {
const message: ChatMessageProps = {
content: newMessage,
sender: nickname,
createdAt: new Date(),
createdAt: formatDate(new Date()),
isAuthor: isAuthor,
profileImageUrl: profileImage,
};

console.log(message);
sendMessage(`/pub/ws/${chatRoomId}/chat-messages`, message);
setNewMessage('');
scrollToBottom();
Expand Down
2 changes: 1 addition & 1 deletion src/types/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface ChatMessage {
export interface ChatMessageProps {
sender: string;
content: string;
createdAt: Date;
createdAt: Date | string;
isAuthor: boolean;
profileImageUrl: string;
}
Expand Down
11 changes: 11 additions & 0 deletions src/utils/formatDateforChat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const formatDate = (date: Date) => {
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');
const hours = String(date.getHours()).padStart(2, '0');
const minutes = String(date.getMinutes()).padStart(2, '0');
const seconds = String(date.getSeconds()).padStart(2, '0');

const formattedDateString = `${year}-${month}-${day}T${hours}:${minutes}:${seconds}`;
return formattedDateString;
};

0 comments on commit f5b8e24

Please sign in to comment.