Commit 12508c84 authored by Choi Ga Young's avatar Choi Ga Young
Browse files

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

parents 54789675 0bfa56e9
...@@ -9,6 +9,7 @@ function Chat(props) { ...@@ -9,6 +9,7 @@ function Chat(props) {
const [sender, setSender] = useState([]) const [sender, setSender] = useState([])
const [roomName, setRoomName] = useState('')
const [inner, setInner] = useState(['']) const [inner, setInner] = useState([''])
const [chat, setChat] = useState([]) //object로 key는 보낸사람 value는 메세지 const [chat, setChat] = useState([]) //object로 key는 보낸사람 value는 메세지
...@@ -17,7 +18,7 @@ function Chat(props) { ...@@ -17,7 +18,7 @@ function Chat(props) {
const [disabled, setDisabled] = useState(true) const [disabled, setDisabled] = useState(true)
const [user, setUser] = useState('') const [user, setUser] = useState('')
const [error, setError] = useState(''); const [error, setError] = useState('');
const userId = isAuthenticated() const userId = isAuthenticated()
async function getProfile(userId) { async function getProfile(userId) {
...@@ -29,6 +30,16 @@ function Chat(props) { ...@@ -29,6 +30,16 @@ function Chat(props) {
} }
} }
async function getRoomName(roomCode) {
try {
let res = await axios.get('/room/getRoomName', { params: { 'roomCode': roomCode } })
console.log(res.data)
setRoomName(res.data)
} catch (error) {
catchErrors(error, setError)
}
}
function handleChange(e) { function handleChange(e) {
e.preventDefault() e.preventDefault()
setInner(e.target.value) setInner(e.target.value)
...@@ -68,11 +79,23 @@ function Chat(props) { ...@@ -68,11 +79,23 @@ function Chat(props) {
setChat([...chat, props.recievedMsg]) setChat([...chat, props.recievedMsg])
}, [props.recievedMsg]) }, [props.recievedMsg])
useEffect(() => {
getRoomName(props.roomCode)
}, [props.roomCode])
const time = new Date().toLocaleTimeString() const time = new Date().toLocaleTimeString()
return ( return (
<> <>
<Container id="chat" style={{ overflow: 'auto', padding: '20px', border: "2px solid", height: "500px", margin: "1%", borderColor: "#BDBDBD", background: '' }}> <Container id="chat" style={{ overflow: 'auto', padding: '20px', border: "2px solid", height: "500px", margin: "1%", borderColor: "#BDBDBD", background: '' }}>
<h2>해당 방에 대한 참여코드는 {props.roomCode} 입니다.</h2> <Row class="d-flex justify-content-center" style={{ border: "2px solid", borderWidth: "medium", borderColor: "#FFD75F", height: "80px", margin: "1%" }}>
<Col md="auto">
<Button variant="light" onClick={props.handleChatc} >{`<`}</Button>
</Col>
<Col>
<Row style={{ fontWeight: "bold", fontSize: "x-large" }}> {roomName} </Row>
<Row > {props.roomCode} </Row>
</Col>
</Row>
<p>{props.newUser}님이 입장하셨습니다.</p> <p>{props.newUser}님이 입장하셨습니다.</p>
{chat.map((value, index) => { {chat.map((value, index) => {
if (!(value == '')) { if (!(value == '')) {
...@@ -110,14 +133,14 @@ function Chat(props) { ...@@ -110,14 +133,14 @@ function Chat(props) {
<Button variant="light" onClick={handleClick} >{`<`}</Button> <Button variant="light" onClick={handleClick} >{`<`}</Button>
</Container > </Container >
<Form onSubmit={sendMsgCH} fluid> <Form onSubmit={sendMsgCH} fluid>
<Form.Group className='d-flex flex-wrap-nowrap justify-content-center m-3'> <Form.Group className='d-flex flex-wrap-nowrap justify-content-center m-3'>
<Form.Control className='border border-warning' name='chat' type="text" value={inner} onChange={handleChange} style={{ width: '85%' }} /> <Form.Control className='border border-warning' name='chat' type="text" value={inner} onChange={handleChange} style={{ width: '85%' }} />
<Button variant="warning" type="submit" disabled={disabled} style={{ width: '10%' }}> <Button variant="warning" type="submit" disabled={disabled} style={{ width: '10%' }}>
전송 전송
</Button> </Button>
</Form.Group> </Form.Group>
</Form> </Form>
</> </>
......
...@@ -8,7 +8,7 @@ function ClosedList(props) { ...@@ -8,7 +8,7 @@ function ClosedList(props) {
useEffect(() => { useEffect(() => {
getClosedList(); getClosedList();
}, []); }, [props.roomCode]);
async function getClosedList() { async function getClosedList() {
const userid = sessionStorage.getItem('userId') const userid = sessionStorage.getItem('userId')
...@@ -18,16 +18,16 @@ function ClosedList(props) { ...@@ -18,16 +18,16 @@ function ClosedList(props) {
function enterChatRoomCH(e) { function enterChatRoomCH(e) {
const roomCode = e.target.name const roomCode = e.target.name
const roomName = e.target.value
props.enterChatRoom(roomCode) props.enterChatRoom(roomCode)
props.setRoomCode(roomCode) props.setRoomCode(roomCode)
} }
return ( return (
<div> <div>
{list.map((item, index) => {list.map((item, index) =>
<ListGroup key={index}> <ListGroup key={index}>
<ListGroup.Item action onClick={enterChatRoomCH} name={item.roomId}> <ListGroup.Item action onClick={enterChatRoomCH} name={item.roomId} value={item.roomName}>
{item.roomName} {item.roomName}
</ListGroup.Item> </ListGroup.Item>
</ListGroup> </ListGroup>
......
...@@ -7,6 +7,9 @@ import catchErrors from '../utils/catchErrors' ...@@ -7,6 +7,9 @@ import catchErrors from '../utils/catchErrors'
function EnterRoom(props) { function EnterRoom(props) {
const [enterCode, setEnterCode] = useState(''); const [enterCode, setEnterCode] = useState('');
const [error, setError] = useState(''); const [error, setError] = useState('');
const userId = sessionStorage.getItem('userId'); //sessionStorage에 저장된 userId가져옴
function handleChange(event) { function handleChange(event) {
const { name, value } = event.target const { name, value } = event.target
...@@ -19,6 +22,7 @@ function EnterRoom(props) { ...@@ -19,6 +22,7 @@ function EnterRoom(props) {
try { try {
setError('') setError('')
let res = await axios.post('/room/enterRoom', { enterCode }) let res = await axios.post('/room/enterRoom', { enterCode })
await axios.put('/room/member', { userId: userId, roomId: enterCode })
props.setRoomName(res.data) props.setRoomName(res.data)
props.enterChatRoom(enterCode) props.enterChatRoom(enterCode)
props.handleCloseEnter() props.handleCloseEnter()
......
...@@ -16,7 +16,7 @@ function Menu() { ...@@ -16,7 +16,7 @@ function Menu() {
<Nav className="mr-auto"> <Nav className="mr-auto">
<Nav.Link href="/profile">Profile</Nav.Link> <Nav.Link href="/profile">Profile</Nav.Link>
</Nav> </Nav>
<Button className="ml-auto" onClick={() => handleLogout()} variant="light" className="ml-3">Logout</Button> <Button className="ml-auto" onClick={() => handleLogout()} variant="light">Logout</Button>
</> </>
: <Nav className="ml-auto"> : <Nav className="ml-auto">
<Nav.Link href='/login'>로그인</Nav.Link> <Nav.Link href='/login'>로그인</Nav.Link>
......
...@@ -3,11 +3,11 @@ import { ListGroup } from 'react-bootstrap'; ...@@ -3,11 +3,11 @@ import { ListGroup } from 'react-bootstrap';
import axios from 'axios' import axios from 'axios'
function OpenList(props) { function OpenList(props) {
const [openlist, setOpenlist] = useState([]); const [openlist, setOpenlist] = useState([])
useEffect(() => { useEffect(() => {
getOpenList(); getOpenList();
}, []); }, [props.roomCode]);
async function getOpenList() { async function getOpenList() {
let res = await axios.get('/room/openlist') let res = await axios.get('/room/openlist')
......
...@@ -34,6 +34,7 @@ function RoomMake(props) { ...@@ -34,6 +34,7 @@ function RoomMake(props) {
const Id = res.data.roomId const Id = res.data.roomId
alert(`방암호는 ${Id}입니다`) alert(`방암호는 ${Id}입니다`)
props.handleCloseModal() props.handleCloseModal()
props.handleChato()
setRoom(INIT_ROOM) setRoom(INIT_ROOM)
} catch (error){ } catch (error){
catchErrors(error, setError) catchErrors(error, setError)
......
...@@ -9,15 +9,26 @@ import { io } from "socket.io-client"; //모듈 가져오기 ...@@ -9,15 +9,26 @@ import { io } from "socket.io-client"; //모듈 가져오기
import Chat from "../Components/Chat"; import Chat from "../Components/Chat";
import RoomMake from "../Components/RoomMake" import RoomMake from "../Components/RoomMake"
import EnterRoom from "../Components/EnterRoom" import EnterRoom from "../Components/EnterRoom"
import axios from 'axios';
const socket = io(); const socket = io();
const INIT_ROOM = {
roomName: '',
interest: '',
roomId: '',
member: '',
}
function Home() { function Home() {
const userName = sessionStorage.getItem('name') const userName = sessionStorage.getItem('name')
const [showModal, setShowModal] = useState(false); const [showModal, setShowModal] = useState(false);
const [showEnter, setEnter] = useState(false); const [showEnter, setEnter] = useState(false);
const [chat, setChat] = useState(false); const [chat, setChat] = useState(false);
const [open, setOpen] = useState(false);
const [room, setRoom] = useState(INIT_ROOM)
const [show, setShow] = useState(true)
//소켓 //소켓
const [singleChat, setSingleChat] = useState('') const [singleChat, setSingleChat] = useState('')
...@@ -51,6 +62,31 @@ function Home() { ...@@ -51,6 +62,31 @@ function Home() {
setNewUser(data) setNewUser(data)
}) })
//오픈채팅방에서 참가하기
async function openListroom(roomId) {
console.log(roomId)
const roomInf = await axios.get('/room/changeMem', { params: { 'roomId': roomId } })
console.log(roomInf)
console.log(roomInf.data)
console.log(roomInf.data[0])
setRoom(roomInf.data[0])
setShow(false)
}
async function attendListRoom() {
const userId = sessionStorage.getItem('userId'); //sessionStorage에 저장된 userId가져옴
const roomId = room.roomId
const tf = await axios.put('/room/changeMem', { userId: userId, roomId: roomId })
if (tf.data) {
alert('참가되었습니다.')
} else {
alert('이미 참가된 방입니다.')
}
}
function enterButton() {
setOpen(false)
}
const sendMsg = (e) => { const sendMsg = (e) => {
e.preventDefault() e.preventDefault()
} }
...@@ -86,28 +122,46 @@ function Home() { ...@@ -86,28 +122,46 @@ function Home() {
<Col className="list" md={5}> <Col className="list" md={5}>
<Tabs defaultActiveKey="closed" id="uncontrolled-tab-example"> <Tabs defaultActiveKey="closed" id="uncontrolled-tab-example">
<Tab eventKey="closed" title="내 채팅" onClick={handleChato} > <Tab eventKey="closed" title="내 채팅" onClick={handleChato} >
<ClosedList enterChatRoom={enterChatRoom} setRoomCode={setRoomCode} /> <ClosedList enterChatRoom={enterChatRoom} setRoomCode={setRoomCode} setRoomName={setRoomName} roomCode={roomCode} />
</Tab> </Tab>
<Tab eventKey="open" title="공개방" onClick={handleChato}> <Tab eventKey="open" title="공개방" onClick={handleChato}>
<OpenList enterChatRoom={enterChatRoom} setRoomCode={setRoomCode} /> <OpenList enterChatRoom={enterChatRoom} setRoomCode={setRoomCode} setRoomName={setRoomName} roomCode={roomCode} />
</Tab> </Tab>
</Tabs> </Tabs>
</Col> </Col>
<Col style={{ padding: "0" }}> <Col style={{ padding: "0" }}>
{show ? <>
{chat ? <Chat handleChatc={handleChatc} sendMsg={sendMsg} singleChat={singleChat} recievedMsg={recievedMsg} newUser={newUser} setSingleChat={setSingleChat} roomCode={roomCode} singleImg={singleImg} setSingleImg={setSingleImg} recievedImg={recievedImg} singleUser={singleUser} setSingleUser={setSingleUser} recievedUser={recievedUser} /> : <div style={{ position: "fixed", bottom: "20px", right: "30px" }}> {chat ?
<Button variant="primary" onClick={handleShowModal} size="lg" block> <Chat handleChatc={handleChatc} sendMsg={sendMsg} singleChat={singleChat} recievedMsg={recievedMsg} newUser={newUser} setSingleChat={setSingleChat} roomCode={roomCode} singleImg={singleImg} setSingleImg={setSingleImg} recievedImg={recievedImg} singleUser={singleUser} setSingleUser={setSingleUser} recievedUser={recievedUser} />
생성 : <div style={{ position: "fixed", bottom: "20px", right: "30px" }}>
</Button> <Button variant="primary" onClick={handleShowModal} size="lg" block>생성</Button>
<Button variant="secondary" onClick={handleShowEnter} size="lg" block>참가</Button>
<Button variant="secondary" onClick={handleShowEnter} size="lg" block> </div>}
참가 </> : <>
</Button> {open ?
</div>} <div className="vh-90 flex-column align-items-center justify-content-center mt-2" variant="dark">
<div className="d-flex justify-content-center">
<div className="mt-5 p-5 shadow w-75">
<h2 className="d-flex justify-content-center mb-3">현재 {room.roomName} 입니다.</h2>
<h5> 관심분야 : {room.interest}</h5>
<h5> 참여인원 : {room.member.length}</h5>
<h5 className="mb-3"> 방코드(방코드를 통해서도 참여할 있습니다.) : {room.roomId}</h5>
<Row className='justify-content-center'>
<Button variant="outline-warning" size="sm" className="mr-4" onClick={enterButton}>뒤로가기</Button>
<Button variant="outline-warning" size="sm" className="ml-4" type='submit' onClick={attendListRoom}>참가</Button>
</Row>
</div>
</div>
</div> :
<div style={{ position: "fixed", bottom: "20px", right: "30px" }}>
<Button variant="primary" onClick={handleShowModal} size="lg" block>생성</Button>
<Button variant="secondary" onClick={handleShowEnter} size="lg" block>참가</Button>
</div>}
</>}
</Col> </Col>
</Row> </Row>
<RoomMake showModal={showModal} handleCloseModal={handleCloseModal} /> <RoomMake showModal={showModal} handleCloseModal={handleCloseModal} />
<EnterRoom showEnter={showEnter} enterChatRoom={enterChatRoom} handleCloseEnter={handleCloseEnter} handleChato={handleChato} setRoomName={setRoomName} /> <EnterRoom showEnter={showEnter} enterChatRoom={enterChatRoom} handleCloseEnter={handleCloseEnter} handleChato={handleChato} setRoomCode={setRoomCode} setRoomName={setRoomName} />
</> </>
); );
} }
......
...@@ -8,7 +8,6 @@ const makeRoom = async (req, res) => { ...@@ -8,7 +8,6 @@ const makeRoom = async (req, res) => {
console.log(req.body) console.log(req.body)
const { roomName, interest, isOpen, member } = req.body; const { roomName, interest, isOpen, member } = req.body;
console.log('콘솔확인', roomName, interest, isOpen, member) console.log('콘솔확인', roomName, interest, isOpen, member)
const roomId = nanoid() const roomId = nanoid()
const room = await Room.findOne({ roomId }) const room = await Room.findOne({ roomId })
while (room) { while (room) {
...@@ -51,11 +50,57 @@ const getClosedList = async (req, res) => { ...@@ -51,11 +50,57 @@ const getClosedList = async (req, res) => {
const getOpenList = async (req, res) => { const getOpenList = async (req, res) => {
try { try {
let list = await Room.find({ isOpen: true }) let list = await Room.find({ isOpen: true })
console.log('o_list가져오기', list) console.log('o_list가져오기', list.roomName)
return res.json(list) return res.json(list)
} catch (error) { } catch (error) {
res.status(500).send('리스트 불러오기를 실패하였습니다!') res.status(500).send('리스트 불러오기를 실패하였습니다!')
} }
} }
export default { makeRoom, getClosedList, getOpenList } const getRoomName = async (req, res) => {
const roomId = req.query.roomCode
console.log(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('리스트 불러오기를 실패하였습니다!')
}
}
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 {
return res.json(false)
}
res.end()
} catch (error) {
res.status(500).send('멤버 업데이트 실패')
}
}
const roomInf = async (req, res) => {
try {
console.log(req.query.roomId)
// let roomInf = await Room.findOne({ member: req.query.roomId }).select('interest roomId member').exec()
let roomInf = await Room.find({ roomId: req.query.roomId })
console.log('room_member로 정보 가져오기:', roomInf)
return res.json(roomInf)
} catch (error) {
alert('올바르지 못한 접근입니다.')
}
}
export default { makeRoom, getClosedList, getOpenList, getRoomName, changemember, roomInf }
...@@ -5,7 +5,6 @@ const roomEnter = async (req, res) => { ...@@ -5,7 +5,6 @@ const roomEnter = async (req, res) => {
// console.log(req) // 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(`참여코드가 존재하지 않습니다.`)
......
...@@ -13,7 +13,7 @@ const profileUpload = upload.fields([ ...@@ -13,7 +13,7 @@ const profileUpload = upload.fields([
const signup = async (req, res) => { const signup = async (req, res) => {
const { username, nickname, email, password } = req.body const { username, nickname, email, password } = req.body
try { try {
if (!isLength(username, { min: 3, max: 10 })) { if (!isLength(username, { min: 3, max: 10 })) {
return res.status(422).send('이름은 3-10자 사이입니다') return res.status(422).send('이름은 3-10자 사이입니다')
......
...@@ -16,7 +16,7 @@ const RoomSchema = new mongoose.Schema({ ...@@ -16,7 +16,7 @@ const RoomSchema = new mongoose.Schema({
interest: { interest: {
type: String, type: String,
required: true, required: true,
select: false // select: false
}, },
isOpen: { isOpen: {
type: Boolean, type: Boolean,
......
...@@ -6,11 +6,19 @@ const router = express.Router() ...@@ -6,11 +6,19 @@ const router = express.Router()
router.route('/room/makeRoom') router.route('/room/makeRoom')
.post(roomCtrl.makeRoom) .post(roomCtrl.makeRoom)
router.route('/room/changeMem')
.put(roomCtrl.changemember)
.get(roomCtrl.roomInf)
router.route('/room/closedlist') router.route('/room/closedlist')
.get(roomCtrl.getClosedList) .get(roomCtrl.getClosedList)
router.route('/room/openlist') router.route('/room/openlist')
.get(roomCtrl.getOpenList) .get(roomCtrl.getOpenList)
router.route('/room/member')
.put(roomCtrl.changemember)
router.route('/room/getRoomName')
.get(roomCtrl.getRoomName)
export default router export default router
\ 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