ClosedList.js 946 Bytes
Newer Older
Choi Ga Young's avatar
Choi Ga Young committed
1
import React, { useState, useEffect } from 'react'
2
import { ListGroup } 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
  useEffect(() => {
    getClosedList();
Soo Hyun Kim's avatar
Soo Hyun Kim committed
11
  }, [props.roomCode]);
우지원's avatar
수정    
우지원 committed
12

Choi Ga Young's avatar
Choi Ga Young committed
13
  async function getClosedList() {
14
15
    const userid = sessionStorage.getItem('userId')
    let res = await axios.get('/room/closedlist', { params: { '_id': userid } })
Choi Ga Young's avatar
Choi Ga Young committed
16
17
    setList(res.data)
  }
Soo Hyun Kim's avatar
soo0115    
Soo Hyun Kim committed
18

Soo Hyun Kim's avatar
Soo Hyun Kim committed
19
  function enterChatRoomCH(e) {
20
    const roomCode = e.target.name
Soo Hyun Kim's avatar
Soo Hyun Kim committed
21
    const roomName = e.target.value
22
    props.enterChatRoom(roomCode)
Soo Hyun Kim's avatar
Soo Hyun Kim committed
23
    props.setRoomCode(roomCode)
24
  }
우지원's avatar
수정    
우지원 committed
25

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

export default ClosedList