RoomSingle.js 1.77 KB
Newer Older
우지원's avatar
우지원 committed
1
import { useEffect, useState } from 'react';
seoyeon's avatar
seoyeon committed
2
import { Link } from 'react-router-dom'
우지원's avatar
e    
우지원 committed
3
import roomApi from '../../apis/room.api';
우지원's avatar
우지원 committed
4
import userApi from '../../apis/user.api';
이재연's avatar
이재연 committed
5
import catchErrors from '../../context/catchError';
우지원's avatar
우지원 committed
6

이재연's avatar
이재연 committed
7
8
9
10
11
12
const id = localStorage.getItem('user');
const INIT_ROOM={
  name:"",
  profileimg:"",
  member:"",
}
Kim, Chaerin's avatar
Kim, Chaerin committed
13
const RoomSingle = () => {
이재연's avatar
이재연 committed
14
15
  const [room, setRoom] = useState(INIT_ROOM)
  const [error,setError]=useState('')
seoyeon's avatar
seoyeon committed
16
  const channelId = 1
우지원's avatar
우지원 committed
17

이재연's avatar
이재연 committed
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
  async function getJoinRoom(Id) {
    try {
      const User = await userApi.getUser(Id)
      const RoomNumArr = User.roomNumber
      const Room= await roomApi.getRoom(RoomNumArr)
      console.log(Room[0])
      const rrr=Room[0]
      const memcount= rrr.member.length
      setRoom({...room, name:rrr.name, profileimg: rrr.profileimg, member:memcount})
      console.log(room)

    } catch (error) {
      catchErrors(error, setError)
    }
  }
우지원's avatar
우지원 committed
33

이재연's avatar
이재연 committed
34
35
36
  useEffect(() => {
    getJoinRoom(id)
  }, [id])
우지원's avatar
우지원 committed
37

Kim, Chaerin's avatar
Kim, Chaerin committed
38
  return (
seoyeon's avatar
seoyeon committed
39
40
41
42
    <Link
      to={`/room/${id}/${channelId}`}
      className="text-decoration-none text-dark"
    >
Kim, Chaerin's avatar
Kim, Chaerin committed
43
      <div
우지원's avatar
우지원 committed
44
        className="d-flex mx-4 my-2 p-2"
seoyeon's avatar
seoyeon committed
45
        style={{ backgroundColor: '#C4C4C4' }}
Kim, Chaerin's avatar
Kim, Chaerin committed
46
      >
seoyeon's avatar
seoyeon committed
47
        <div style={{ width: '37px', height: '37px' }}>
이재연's avatar
이재연 committed
48
49
          {/* <img
            src={`/roomUploads/${profileimg}`}
Kim, Chaerin's avatar
Kim, Chaerin committed
50
            className="rounded-circle"
seoyeon's avatar
seoyeon committed
51
            style={{ width: '37px', height: '37px' }}
이재연's avatar
이재연 committed
52
          /> */}
Kim, Chaerin's avatar
Kim, Chaerin committed
53
        </div>
seoyeon's avatar
seoyeon committed
54
55
56
57
58
59
60
61
62
        <div
          className="mx-3 mt-2"
          style={{
            width: '250px',
            overflow:'scroll',
            whiteSpace: 'nowrap',
            msOverflowStyle:'none',
          }}
        >
이재연's avatar
이재연 committed
63
          {room.name}
seoyeon's avatar
seoyeon committed
64
        </div>
이재연's avatar
이재연 committed
65
        <div className="ms-auto mt-2"> {room.member}/100 </div>
Kim, Chaerin's avatar
Kim, Chaerin committed
66
      </div>
우지원's avatar
우지원 committed
67

seoyeon's avatar
seoyeon committed
68
69
70
    </Link>
  )
}
Kim, Chaerin's avatar
Kim, Chaerin committed
71

seoyeon's avatar
seoyeon committed
72
export default RoomSingle