import React, { useState, useEffect } from 'react'
import { ListGroup, Row, Col } from 'react-bootstrap';
import axios from 'axios'

function ClosedList(props) {

  const [list, setList] = useState([]);

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

  const userId = sessionStorage.getItem('userId');

  async function getClosedList() {
    const userid = sessionStorage.getItem('userId')
    console.log('id가져오기', userid)
    let res = await axios.get('/room/closedlist', { params: { '_id': userid } })
    console.log('가져온거', res)
    setList(res.data)
  }

  function enterChatRoomCH(e) {
    console.log(e.target.name)
    console.log(e.target)
    const roomName = e.target.name
    props.enterChatRoom(roomName) // 각각의 room으로 들어가도록 설정해야 함
    props.setRoomName(roomName)
   
  }

  //user.hasOwnProperty('이름');

  return (
    <div>
      {list.map((item, index) =>
        <ListGroup key={index}>
          <ListGroup.Item action onClick={enterChatRoomCH} name={item.roomName}>
            {item.roomName}
          </ListGroup.Item>
        </ListGroup>
      )}
    </div>
  )
}

export default ClosedList
