Commit 7d48edd7 authored by Choi Ga Young's avatar Choi Ga Young
Browse files

Merge remote-tracking branch 'origin/jiweon827' into young

parents d312cb31 6bcffb88
......@@ -9,9 +9,6 @@ import Menu from '../Components/Menu';
import catchErrors from '../utils/catchErrors';
import { io } from "socket.io-client"; //모듈 가져오기
import Chat from "../Components/Chat";
import { customAlphabet } from 'nanoid';
import { Redirect } from 'react-router-dom';
const socket = io();
const INIT_ROOM = {
......@@ -31,7 +28,7 @@ function Home() {
const [singleChat, setSingleChat] = useState('')
const [roomName, setRoomName] = useState('')
const [success, setSuccess] = useState(false)
// const [success, setSuccess] = useState(false)
const handleClose = () => setShow(false);
const handleShow = () => setShow(true);
......@@ -41,8 +38,6 @@ function Home() {
const handleShow2 = () => setShow2(true);
const moderator = sessionStorage.getItem('userId');
const nanoid = customAlphabet('1234567890abcdef', 10)
const roomId = nanoid()
useEffect(() => {
const isRoom = Object.values(room).every(el => Boolean(el))
......@@ -51,22 +46,22 @@ function Home() {
function handleChange(event) {
const { name, value } = event.target
setRoom({ ...room, [name]: value, moderator, roomId })
setRoom({ ...room, [name]: value, moderator })
//console.log(room)
}
console.log(room)
console.log(room.roomId)
async function handleSubmit(event) {
event.preventDefault()
try {
setError('')
await axios.post('/room/makeRoom', room)
// await axios.patch('/user/signup', { joinroom: `${room.roomId}`})
// await axios.post(`/user/${moderator}`, room.roomId)
setSuccess(true)
let res = await axios.post('/room/makeRoom', room)
console.log(res.data.roomId)
const Id = res.data.roomId
alert(`방암호는 ${Id}입니다`)
// setSuccess(true)
// setRoom(INIT_ROOM)
setShow(false)
} catch (error) {
......@@ -95,14 +90,7 @@ function Home() {
setSingleChat(msg)
})
}, [singleChat])
// console.log(room.roomId)
if (success) {
// console.log(room.roomId)
alert(`방암호는 ${room.roomId}입니다`)
// return <Redirect to='/home' />
}
return (
<>
<Menu />
......
import Room from "../models/Room.js"
// import { customAlphabet } from 'nanoid'
import { customAlphabet } from 'nanoid'
import isLength from 'validator/lib/isLength.js'
// const nanoid = customAlphabet('1234567890abcdef', 10)
const nanoid = customAlphabet('1234567890abcdef', 10)
const makeRoom = async (req, res) => {
console.log(req.body)
const { roomName, interest, isOpen, moderator, roomId } = req.body;
console.log(roomName, interest, isOpen, moderator, roomId)
const { roomName, interest, isOpen, moderator } = req.body;
console.log(roomName, interest, isOpen, moderator)
// const roomId = nanoid()
// const room = await Room.findOne({ roomId })
// while (room) {
// roomId = nanoid()
// room = await Room.findOne({ roomId })
// }
const roomId = nanoid()
const room = await Room.findOne({ roomId })
while (room) {
roomId = nanoid()
room = await Room.findOne({ roomId })
}
try {
if (!isLength(roomName, { min: 3, max: 20 })) {
......
......@@ -70,6 +70,5 @@ const loginNavbar = async (req, res) => {
}
}
export default { signup, logineduser, changenick, loginNavbar }
// {} : 객체로 return 함
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