ClosedList.js 1014 Bytes
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

Choi Ga Young's avatar
Choi Ga Young committed
12
13
14
15
16
  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
17

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

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

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

export default ClosedList