ClosedList.js 1.11 KB
Newer Older
Choi Ga Young's avatar
Choi Ga Young committed
1
import React, { useState, useEffect } from 'react'
2
import { ListGroup, Row, Col } 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

Choi Ga Young's avatar
Choi Ga Young committed
7
8
9
10
11
12
13
  const [list, setList] = useState([]);

  useEffect(() => {
    getClosedList();
  }, []);

  async function getClosedList() {
14
15
16
    const userid = sessionStorage.getItem('userId')
    console.log('id가져오기', userid)
    let res = await axios.get('/room/closedlist', { params: { '_id': userid } })
Choi Ga Young's avatar
Choi Ga Young committed
17
18
19
    console.log('가져온거', res)
    setList(res.data)
  }
Soo Hyun Kim's avatar
soo0115    
Soo Hyun Kim committed
20

21
  function enterChatroomCH(e) {
Soo Hyun Kim's avatar
soo0115    
Soo Hyun Kim committed
22
23
    console.log(e.target.name)
    console.log(e.target)
24
25
26
    const roomName = e.target.name
    props.enterChatroom(roomName) // 각각의 room으로 들어가도록 설정해야 함
    props.setRoomName(roomName)
Soo Hyun Kim's avatar
soo0115    
Soo Hyun Kim committed
27
    // props.clearChat()
28
29
  }

우지원's avatar
수정    
우지원 committed
30
31
  //user.hasOwnProperty('이름');

Choi Ga Young's avatar
Choi Ga Young committed
32
33
  return (
    <div>
Soo Hyun Kim's avatar
soo0115    
Soo Hyun Kim committed
34
      {list.map((item, index) =>
Choi Ga Young's avatar
Choi Ga Young committed
35
        <ListGroup key={index}>
Choi Ga Young's avatar
Choi Ga Young committed
36
37
          <ListGroup.Item action onClick={enterChatroomCH} name={item.roomName}>
            {item.roomName}
Choi Ga Young's avatar
Choi Ga Young committed
38
39
40
41
42
43
44
45
          </ListGroup.Item>
        </ListGroup>
      )}
    </div>
  )
}

export default ClosedList