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

[4주차] 안채연 미션 제출합니다 #18

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
16 changes: 8 additions & 8 deletions src/components/ChattingRoom/SendMessage.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useRecoilState, useRecoilValue } from "recoil";
import styled from "styled-components";
import useInput from "../../hooks/useInput";
import { useState } from "react";
import { chat, chatRoom } from "../../interface/chat";
import {
chatList,
Expand All @@ -22,21 +21,22 @@ function SendMessage() {
chatId: Date.now(),
senderId: sender,
receiverId: sender === 0 ? room : 0,
text: "dvavd", //text,
text: text,
time: time.getHours() + ":" + time.getMinutes(),
};

const newChatting: chatRoom = { roomId: room, chat: [newChat] };
const newChatting: chatRoom = {
roomId: room,
chat: [...getChatting[0].chat, newChat],
};

let copy = [...getChatting];
function AddText(text: string) {
if (text.trim()) {
copy[0].chat.concat(newChat);

//setChatting(chatting[room - 1].chat.concat(newChat));
setChatting(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이번 과제 채팅 저장하는 부분에서 엄청 힘들었는데 채연님은 깔끔하게 잘 작성하셨네요 🤩 저도 삼항연산자를 사용해서 작성해봐야겠어요!

chatting.map((chat) => (chat.roomId === room ? newChatting : chat))
);
}
}
console.log(copy[0].chat);

function onSend(e: any) {
e.preventDefault();
Expand Down