Commit a176c47f authored by Soo Hyun Kim's avatar Soo Hyun Kim
Browse files

0120참여코드로참가

parent 0a02c1c5
......@@ -6,12 +6,11 @@ function Chat(props) {
let defaultname = sessionStorage.getItem('name');
const [inner, setInner] = useState([''])
const [chat, setChat] = useState([inner]) //object로 key는 보낸사람 value는 메세지
const [chat, setChat] = useState([]) //object로 key는 보낸사람 value는 메세지
function handleChange(e) {
e.preventDefault()
setInner(e.target.value)
console.log(e.target.value)
}
function sendMsgCH(e) {
......
......@@ -24,7 +24,7 @@ function ClosedList(props) {
console.log(e.target.name)
console.log(e.target)
const roomName = e.target.name
props.enterChatroom(roomName) // 각각의 room으로 들어가도록 설정해야 함
props.enterChatRoom(roomName) // 각각의 room으로 들어가도록 설정해야 함
props.setRoomName(roomName)
}
......
......@@ -18,8 +18,11 @@ function EnterRoom(props) {
event.preventDefault()
try {
setError('')
await axios.post('/room/enterRoom', enterCode)
let res = await axios.post('/room/enterRoom', { enterCode })
props.setRoomName(res.data)
props.enterChatRoom(enterCode)
props.handleCloseEnter()
props.handleChato()
setEnterCode('')
} catch (error){
catchErrors(error, setError)
......
......@@ -18,7 +18,7 @@ function OpenList(props) {
function enterChatRoomCH(e) {
const roomName = e.target.name
props.enterChatroom(roomName) // 각각의 room으로 들어가도록 설정해야 함
props.enterChatRoom(roomName) // 각각의 room으로 들어가도록 설정해야 함
props.setRoomName(roomName)
// props.clearChat()
}
......
......@@ -23,9 +23,6 @@ function Home() {
const [roomName, setRoomName] = useState('')
const [roomCode, setRoomCode] = useState('')
//방참가
const [roomId, setRoomId] = useState('')
const handleCloseModal = () => setShowModal(false);
const handleShowModal = () => setShowModal(true);
const handleCloseEnter = () => setEnter(false);
......@@ -36,7 +33,7 @@ function Home() {
//SOCKET 관련 시작
function enterChatroom(rName) { //방 입장하기
function enterChatRoom(rName) { //방 입장하기
socket.emit('joinRoom', rName)
console.log(`joinRoom : ${rName} 입장`)
}
......@@ -92,7 +89,7 @@ function Home() {
</Col>
</Row>
<RoomMake showModal={showModal} handleCloseModal={handleCloseModal} />
<EnterRoom showEnter={showEnter} enterChatRoom={enterChatroom} handleCloseEnter={handleCloseEnter} />
<EnterRoom showEnter={showEnter} enterChatRoom={enterChatRoom} handleCloseEnter={handleCloseEnter} handleChato={handleChato} setRoomName={setRoomName}/>
</>
);
}
......
import Room from "../models/Room.js"
const roomEnter = async (req, res) => {
const roomId = req.body
const roomId = req.body.enterCode
// console.log(req)
try {
console.log(roomId)
const room = await Room.findOne({ roomId })
if (!room) {
return res.status(404).send(`참여코드가 존재하지 않습니다.`)
}
// room.member =
console.log('roomId존재')
const name = await Room.findOne({ roomId: roomId }).select('roomName')
return res.json(name.roomName)
} catch (error) {
//알수없는 모든 에러발생시 처리
console.log(error)
res.status(500).send('로그인 에러가 발생하였습니다')
res.status(500).send('방 참여 에러')
}
}
export default { roomEnter }
\ 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