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

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

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