Commit b41db3c2 authored by 우지원's avatar 우지원
Browse files

채널정보 가져오기/온라인사용자 가져오기

parent 7a9a45a8
import axios from "axios"; import axios from "axios";
const getRoom = async (payload) => { const getRoom = async (id) => {
const { data } = await axios.post(`/api/room/getRoom`,payload); const { data } = await axios.post('/api/room/getRoom', id);
return data; return data;
}; };
......
import { useEffect, useState } from 'react'; import { useEffect, useState } from "react";
import { Link } from 'react-router-dom' import { Link, useParams } from "react-router-dom";
import roomApi from '../../apis/room.api'; import roomApi from "../../apis/room.api";
import userApi from '../../apis/user.api'; import userApi from "../../apis/user.api";
import catchErrors from '../../context/catchError'; import catchErrors from "../../context/catchError";
const id = localStorage.getItem('user'); const id = localStorage.getItem("user");
const INIT_ROOM={ const INIT_ROOM = {
name:"", roomid:"",
profileimg:"", name: "",
member:"", profileimg: "",
} member: "",
};
const RoomSingle = () => { const RoomSingle = () => {
const [room, setRoom] = useState(INIT_ROOM) const [room, setRoom] = useState([INIT_ROOM]);
const [error,setError]=useState('') const [error, setError] = useState("");
const channelId = 1 // const channelId = 1;
const roomId = "1234567abc" const {roomId}=useParams();
async function getJoinRoom(Id) { async function getJoinRoom(Id) {
try { try {
const User = await userApi.getUser(Id) const User = await userApi.getUser(Id);
const RoomNumArr = User.roomNumber const RoomNumArr = User.roomNumber;
const Room= await roomApi.getRoom(RoomNumArr) const Room = await roomApi.getRoom(RoomNumArr);
console.log(Room[0]) const roomlist = [];
const rrr=Room[0] for (const prop in Room) {
const memcount= rrr.member.length roomlist.push({
setRoom({...room, name:rrr.name, profileimg: rrr.profileimg, member:memcount}) roomId:Room[prop].id,
console.log(room) name: Room[prop].name,
profileimg: Room[prop].profileimg,
member: Room[prop].member,
});
}
setRoom(roomlist);
} catch (error) { } catch (error) {
catchErrors(error, setError) catchErrors(error, setError);
} }
} }
useEffect(() => { useEffect(() => {
getJoinRoom(id) getJoinRoom(id);
}, [id]) }, [id]);
const { profileimg } = room;
return ( return (
<div>
{room &&
room.map((el) => (
<Link <Link
to={`/room/${roomId}/${channelId}`} to={`/room/${el.roomId}/1`}
className="text-decoration-none text-dark" className="text-decoration-none text-dark"
> >
<div <div
className="d-flex mx-4 my-2 p-2" className="d-flex mx-4 my-2 p-2"
style={{ backgroundColor: '#C4C4C4' }} style={{ backgroundColor: "#C4C4C4" }}
> >
<div style={{ width: '37px', height: '37px' }}> <div style={{ width: "37px", height: "37px" }}>
{/* <img <img
src={`/roomUploads/${profileimg}`} src={`/roomUploads/${el.profileimg}`}
className="rounded-circle" className="rounded-circle"
style={{ width: '37px', height: '37px' }} style={{ width: "37px", height: "37px" }}
/> */} />
</div> </div>
<div <div
className="mx-3 mt-2" className="mx-3 mt-2"
style={{ style={{
width: '250px', width: "250px",
overflow:'scroll', overflow: "scroll",
whiteSpace: 'nowrap', whiteSpace: "nowrap",
msOverflowStyle:'none', msOverflowStyle: "none",
}} }}
> >
{room.name} {el.name}
</div> </div>
<div className="ms-auto mt-2"> {room.member}/100 </div> <div className="ms-auto mt-2"> {el.member}/100 </div>
</div> </div>
</Link> </Link>
) ))}
} </div>
);
};
export default RoomSingle export default RoomSingle;
\ No newline at end of file
import { Link, Route, Switch, useParams } from "react-router-dom"; import { Link, Route, Switch, useParams } from "react-router-dom";
const ChannelSingle = () => { const ChannelSingle = (props) => {
const { roomId } = useParams(); const { roomId } = useParams();
console.log('props', props.channel)
return ( return (
<div className="overflow-auto" style={{ height: "610px" }}> <div>
<div
className="overflow-auto"
style={{ height: "610px" }}
>
{props.channel.map((el) => (
<div className="mb-3"> <div className="mb-3">
<div className="m-3 p-1 row" style={{ backgroundColor: "#E0CEE8" }}> <div className="m-3 p-1 row" style={{ backgroundColor: "#E0CEE8" }}>
<Link to={`${roomId}/meeting`}> <Link to={`${roomId}/${el.channelName}`}>
<img <img
className="col-auto mt-2" className="col-auto mt-2"
src="/fullSpeaker.png" src="/fullSpeaker.png"
...@@ -14,93 +20,18 @@ const ChannelSingle = () => { ...@@ -14,93 +20,18 @@ const ChannelSingle = () => {
height="25px" height="25px"
/> />
<h5 className="col mt-2" style={{ color: "black" }}> <h5 className="col mt-2" style={{ color: "black" }}>
회의 {el.channelName}
</h5> </h5>
</Link> </Link>
</div> </div>
<ul className="mx-5" style={{ color: "#76D079" }}>
<li>
<p style={{ color: "black" }}>CHERRY</p>
</li>
<li>
<p style={{ color: "black" }}>JAEYEON</p>
</li>
<li>
<p style={{ color: "black" }}>SEOYEON</p>
</li>
<li>
<p style={{ color: "black" }}>JIWEON</p>
</li>
<li>
<p style={{ color: "black" }}>BYOUNGYUN</p>
</li>
</ul>
</div>
<div className="mb-3"> {el.joinName && el.joinName.map((e) =>
<div className="m-3 p-1 row" style={{ backgroundColor: "#E0CEE8" }}> <div><ul className="mx-5" style={{ color: "#76D079" }}>
<img
className="col-auto mt-2"
src="/emptySpeaker.png"
width="25px"
height="25px"
/>
<Link to={`${roomId}/normal`}>
<h5 className="col mt-2" style={{ color: "black" }}>
일반
</h5>
</Link>
</div>
<ul className="mx-5" style={{ color: "#76D079" }}>
<li>
<p style={{ color: "black" }}>CHERRY</p>
</li>
<li>
<p style={{ color: "black" }}>JAEYEON</p>
</li>
<li>
<p style={{ color: "black" }}>SEOYEON</p>
</li>
<li>
<p style={{ color: "black" }}>JIWEON</p>
</li>
<li>
<p style={{ color: "black" }}>BYOUNGYUN</p>
</li>
</ul>
</div>
<div className="mb-3">
<div className="m-3 p-1 row" style={{ backgroundColor: "#E0CEE8" }}>
<img
className="col-auto mt-2"
src="/emptySpeaker.png"
width="25px"
height="25px"
/>
<Link to={`${roomId}/notice`}>
<h5 className="col mt-2" style={{ color: "black" }}>
공지
</h5>
</Link>
</div>
<ul className="mx-5" style={{ color: "#76D079" }}>
<li>
<p style={{ color: "black" }}>CHERRY</p>
</li>
<li>
<p style={{ color: "black" }}>JAEYEON</p>
</li>
<li>
<p style={{ color: "black" }}>SEOYEON</p>
</li>
<li>
<p style={{ color: "black" }}>JIWEON</p>
</li>
<li> <li>
<p style={{ color: "black" }}>BYOUNGYUN</p> <p style={{ color: "black" }}>{e}</p>
</li> </li>
</ul> </ul></div>)}
</div>))}
</div> </div>
</div> </div>
); );
......
import ChannelSingle from "./ChannelSingle"; import ChannelSingle from "./ChannelSingle";
import catchErrors from "../../context/catchError"; import catchErrors from "../../context/catchError";
import roomApi from "../../apis/room.api"; import roomApi from "../../apis/room.api";
import { useState } from "react"; import { useState, useEffect } from "react";
import { useParams } from "react-router-dom";
const userId = localStorage.getItem('user'); const userId = localStorage.getItem('user');
const INIT_ROOM = { const INIT_ROOM = {
...@@ -11,7 +12,46 @@ const INIT_ROOM = { ...@@ -11,7 +12,46 @@ const INIT_ROOM = {
profileimg: '', profileimg: '',
} }
const INIT_CHANNEL = {
channelName: "",
joinName: [],
};
const LeftHamberger = () => { const LeftHamberger = () => {
const [channel, setChannel] = useState([INIT_CHANNEL]);
const { roomId } = useParams();
const [error, setError] = useState("");
async function getChannel(roomId) {
console.log('roomId', roomId)
const ID = roomId
try {
const data = await roomApi.getRoom([ID]);
const Channel = data[0].channel
console.log('방데이터:', Channel[0])
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,
joinName: Channel[prop][key]
});
}
}
setChannel(channelList);
} catch (error) {
catchErrors(error, setError);
}
}
console.log(channel)
useEffect(() => {
console.log('roomId', roomId)
getChannel(roomId);
}, [roomId]);
function roomIdCopy() { function roomIdCopy() {
const t = document.querySelector("#roomId").innerText; const t = document.querySelector("#roomId").innerText;
...@@ -72,23 +112,17 @@ const LeftHamberger = () => { ...@@ -72,23 +112,17 @@ const LeftHamberger = () => {
<div className="m-3 p-1 row" style={{ backgroundColor: "#E0CEE8" }}> <div className="m-3 p-1 row" style={{ backgroundColor: "#E0CEE8" }}>
<h5 className="col mt-2">온라인 사용자</h5> <h5 className="col mt-2">온라인 사용자</h5>
</div> </div>
{channel.map((el) => (
<div>
{el.joinName && el.joinName.map((e) => (
<ul className="mx-5" style={{ color: "#76D079" }}> <ul className="mx-5" style={{ color: "#76D079" }}>
<li> <li>
<p style={{ color: "black" }}>CHERRY</p> <p style={{ color: "black" }}>{e}</p>
</li>
<li>
<p style={{ color: "black" }}>JAEYEON</p>
</li>
<li>
<p style={{ color: "black" }}>SEOYEON</p>
</li>
<li>
<p style={{ color: "black" }}>JIWEON</p>
</li>
<li>
<p style={{ color: "black" }}>BYOUNGYUN</p>
</li> </li>
</ul> </ul>
))}
</div>
))}
</div> </div>
<div className="mb-3"> <div className="mb-3">
......
import { useState } from "react"; import { useState, useEffect } from "react";
import ChannelSingle from './ChannelSingle' import { useParams } from "react-router-dom";
import ChannelSingle from "./ChannelSingle";
import Rightimg from "../../images/RightHamburgerImg.png";
import RoomApi from "../../apis/room.api";
import roomApi from "../../apis/room.api";
import catchErrors from "../../context/catchError";
const RightHamberger = () => { const INIT_CHANNEL = {
const [admin, setAdmin] = useState('true') channelName: "",
joinName: [],
};
const RightHamburger = () => {
const [channel, setChannel] = useState([INIT_CHANNEL]);
const { roomId } = useParams();
const [error, setError] = useState("");
async function getChannel(roomId) {
console.log('roomId', 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,
joinName: Channel[prop][key]
});
}
}
setChannel(channelList);
} catch (error) {
catchErrors(error, setError);
}
}
console.log(channel)
useEffect(() => {
console.log('roomId', roomId)
getChannel(roomId);
}, [roomId]);
return ( return (
<div> <div>
<div> <div>
...@@ -14,15 +56,14 @@ const RightHamberger = () => { ...@@ -14,15 +56,14 @@ const RightHamberger = () => {
aria-controls="right-hamburger" aria-controls="right-hamburger"
aria-expanded="false" aria-expanded="false"
aria-label="Toggle navigation" aria-label="Toggle navigation"
style={{ border: '#f4c1f2' }} style={{ border: "#f4c1f2" }}
> >
<span className="navbar-toggler-icon"></span> <img src={Rightimg} width="50px" height="30px" />
</button> </button>
</div> </div>
<div <div
className="offcanvas offcanvas-end" className="offcanvas offcanvas-end"
style={{ width: '330px' }} style={{ width: "330px" }}
tabIndex="-1" tabIndex="-1"
id="right-hamburger" id="right-hamburger"
aria-labelledby="hamburgerLabel" aria-labelledby="hamburgerLabel"
...@@ -32,17 +73,20 @@ const RightHamberger = () => { ...@@ -32,17 +73,20 @@ const RightHamberger = () => {
className="col-6 offcanvas-title" className="col-6 offcanvas-title"
id="offcanvasExampleLabel" id="offcanvasExampleLabel"
style={{ style={{
fontWeight: 'bold', fontWeight: "bold",
fontSize: '15px', fontSize: "15px",
overflow: 'hidden', overflow: "hidden",
whiteSpace: 'nowrap', whiteSpace: "nowrap",
width: '150px', width: "150px",
color: '#000000', color: "#000000",
}} }}
> >
데계데계데계데계데계데계데계데계데계데계 재밌는 수학과 이름{/*Room.name*/}
</p> </p>
<h6 className="mt-2" id="roomId" > #ASV2AE985 </h6> <h6 className="mt-2" id="roomId">
{" "}
{`${roomId}`}{" "}
</h6>
<button <button
type="button" type="button"
className="btn-close text-reset" className="btn-close text-reset"
...@@ -51,7 +95,7 @@ const RightHamberger = () => { ...@@ -51,7 +95,7 @@ const RightHamberger = () => {
></button> ></button>
</div> </div>
<ChannelSingle /> <ChannelSingle channel={channel}/>
<div> <div>
<div className="d-flex flex-row-reverse"> <div className="d-flex flex-row-reverse">
<button <button
...@@ -60,28 +104,30 @@ const RightHamberger = () => { ...@@ -60,28 +104,30 @@ const RightHamberger = () => {
data-bs-toggle="modal" data-bs-toggle="modal"
data-bs-target="#exitRoom" data-bs-target="#exitRoom"
style={{ style={{
height: '30px', height: "30px",
fontWeight: 'bold', fontWeight: "bold",
backgroundColor: '#d86da6', backgroundColor: "#d86da6",
color: 'black', color: "black",
border: '1px #d86da6', border: "1px #d86da6",
}} }}
> >
퇴장 퇴장
</button> </button>
{admin ? <button {/* {admin ? (
<button
type="button" type="button"
className="m-3 rounded" className="m-3 rounded"
style={{ style={{
height: '30px', height: "30px",
fontWeight: 'bold', fontWeight: "bold",
backgroundColor: '#E0CEE8', backgroundColor: "#E0CEE8",
color: 'black', color: "black",
border: '1px #D64D61', border: "1px #D64D61",
}} }}
> >
설정 설정
</button> : null} </button>
) : null} */}
<div <div
className="modal fade" className="modal fade"
...@@ -129,10 +175,8 @@ const RightHamberger = () => { ...@@ -129,10 +175,8 @@ const RightHamberger = () => {
</div> </div>
</div> </div>
</div> </div>
</div > </div>
) );
};
}
export default RightHamberger export default RightHamburger;
\ No newline at end of file \ No newline at end of file
...@@ -92,9 +92,8 @@ const createRoom = async (req, res) => { ...@@ -92,9 +92,8 @@ const createRoom = async (req, res) => {
const getRoom = async (req, res) => { const getRoom = async (req, res) => {
console.log("fhgfghdgfdgf:", req.body); console.log("fhgfghdgfdgf:", req.body);
const roomId = req.body
try { try {
const roomlist = await Room.findAll({ where: { id: roomId } }); const roomlist = await Room.findAll({ where: { id: req.body} });
console.log(roomlist); console.log(roomlist);
res.json(roomlist) res.json(roomlist)
} catch (error) { } catch (error) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment