Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
students
messenger
Commits
fe18c505
Commit
fe18c505
authored
Jan 22, 2021
by
Soo Hyun Kim
Browse files
Merge remote-tracking branch 'origin/jiweon827' into sooModalTest
parents
441ffcb0
499397b7
Changes
7
Show whitespace changes
Inline
Side-by-side
client/src/Components/Menu.js
View file @
fe18c505
...
@@ -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
>
...
...
client/src/Components/OpenList.js
View file @
fe18c505
...
@@ -3,7 +3,7 @@ import { ListGroup } from 'react-bootstrap';
...
@@ -3,7 +3,7 @@ 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
();
...
@@ -14,17 +14,19 @@ function OpenList(props) {
...
@@ -14,17 +14,19 @@ function OpenList(props) {
setOpenlist
(
res
.
data
)
setOpenlist
(
res
.
data
)
}
}
async
function
enterChatRoomCH
(
e
)
{
function
enterChatRoomCH
(
e
)
{
const
roomId
=
e
.
target
.
name
const
roomCode
=
e
.
target
.
code
console
.
log
(
roomId
)
props
.
enterChatRoom
(
roomCode
)
// 각각의 room으로 들어가도록 설정해야 함
props
.
openListroom
(
roomId
)
// 각각의 room으로 들어가도록 설정해야 함
props
.
setRoomName
(
roomId
)
// props.clearChat()
}
}
return
(
return
(
<
div
>
<
div
>
{
openlist
.
map
((
item
,
index
)
=>
{
openlist
.
map
((
item
,
index
)
=>
<
ListGroup
key
=
{
index
}
>
<
ListGroup
key
=
{
index
}
>
<
ListGroup
.
Item
action
onClick
=
{
enterChatRoomCH
}
cod
e
=
{
item
.
roomId
}
>
<
ListGroup
.
Item
action
onClick
=
{
enterChatRoomCH
}
nam
e
=
{
item
.
roomId
}
>
{
item
.
roomName
}
{
item
.
roomName
}
<
/ListGroup.Item
>
<
/ListGroup.Item
>
<
/ListGroup
>
<
/ListGroup
>
...
...
client/src/Pages/HomePage.js
View file @
fe18c505
...
@@ -9,13 +9,24 @@ import { io } from "socket.io-client"; //모듈 가져오기
...
@@ -9,13 +9,24 @@ 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
[
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
(
''
)
...
@@ -31,17 +42,43 @@ function Home() {
...
@@ -31,17 +42,43 @@ function Home() {
const
handleCloseEnter
=
()
=>
setEnter
(
false
);
const
handleCloseEnter
=
()
=>
setEnter
(
false
);
const
handleShowEnter
=
()
=>
setEnter
(
true
);
const
handleShowEnter
=
()
=>
setEnter
(
true
);
const
handleChato
=
()
=>
setChat
(
true
);
const
handleChato
=
()
=>
setChat
(
true
);
const
handleChatc
=
()
=>
setChat
(
false
);
const
handleChatc
=
()
=>
setOpen
(
true
);
//SOCKET 관련 시작
//SOCKET 관련 시작
function
enterChatRoom
(
rCode
)
{
//방 입장하기
function
enterChatRoom
(
rCode
)
{
//방 입장하기
socket
.
emit
(
'
joinRoom
'
,
rCode
)
socket
.
emit
(
'
joinRoom
'
,
rCode
)
setRoomCode
(
rCode
)
console
.
log
(
`joinRoom :
${
rCode
}
입장`
)
console
.
log
(
`joinRoom :
${
rCode
}
입장`
)
}
}
//오픈채팅방에서 참가하기
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
()
}
}
...
@@ -79,17 +116,34 @@ function Home() {
...
@@ -79,17 +116,34 @@ function Home() {
<
/Tabs
>
<
/Tabs
>
<
/Col
>
<
/Col
>
<
Col
style
=
{{
padding
:
"
0
"
}}
>
<
Col
style
=
{{
padding
:
"
0
"
}}
>
{
chat
?
<
Chat
handleChatc
=
{
handleChatc
}
sendMsg
=
{
sendMsg
}
singleChat
=
{
singleChat
}
recievedMsg
=
{
recievedMsg
}
setSingleChat
=
{
setSingleChat
}
roomCode
=
{
roomCode
}
/> : null
}
{
show
?
<>
{
chat
?
<
div
style
=
{{
position
:
"
fixed
"
,
bottom
:
"
20px
"
,
right
:
"
30px
"
}}
>
<
Chat
handleChatc
=
{
handleChatc
}
sendMsg
=
{
sendMsg
}
singleChat
=
{
singleChat
}
recievedMsg
=
{
recievedMsg
}
setSingleChat
=
{
setSingleChat
}
roomName
=
{
roomName
}
/
>
<
Button
variant
=
"
primary
"
onClick
=
{
handleShowModal
}
size
=
"
lg
"
block
>
:
<
div
style
=
{{
position
:
"
fixed
"
,
bottom
:
"
20px
"
,
right
:
"
30px
"
}}
>
생성
<
Button
variant
=
"
primary
"
onClick
=
{
handleShowModal
}
size
=
"
lg
"
block
>
생성
<
/Button
>
<
/Button
>
<
Button
variant
=
"
secondary
"
onClick
=
{
handleShowEnter
}
size
=
"
lg
"
block
>
참가
<
/Button
>
<
/div>
}
<
Button
variant
=
"
secondary
"
onClick
=
{
handleShowEnter
}
size
=
"
lg
"
block
>
<
/> : <
>
참가
{
open
?
<
/Button
>
<
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>
:
<
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
}
handleChato
=
{
handleChato
}
/
>
<
RoomMake
showModal
=
{
showModal
}
handleCloseModal
=
{
handleCloseModal
}
handleChato
=
{
handleChato
}
/
>
...
...
server/controllers/room.controller.js
View file @
fe18c505
...
@@ -7,8 +7,8 @@ const nanoid = customAlphabet('1234567890abcdef', 10)
...
@@ -7,8 +7,8 @@ const nanoid = customAlphabet('1234567890abcdef', 10)
const
makeRoom
=
async
(
req
,
res
)
=>
{
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
)
//console.log('member저장', member)
const
roomId
=
nanoid
()
const
roomId
=
nanoid
()
const
room
=
await
Room
.
findOne
({
roomId
})
const
room
=
await
Room
.
findOne
({
roomId
})
while
(
room
)
{
while
(
room
)
{
...
@@ -48,6 +48,7 @@ const getClosedList = async (req, res) => {
...
@@ -48,6 +48,7 @@ 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
})
...
@@ -79,12 +80,27 @@ const changemember = async (req, res) => {
...
@@ -79,12 +80,27 @@ const changemember = async (req, res) => {
const
memberId
=
room
.
member
.
push
(
userId
)
const
memberId
=
room
.
member
.
push
(
userId
)
await
Room
.
updateOne
({
'
roomId
'
:
roomId
},
{
'
member
'
:
room
.
member
})
await
Room
.
updateOne
({
'
roomId
'
:
roomId
},
{
'
member
'
:
room
.
member
})
console
.
log
(
'
room.member 업데이트 완료
'
)
console
.
log
(
'
room.member 업데이트 완료
'
)
return
res
.
json
(
true
)
}
else
{
return
res
.
json
(
false
)
}
}
res
.
end
()
res
.
end
()
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
log
(
error
)
res
.
status
(
500
).
send
(
'
멤버 업데이트 실패
'
)
res
.
status
(
500
).
send
(
'
멤버 업데이트 실패
'
)
}
}
}
}
export
default
{
makeRoom
,
getClosedList
,
getOpenList
,
getRoomName
,
changemember
}
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
,
changemember
,
roomInf
}
server/controllers/user.controller.js
View file @
fe18c505
server/models/Room.js
View file @
fe18c505
...
@@ -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
,
...
...
server/routes/room.routers.js
View file @
fe18c505
...
@@ -6,6 +6,10 @@ const router = express.Router()
...
@@ -6,6 +6,10 @@ 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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment