ClosedList.js 1.77 KB
Newer Older
Choi Ga Young's avatar
Choi Ga Young committed
1
import React, { useState, useEffect } from 'react'
2
import { Badge, Button, ListGroup } from 'react-bootstrap';
Choi Ga Young's avatar
Choi Ga Young committed
3
import axios from 'axios'
Choi Ga Young's avatar
Choi Ga Young committed
4

5
function ClosedList(props) {
6

우지원's avatar
수정    
우지원 committed
7
8
  const [list, setList] = useState([]);

Choi Ga Young's avatar
Choi Ga Young committed
9
10
  useEffect(() => {
    getClosedList();
Soo Hyun Kim's avatar
Soo Hyun Kim committed
11
  }, [props.roomCode]);
우지원's avatar
수정    
우지원 committed
12

13
14
15
16
  useEffect(() => {
    console.log('안읽은정보', props.leaveInfo)
  }, [props.leaveInfo])

Choi Ga Young's avatar
Choi Ga Young committed
17
  async function getClosedList() {
18
19
    const userid = sessionStorage.getItem('userId')
    let res = await axios.get('/room/closedlist', { params: { '_id': userid } })
Choi Ga Young's avatar
Choi Ga Young committed
20
21
    setList(res.data)
  }
Soo Hyun Kim's avatar
soo0115    
Soo Hyun Kim committed
22

Soo Hyun Kim's avatar
Soo Hyun Kim committed
23
  function enterChatRoomCH(e) {
24
    const roomCode = e.target.name
Soo Hyun Kim's avatar
Soo Hyun Kim committed
25
    const roomName = e.target.value
26
    props.enterChatRoom(roomCode)
Soo Hyun Kim's avatar
Soo Hyun Kim committed
27
    props.setRoomCode(roomCode)
28

29
  }
우지원's avatar
수정    
우지원 committed
30

31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47

//   async function unreadMessage() {
//     //여기서 나간시간과 db의 메세지와 시간비교해서 개수를 count해주면 됨
//     //물론 그 방 별로 찾아서 list를 맵써서 하던?
//     const respond = await axios.get('/room/unreadMessage', { params: { 'leaveInfo': props.leaveInfo, 'roomId': 'fd5243a90f' } })
//     console.log('클라이언트 클로즈드 카운드', respond)
//     // console.log('클라이언트 unreadmsg',respond.data)
//     const respond222 = await axios.get('/room/dbChat')
//     return respond
//   }
// let c=''
//   useEffect(() => {
//     c =unreadMessage()
//     console.log('클로즈드 이펙트',c)
    
//   },[])

Choi Ga Young's avatar
Choi Ga Young committed
48
49
  return (
    <div>
Soo Hyun Kim's avatar
soo0115    
Soo Hyun Kim committed
50
      {list.map((item, index) =>
Choi Ga Young's avatar
Choi Ga Young committed
51
        <ListGroup key={index}>
Soo Hyun Kim's avatar
Soo Hyun Kim committed
52
          <ListGroup.Item action onClick={enterChatRoomCH} name={item.roomId} value={item.roomName}>
Choi Ga Young's avatar
Choi Ga Young committed
53
            {item.roomName}
54
            <Badge className='ml-2' pill variant='danger'>8</Badge>
Choi Ga Young's avatar
Choi Ga Young committed
55
56
57
58
59
60
61
62
          </ListGroup.Item>
        </ListGroup>
      )}
    </div>
  )
}

export default ClosedList