OpenList.js 1006 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) {
우지원's avatar
우지원 committed
6
  const [openlist, setOpenlist] = useState([])
우지원's avatar
e    
우지원 committed
7
8
9

  useEffect(() => {
    getOpenList();
Soo Hyun Kim's avatar
Soo Hyun Kim committed
10
  }, [props.roomCode]);
우지원's avatar
e    
우지원 committed
11
12

  async function getOpenList() {
13
    let res = await axios.get('/room/openlist')
JeongYeonwoo's avatar
dd    
JeongYeonwoo committed
14
    console.log('getOpenlist', res.data)
Choi Ga Young's avatar
Choi Ga Young committed
15
    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) {
Choi Ga Young's avatar
Choi Ga Young committed
20
    console.log('e확인', e.target)
21
    const roomCode = e.target.name
Choi Ga Young's avatar
Choi Ga Young committed
22
23
    // props.enterChatRoom(roomCode) // 각각의 room으로 들어가도록 설정해야 함
    props.openListroom(roomCode)
24
    props.setRoomCode(roomCode)
Soo Hyun Kim's avatar
soo0115    
Soo Hyun Kim committed
25
26
27
    // props.clearChat()
  }

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

export default OpenList