import { useState, useEffect } from "react"; import { Link, useParams } from "react-router-dom"; import ChannelSingle from "./ChannelSingle"; import RoomApi from "../../apis/room.api"; import catchErrors from "../../context/catchError"; const INIT_ROOM = { name: "", }; const INIT_CHANNEL = { channelName: "", joinUser: [], }; const RightHamburger = () => { const [channel, setChannel] = useState([INIT_CHANNEL]); const [room, setRoom] = useState([INIT_ROOM]); const { roomId } = useParams(); const [error, setError] = useState(""); const id = localStorage.getItem("user"); async function getRoom(roomId) { try { const data = await RoomApi.getRoom([roomId]); setRoom({ ...room, name: data[0].name }); } catch (error) { catchErrors(error, setError); } } async function exitRoom() { console.log("id, roomid정보", id, roomId); try { const data = await RoomApi.exitRoom({ id, roomId }); console.log(data); } catch (error) { catchErrors(error, setError); } } async function getChannel(roomId) { const ID = roomId; try { const data = await RoomApi.getRoom([ID]); const Channel = data[0].channel; console.log("방데이터:", Channel); const channelList = []; for (const prop in Channel) { // Channel의 항목(prop)으로 작업을 실행합니다 for (const key in Channel[prop]) { console.log(key); console.log(prop); console.log(Channel[prop][key]); channelList.push({ channelName: key, joinUser: Channel[prop][key], }); } } setChannel(channelList); } catch (error) { catchErrors(error, setError); } } // console.log(channel) useEffect(() => { getChannel(roomId); getRoom(roomId); }, [roomId]); function roomIdCopy() { const t = document.querySelector("#roomId").innerText; console.log(t); navigator.clipboard.writeText(t); document.execCommand("copy"); } return (
{room.name}