ClosedList.js 1.04 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) {
우지원's avatar
수정    
우지원 committed
6
7
  const [list, setList] = useState([]);

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

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

Choi Ga Young's avatar
Choi Ga Young committed
14
15
16
17
18
  async function getClosedList() {
    let res = await axios.get('/room/closedlist')
    console.log('가져온거', res)
    setList(res.data)
  }
Soo Hyun Kim's avatar
soo0115    
Soo Hyun Kim committed
19

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

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

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

export default ClosedList