Commit 4c6f4efe authored by Choi Ga Young's avatar Choi Ga Young
Browse files

parent bd853bc1
......@@ -14,11 +14,9 @@ const INIT_CHAT = {
}
function Chat(props) {
//const [sender, setSender] = useState([])
//const [roomName, setRoomName] = useState('')
const [inner, setInner] = useState([''])
const [chat, setChat] = useState([INIT_CHAT]) //object로 key는 보낸사람 value는 메세지
const [chat, setChat] = useState([INIT_CHAT])
const simpleTime = new Date().toLocaleTimeString()
const usualTime = simpleTime.substring(0, simpleTime.length - 3)
......@@ -63,7 +61,6 @@ function Chat(props) {
recordEntryLog() //그냥 새로고침해도 최신화
}
async function recordEntryLog() {
const leaveInfo = { userId: userId, roomCode: props.roomCode, leaveTime: realTime }
try {
......@@ -79,7 +76,6 @@ function Chat(props) {
}
function handleClick() {
props.closeChatRoom(props.roomCode)
props.setRecievedMsg('')
......
......@@ -62,8 +62,8 @@ function ClosedList(props) {
}, [props.unreadnumber])
return (
<div style={{height: "80vh"}}>
<div style={{overflow: 'auto', height:"100%"}}>
<div style={{ height: "80vh" }}>
<div style={{ overflow: 'auto', height: "100%" }}>
{props.closedlist.map((item, index) =>
<ListGroup key={index}>
<ListGroup.Item action onClick={enterChatRoomCH} name={item.roomId} value={item.roomName}
......
......@@ -14,7 +14,8 @@ function OpenList(props) {
}
return (
<div style={{overflow: 'auto', height: "80vh"}}>
<div style={{ height: "80vh" }}>
<div style={{ overflow: 'auto', height: "80vh" }}>
{props.openlist.map((item, index) =>
<ListGroup key={index}>
<ListGroup.Item action onClick={enterChatRoomCH} name={item.roomId} className='rounded-0'>
......@@ -23,6 +24,7 @@ function OpenList(props) {
</ListGroup>
)}
</div>
</div>
)
}
......
......@@ -34,7 +34,6 @@ function RoomMake(props) {
function handleChange(event) {
const { name, value } = event.target
setRoom({ ...room, [name]: value, member })
// console.log(room)
}
async function handleSubmit(event) {
......@@ -46,7 +45,6 @@ function RoomMake(props) {
alert(`방암호는 ${Id}입니다`)
props.handleCloseModal()
setRoom(INIT_ROOM)
// setRoomCode(Id)
recordEntryLog(Id)
} catch (error) {
catchErrors(error, setError)
......
......@@ -4,7 +4,7 @@ import styled from 'styled-components';
import ClosedList from '../Components/ClosedList';
import OpenList from '../Components/OpenList';
import Menu from '../Components/Menu';
import { io } from "socket.io-client"; //모듈 가져오기
import { io } from "socket.io-client";
import Chat from "../Components/Chat";
import RoomMake from "../Components/RoomMake"
import EnterRoom from "../Components/EnterRoom"
......@@ -85,8 +85,6 @@ function Home() {
socket.emit('newUser', { rmIf: rCode, userInfo: userName })
setShow(true)
console.log(`joinRoom : ${rCode} 입장`)
console.log('show:', show)
//여기서 채팅 불러와서 넘겨주던가 해야할거 같은데
console.log('HomePage/enterChatRoom 끝났습니다')
}
......@@ -107,7 +105,6 @@ function Home() {
async function getClosedList() {
const userid = sessionStorage.getItem('userId')
let res = await axios.get('/room/closedlist', { params: { '_id': userid } })
// console.log('getClosedList',res.data)
setClosedList(res.data)
}
......
......@@ -84,8 +84,6 @@ function ProfilePage() {
getProfile(userId)
}, [userId])
return (
<>
<Menu />
......
......@@ -17,6 +17,9 @@ ReactDOM.render(
<PrivateRoute exact path="/">
<HomePage />
</PrivateRoute>
<PrivateRoute path="/home">
<HomePage />
</PrivateRoute>
<Route path="/home" component={HomePage} />
<Route path="/login" component={LogInPage} />
<Route path="/signup" component={SignUpPage} />
......@@ -25,6 +28,7 @@ ReactDOM.render(
<ProfilePage />
</PrivateRoute>
</Switch>
</Router>,
document.getElementById('root')
......
import React, { useState } from 'react';
function randCode(){
// const [ranNumArr,setRanNumArr] = useState([]);
const min = 1;
const max = 99999;
let newNum = Math.floor((Math.random()*max)+min);
// for (let i=0;i<ranNumArr.length;i++){
// if (ranNumArr[i]==newNum){
// newNum = Math.floor((Math.random()*max)+min);
// }
// }
let zeroSize = "";
for (let j=0;j<5-newNum.toString().length;j++){
zeroSize += "0";
}
// setRanNumArr(zeroSize+newNum);
return (zeroSize+newNum.toString());
}
export default randCode;
\ No newline at end of file
......@@ -7,9 +7,7 @@ import EntryLog from "../models/EntryLog.js"
const nanoid = customAlphabet('1234567890abcdef', 10)
const makeRoom = async (req, res) => {
// console.log(req.body)
const { roomName, interest, isOpen, member } = req.body;
// console.log('콘솔확인', roomName, interest, isOpen, member)
const roomId = nanoid()
const room = await Room.findOne({ roomId })
while (room) {
......@@ -30,7 +28,6 @@ const makeRoom = async (req, res) => {
isOpen,
member,
}).save()
// console.log(newRoom)
res.json(newRoom)
} catch (error) {
console.log(error)
......@@ -58,11 +55,9 @@ const getOpenList = async (req, res) => {
const getRoomName = async (req, res) => {
const roomId = req.query.roomCode
// console.log('getRoomName', req.query.roomCode)
try {
let roominfo = await Room.findOne({ roomId: roomId }).select('roomName')
// console.log(roominfo.roomName)
return res.json(roominfo.roomName)
} catch (error) {
res.status(500).send('리스트 불러오기를 실패하였습니다!')
......@@ -71,14 +66,12 @@ const getRoomName = async (req, res) => {
const changemember = async (req, res) => {
const { userId, roomId } = req.body
// console.log(roomId)
let room = await Room.findOne({ roomId: roomId }).select('member')
const isPresent = room.member.indexOf(userId)
try {
if (isPresent < 0) {
const memberId = room.member.push(userId)
await Room.updateOne({ 'roomId': roomId }, { 'member': room.member })
// console.log('room.member 업데이트 완료')
return res.json(true)
}
else {
......@@ -90,15 +83,12 @@ const changemember = async (req, res) => {
}
const deleteUserId = async (req, res) => {
// console.log(req.body)
const { userId, roomId } = req.body
let room = await Room.findOne({ roomId: roomId }).select('member')
// console.log('deletetest', room)
const memIndex = room.member.indexOf(userId)
try {
room.member.splice(memIndex, 1)
await Room.updateOne({ 'roomId': roomId }, { 'member': room.member })
// console.log(`${roomId}방 ${userId}삭제완료`)
return res.json(true)
} catch (error) {
res.status(500).send('멤버 업데이트 실패')
......
......@@ -2,7 +2,6 @@ import express from 'express'
import userCtrl from '../controllers/user.controller.js'
const router = express.Router()
//router의 역할 : './주소'부분을 처리하는 역할함.
router.route('/users/signup')
.post(userCtrl.signup)
......
......@@ -23,21 +23,17 @@ io.on("connection", (socket) => { // 기본 연결
console.log("socket connect ok", socket.id)
socket.on('joinRoom', (data) => { // joinRoom을 클라이언트가 emit했을 때
// console.log('join_data확인', data)
let roomInfo = data;
socket.join(roomInfo); //클라이언트에서 data에 적힌 room으로 참여시킴
});
socket.on('closeRoom', (data) => {
// console.log('close_data확인', data)
let roomInfo = data;
socket.leave(roomInfo); //클라이언트에서 data에 적힌 room정보를 브로드캐스팅 받지 않는다.
});
socket.on('chat', async (data) => {
// console.log('roomname확인', data)
const room = await Room.findOne({ roomId: data.roomInfo })
// console.log('room이 떴나', room)
const chat = await new Chat({
room: room._id,
......@@ -45,7 +41,6 @@ io.on("connection", (socket) => { // 기본 연결
message: data.sendInfo.msg,
profileimg: data.sendInfo.img
}).save()
// console.log('resChat확인', chat)
socket.broadcast.to(data.roomInfo).emit('sendedMSG', data.sendInfo); // sender 제외 특정 방으로
socket.broadcast.emit('checking', data.sendInfo) // 메세지를 어딘가에서 보냈다는 신호
......@@ -70,4 +65,3 @@ server.listen(3030, () => {
})
export default server
\ No newline at end of file
// module.exports = server;
\ No newline at end of file
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