import React, { 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"; import KakaoShareButton from "../KakaoShareButton"; import Roomnamechange from "./Roomnamechange"; const INIT_ROOM = { name: "", owner: "", }; 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]); const roomdata = []; roomdata.push({ name: data[0].name, owner: data[0].owner, }); console.log(roomdata); setRoom(roomdata); } catch (error) { catchErrors(error, setError); } } async function exitRoom() { console.log("id, roomid정보", id, roomId); try { const data = await RoomApi.exitRoom({ id, roomId }); } catch (error) { catchErrors(error, setError); } } async function getChannel(roomId) { try { const data = await RoomApi.getRoom([roomId]); const Channel = data[0].channel; const channelList = []; for (const prop in Channel) { // Channel의 항목(prop)으로 작업을 실행합니다 for (const el in Channel[prop]) { channelList.push({ channelName: el, joinUser: Channel[prop][el], }); } } 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[0].name}

{" "} {`${roomId}`}{" "}
{room[0].owner == id ? ( ) : null}
); }; export default RightHamburger;