RoomSingle.js 1.8 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
seoyeon's avatar
12    
seoyeon committed
17
  const roomId = "1234567abc"
우지원's avatar
우지원 committed
18

이재연's avatar
이재연 committed
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
  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
34

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

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

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

seoyeon's avatar
seoyeon committed
73
export default RoomSingle