Commit 9d342b6c authored by Choi Ga Young's avatar Choi Ga Young
Browse files

에러해결

parent 15336d57
......@@ -14,7 +14,7 @@ const INIT_CHAT = {
function Chat(props) {
const [sender, setSender] = useState([])
const [roomName, setRoomName] = useState('')
//const [roomName, setRoomName] = useState('')
const [inner, setInner] = useState([''])
const [chat, setChat] = useState([INIT_CHAT]) //object로 key는 보낸사람 value는 메세지
......@@ -43,7 +43,7 @@ function Chat(props) {
e.preventDefault()
setInner(e.target.value)
setDisabled(false)
console.log(chat)
//console.log(chat)
}
function sendMsgCH(e) {
......@@ -100,7 +100,7 @@ function Chat(props) {
setChat(intochat)
}
async function exitAndCloseRoom(){
async function exitAndCloseRoom() {
props.exitRoom(props.roomCode)
setExit(false)
props.handleChatc()
......@@ -120,7 +120,6 @@ function Chat(props) {
}, [props.recievedMsg])
useEffect(() => {
getRoomName(props.roomCode)
getPreviousChat()
// console.log('겟 룸네임', chat)
}, [props.roomCode])
......@@ -147,7 +146,6 @@ function Chat(props) {
<Col md="auto"><Button variant="light" onClick={exitAndCloseRoom}>{"나가기"}</Button></Col>
</Row>
: null}
<p>{props.newUser}님이 입장하셨습니다.</p>
{chat.map((value, index) => {
if (!(value.msg === '')) {
if (!(value.sender === user.nickname)) {
......@@ -188,7 +186,7 @@ function Chat(props) {
</Container >
<Form onSubmit={sendMsgCH} fluid>
<Form.Group className='d-flex flex-wrap-nowrap justify-content-center m-3'>
<Form.Control className='border border-warning' name='chat' type="text" value={inner} onChange={handleChange} style={{ width: '85%', position: 'fixed' }} />
<Form.Control className='border border-warning' name='chat' type="text" value={inner} onChange={handleChange} style={{ width: '85%'}} />
<Button variant="warning" type="submit" disabled={disabled} style={{ width: '10%' }}>
전송
</Button>
......
......@@ -21,43 +21,43 @@ function ClosedList(props) {
props.setRoomCode(roomCode)
props.setRoomName(roomName)
console.log('rrrrrrrrrrrrrrr', props.closedlist)
console.log('1111111111111111111', props.leaveInfo, typeof (props.leaveInfo))
// console.log('rrrrrrrrrrrrrrr', props.closedlist)
// console.log('1111111111111111111', props.leaveInfo, typeof (props.leaveInfo))
}
const [checknew, setChecknew] = useState([])
const [unreadnumber, setUnreadnumber] = useState([''])
async function dbChat() {
for (let i = 0; i <= props.closedlist.length - 1; i++) {
const respond = await axios.get('/room/dbChat', { params: { 'roomId': props.closedlist[i].roomId } })
setChecknew(respond.data)
}
}
useEffect(() => {
dbChat()
}, [props.singleChat, props.recievedMsg])
// const [checknew, setChecknew] = useState([])
// const [unreadnumber, setUnreadnumber] = useState([''])
// async function dbChat() {
// for (let i = 0; i <= props.closedlist.length - 1; i++) {
// const respond = await axios.get('/room/dbChat', { params: { 'roomId': props.closedlist[i].roomId } })
// setChecknew(respond.data)
// }
// }
// useEffect(() => {
// dbChat()
// }, [props.singleChat, props.recievedMsg])
useEffect(() => {
// console.log('chat 클라이언트 변경!')
unreadMessage()
}, [checknew])
// useEffect(() => {
// // console.log('chat 클라이언트 변경!')
// unreadMessage()
// }, [checknew])
async function unreadMessage() {
//여기서 나간시간과 db의 메세지와 시간비교해서 개수를 count해주면 됨
//물론 그 방 별로 찾아서 list를 맵써서 하던?
// console.log('ddddddddd', list[0].roomId)
// async function unreadMessage() {
// //여기서 나간시간과 db의 메세지와 시간비교해서 개수를 count해주면 됨
// //물론 그 방 별로 찾아서 list를 맵써서 하던?
// // console.log('ddddddddd', list[0].roomId)
setUnreadnumber([''])
let arr = []
for (let i = 0; i <= props.closedlist.length - 1; i++) {
const respond = await axios.get('/room/unreadMessage', { params: { 'leaveInfo': props.leaveInfo, 'roomId': props.closedlist[i].roomId } })
// setUnreadnumber([...unreadnumber, respond.data])
arr = [...arr, respond.data]
}
setUnreadnumber(arr)
// console.log('클라이언트 클로즈드 카운드', unreadnumber, list.length)
// setUnreadnumber([''])
// let arr = []
// for (let i = 0; i <= props.closedlist.length - 1; i++) {
// const respond = await axios.get('/room/unreadMessage', { params: { 'leaveInfo': props.leaveInfo, 'roomId': props.closedlist[i].roomId } })
// // setUnreadnumber([...unreadnumber, respond.data])
// arr = [...arr, respond.data]
// }
// setUnreadnumber(arr)
// // console.log('클라이언트 클로즈드 카운드', unreadnumber, list.length)
}
// }
return (
<div>
......@@ -65,7 +65,7 @@ function ClosedList(props) {
<ListGroup key={index}>
<ListGroup.Item action onClick={enterChatRoomCH} name={item.roomId} value={item.roomName}>
{item.roomName}
{unreadnumber[index] ? <Badge className='ml-2' pill variant='danger'>{unreadnumber[index]}</Badge> : ''}
{/* {[index] ? <Badge className='ml-2' pill variant='danger'>{unreadnumber[index]}</Badge> : ''} */}
</ListGroup.Item>
</ListGroup>
)
......
......@@ -10,7 +10,6 @@ import { Server } from 'socket.io';
import cors from "cors"
import Room from './models/Room.js'
import Chat from "./models/Chat.js"
import User from "./models/User.js"
connectDb()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment