ClosedList.js 1.14 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

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

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

우지원's avatar
e    
우지원 committed
13
14
  const userId = sessionStorage.getItem('userId');

Choi Ga Young's avatar
Choi Ga Young committed
15
  async function getClosedList() {
16
17
18
    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
19
20
21
    console.log('가져온거', res)
    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) {
Soo Hyun Kim's avatar
soo0115    
Soo Hyun Kim committed
24
25
    console.log(e.target.name)
    console.log(e.target)
26
    const roomName = e.target.name
Yoon, Daeki's avatar
Yoon, Daeki committed
27
    props.enterChatRoom(roomName) // 각각의 room으로 들어가도록 설정해야 함
28
    props.setRoomName(roomName)
Choi Ga Young's avatar
에러    
Choi Ga Young committed
29
   
30
31
  }

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

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

export default ClosedList