From 8385db83117367179addab33e67c4d920b1ce467 Mon Sep 17 00:00:00 2001 From: jaeyeon Date: Mon, 9 Aug 2021 14:30:18 +0900 Subject: [PATCH] =?UTF-8?q?=EB=A8=B8=EC=A7=80=ED=95=98=EC=84=B8=EC=9A=A9?= =?UTF-8?q?=20=E3=85=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/apis/room.api.js | 8 ++ client/src/components/Header.js | 2 +- client/src/components/Home/CreateRoom.js | 2 +- client/src/components/Home/HomeProfile.js | 2 +- client/src/components/Home/JoinRoom.js | 2 +- client/src/components/Home/RoomSingle.js | 2 +- client/src/components/KakaoShareButton.js | 2 +- client/src/components/Login.js | 2 +- client/src/components/Profile/Info.js | 2 +- client/src/components/Profile/InfoUpdate.js | 2 +- client/src/components/Profile/Profile.js | 2 +- client/src/components/Room/ChannelList.js | 2 +- client/src/components/Room/ChannelSingle.js | 2 +- client/src/components/Room/RightHamburger.js | 43 ++++++++++- client/src/context/auth.js | 6 +- client/src/context/auth_context.js | 4 +- client/src/pages/InvitePage.js | 2 +- server/controllers/room.controller.js | 78 +++++++++++--------- server/routes/room.route.js | 1 + 19 files changed, 111 insertions(+), 55 deletions(-) diff --git a/client/src/apis/room.api.js b/client/src/apis/room.api.js index 1ed7a59..8c24314 100644 --- a/client/src/apis/room.api.js +++ b/client/src/apis/room.api.js @@ -37,6 +37,13 @@ const doubleJoin = async (payload) => { return data; }; +const removeRoom = async (ID)=>{ + const { data } = await axios.delete( + `/api/room/removeRoom/${ID.roomId}` + ); + return data; +} + // const makeChannel = async (payload) => { // const { data } = await axios.post("/api/room/makeChannel", payload); // return data; @@ -50,6 +57,7 @@ const roomApi = { changename, joinChannel, doubleJoin, + removeRoom }; export default roomApi; diff --git a/client/src/components/Header.js b/client/src/components/Header.js index 75d35c6..52e4e69 100644 --- a/client/src/components/Header.js +++ b/client/src/components/Header.js @@ -2,7 +2,7 @@ import { Link } from 'react-router-dom' import { handleLogout } from '../context/auth' const Header = () => { - const id = localStorage.getItem('user'); + const id = sessionStorage.getItem('user'); return (
{ const [roomId, setRoomId] = useState(""); diff --git a/client/src/components/Home/RoomSingle.js b/client/src/components/Home/RoomSingle.js index 1737dba..9c0b69a 100644 --- a/client/src/components/Home/RoomSingle.js +++ b/client/src/components/Home/RoomSingle.js @@ -4,7 +4,7 @@ import roomApi from "../../apis/room.api"; import userApi from "../../apis/user.api"; import catchErrors from "../../context/catchError"; -const id = localStorage.getItem("user"); +const id = sessionStorage.getItem("user"); const INIT_ROOM = { roomId: "", name: "", diff --git a/client/src/components/KakaoShareButton.js b/client/src/components/KakaoShareButton.js index c941312..42469b0 100644 --- a/client/src/components/KakaoShareButton.js +++ b/client/src/components/KakaoShareButton.js @@ -13,7 +13,7 @@ const KakaoShareButton = (porps) => { const [inviteperson, setProfile] = useState(INIT_invite); const [error, setError] = useState(""); const { roomId } = useParams(); - const invitepersonId = localStorage.getItem("user"); + const invitepersonId = sessionStorage.getItem("user"); async function getProfile(userID) { try { diff --git a/client/src/components/Login.js b/client/src/components/Login.js index 3d07a32..53f598c 100644 --- a/client/src/components/Login.js +++ b/client/src/components/Login.js @@ -46,7 +46,7 @@ const Login = () => { } if (success) { alert('로그인 되었습니다') - return ; + window.location.href=`/user/${id}` } const { email, password } = user diff --git a/client/src/components/Profile/Info.js b/client/src/components/Profile/Info.js index ed54fce..a89d3df 100644 --- a/client/src/components/Profile/Info.js +++ b/client/src/components/Profile/Info.js @@ -2,7 +2,7 @@ import userApi from "../../apis/user.api"; import { useEffect, useState } from "react"; import catchErrors from "../../context/catchError"; -const userprofile = localStorage.getItem("user"); +const userprofile = sessionStorage.getItem("user"); const INIT_PROFILE = { name: "", email: "a", diff --git a/client/src/components/Profile/InfoUpdate.js b/client/src/components/Profile/InfoUpdate.js index b063708..cebe222 100644 --- a/client/src/components/Profile/InfoUpdate.js +++ b/client/src/components/Profile/InfoUpdate.js @@ -3,7 +3,7 @@ import React, { useEffect, useState } from "react"; import userApi from "../../apis/user.api"; import catchErrors from "../../context/catchError"; -const userprofile = localStorage.getItem("user"); +const userprofile = sessionStorage.getItem("user"); const INIT_PROFILE = { id: userprofile, name:"", diff --git a/client/src/components/Profile/Profile.js b/client/src/components/Profile/Profile.js index 47cf831..eff76fc 100644 --- a/client/src/components/Profile/Profile.js +++ b/client/src/components/Profile/Profile.js @@ -3,7 +3,7 @@ import { useState, useEffect } from "react"; import userApi from "../../apis/user.api"; import catchErrors from "../../context/catchError"; -const userprofile = localStorage.getItem("user"); +const userprofile = sessionStorage.getItem("user"); const INIT_PROFILE = { img:"", }; diff --git a/client/src/components/Room/ChannelList.js b/client/src/components/Room/ChannelList.js index 5b57529..c7a4329 100644 --- a/client/src/components/Room/ChannelList.js +++ b/client/src/components/Room/ChannelList.js @@ -15,7 +15,7 @@ const ChannelList = () => { const { roomId } = useParams(); const [error, setError] = useState(""); const [channel, setChannel] = useState([INIT_CHANNEL]); - const id = localStorage.getItem('user'); + const id = sessionStorage.getItem('user'); async function getChannel(roomId) { try { diff --git a/client/src/components/Room/ChannelSingle.js b/client/src/components/Room/ChannelSingle.js index 79874dd..ae19267 100644 --- a/client/src/components/Room/ChannelSingle.js +++ b/client/src/components/Room/ChannelSingle.js @@ -9,7 +9,7 @@ const ChannelSingle = (props) => { const [success, setSuccess] = useState(false); const [roomName, setRoomName] = useState(''); const { roomId, channelId } = useParams(); - const userId = localStorage.getItem('user') + const userId = sessionStorage.getItem('user') async function joinChannel(e) { diff --git a/client/src/components/Room/RightHamburger.js b/client/src/components/Room/RightHamburger.js index 59bc76b..b98a6c6 100644 --- a/client/src/components/Room/RightHamburger.js +++ b/client/src/components/Room/RightHamburger.js @@ -5,6 +5,8 @@ import RoomApi from "../../apis/room.api"; import catchErrors from "../../context/catchError"; import KakaoShareButton from "../KakaoShareButton"; import Roomnamechange from "./Roomnamechange"; +import userApi from "../../apis/user.api"; +import roomApi from "../../apis/room.api"; const INIT_ROOM = { name: "", @@ -20,7 +22,7 @@ const RightHamburger = () => { const [room, setRoom] = useState([INIT_ROOM]); const { roomId } = useParams(); const [error, setError] = useState(""); - const id = localStorage.getItem("user"); + const id = sessionStorage.getItem("user"); async function getRoom(roomId) { try { @@ -30,7 +32,6 @@ const RightHamburger = () => { name: data[0].name, owner: data[0].owner, }); - console.log(roomdata); setRoom(roomdata); } catch (error) { catchErrors(error, setError); @@ -38,9 +39,12 @@ const RightHamburger = () => { } async function exitRoom() { - console.log("id, roomid정보", id, roomId); try { const data = await RoomApi.exitRoom({ id, roomId }); + if (data.owner === Number(id)){ + const room = await RoomApi.removeRoom({roomId : roomId}) + console.log(room) + } } catch (error) { catchErrors(error, setError); } @@ -65,6 +69,38 @@ const RightHamburger = () => { catchErrors(error, setError); } } + async function exitChannel() { + try { + const data = await userApi.getUser(id); + const A = doubleJoinCheck(data.name); + if (A) { + await roomApi.doubleJoin({ + roomId: roomId, + index1: A.index1, + index2: A.index2, + joinChName: A.joinChName, + }); + } + } catch (error) { + catchErrors(error, setError); + } + } + + function doubleJoinCheck(e) { + for (const index in channel) { + for (const el in channel[index].joinUser) { + if (channel[index].joinUser[el] === e) { + const doublejoinCh = channel[index].channelName; + const A = { + index1: index, + index2: el, + joinChName: doublejoinCh, + }; + return A; + } + } + } + } // console.log(channel) @@ -289,6 +325,7 @@ const RightHamburger = () => {