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

0120참여코드로참가

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