OpenList.js 919 Bytes
Newer Older
1
import React, { useState, useEffect } from 'react'
우지원's avatar
ul    
우지원 committed
2
import { ListGroup } from 'react-bootstrap';
3
import axios from 'axios'
우지원's avatar
ul    
우지원 committed
4

Soo Hyun Kim's avatar
soo0115    
Soo Hyun Kim committed
5
function OpenList(props) {
Choi Ga Young's avatar
Choi Ga Young committed
6
  const [openlist, setOpenlist] = useState([]);
우지원's avatar
e    
우지원 committed
7
8
9
10
11
12

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

  async function getOpenList() {
13
    let res = await axios.get('/room/openlist')
Choi Ga Young's avatar
Choi Ga Young committed
14
15
    console.log('가져온거o', res)
    setOpenlist(res.data)
우지원's avatar
e    
우지원 committed
16
  }
Soo Hyun Kim's avatar
soo0115    
Soo Hyun Kim committed
17
18


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

우지원's avatar
ul    
우지원 committed
26
27
  return (
    <div>
Choi Ga Young's avatar
Choi Ga Young committed
28
      {openlist.map((item, index) =>
우지원's avatar
ul    
우지원 committed
29
        <ListGroup key={index}>
Choi Ga Young's avatar
Choi Ga Young committed
30
31
          <ListGroup.Item action onClick={enterChatroomCH} name={item.roomName}>
            {item.roomName}
우지원's avatar
ul    
우지원 committed
32
33
34
35
36
37
38
39
          </ListGroup.Item>
        </ListGroup>
      )}
    </div>
  )
}

export default OpenList