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
9d342b6c
Commit
9d342b6c
authored
Jan 25, 2021
by
Choi Ga Young
Browse files
에러해결
parent
15336d57
Changes
3
Hide whitespace changes
Inline
Side-by-side
client/src/Components/Chat.js
View file @
9d342b6c
...
@@ -14,7 +14,7 @@ const INIT_CHAT = {
...
@@ -14,7 +14,7 @@ const INIT_CHAT = {
function
Chat
(
props
)
{
function
Chat
(
props
)
{
const
[
sender
,
setSender
]
=
useState
([])
const
[
sender
,
setSender
]
=
useState
([])
const
[
roomName
,
setRoomName
]
=
useState
(
''
)
//
const [roomName, setRoomName] = useState('')
const
[
inner
,
setInner
]
=
useState
([
''
])
const
[
inner
,
setInner
]
=
useState
([
''
])
const
[
chat
,
setChat
]
=
useState
([
INIT_CHAT
])
//object로 key는 보낸사람 value는 메세지
const
[
chat
,
setChat
]
=
useState
([
INIT_CHAT
])
//object로 key는 보낸사람 value는 메세지
...
@@ -43,7 +43,7 @@ function Chat(props) {
...
@@ -43,7 +43,7 @@ function Chat(props) {
e
.
preventDefault
()
e
.
preventDefault
()
setInner
(
e
.
target
.
value
)
setInner
(
e
.
target
.
value
)
setDisabled
(
false
)
setDisabled
(
false
)
console
.
log
(
chat
)
//
console.log(chat)
}
}
function
sendMsgCH
(
e
)
{
function
sendMsgCH
(
e
)
{
...
@@ -100,12 +100,12 @@ function Chat(props) {
...
@@ -100,12 +100,12 @@ function Chat(props) {
setChat
(
intochat
)
setChat
(
intochat
)
}
}
async
function
exitAndCloseRoom
(){
async
function
exitAndCloseRoom
()
{
props
.
exitRoom
(
props
.
roomCode
)
props
.
exitRoom
(
props
.
roomCode
)
setExit
(
false
)
setExit
(
false
)
props
.
handleChatc
()
props
.
handleChatc
()
}
}
useEffect
(()
=>
{
useEffect
(()
=>
{
getProfile
(
userId
)
getProfile
(
userId
)
...
@@ -120,7 +120,6 @@ function Chat(props) {
...
@@ -120,7 +120,6 @@ function Chat(props) {
},
[
props
.
recievedMsg
])
},
[
props
.
recievedMsg
])
useEffect
(()
=>
{
useEffect
(()
=>
{
getRoomName
(
props
.
roomCode
)
getPreviousChat
()
getPreviousChat
()
// console.log('겟 룸네임', chat)
// console.log('겟 룸네임', chat)
},
[
props
.
roomCode
])
},
[
props
.
roomCode
])
...
@@ -147,7 +146,6 @@ function Chat(props) {
...
@@ -147,7 +146,6 @@ function Chat(props) {
<
Col
md
=
"
auto
"
><
Button
variant
=
"
light
"
onClick
=
{
exitAndCloseRoom
}
>
{
"
나가기
"
}
<
/Button></
Col
>
<
Col
md
=
"
auto
"
><
Button
variant
=
"
light
"
onClick
=
{
exitAndCloseRoom
}
>
{
"
나가기
"
}
<
/Button></
Col
>
<
/Row
>
<
/Row
>
:
null
}
:
null
}
<
p
>
{
props
.
newUser
}
님이
입장하셨습니다
.
<
/p
>
{
chat
.
map
((
value
,
index
)
=>
{
{
chat
.
map
((
value
,
index
)
=>
{
if
(
!
(
value
.
msg
===
''
))
{
if
(
!
(
value
.
msg
===
''
))
{
if
(
!
(
value
.
sender
===
user
.
nickname
))
{
if
(
!
(
value
.
sender
===
user
.
nickname
))
{
...
@@ -188,7 +186,7 @@ function Chat(props) {
...
@@ -188,7 +186,7 @@ function Chat(props) {
<
/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%
'
,
position
:
'
fixed
'
}}
/
>
<
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
>
...
...
client/src/Components/ClosedList.js
View file @
9d342b6c
...
@@ -21,43 +21,43 @@ function ClosedList(props) {
...
@@ -21,43 +21,43 @@ function ClosedList(props) {
props
.
setRoomCode
(
roomCode
)
props
.
setRoomCode
(
roomCode
)
props
.
setRoomName
(
roomName
)
props
.
setRoomName
(
roomName
)
console
.
log
(
'
rrrrrrrrrrrrrrr
'
,
props
.
closedlist
)
//
console.log('rrrrrrrrrrrrrrr', props.closedlist)
console
.
log
(
'
1111111111111111111
'
,
props
.
leaveInfo
,
typeof
(
props
.
leaveInfo
))
//
console.log('1111111111111111111', props.leaveInfo, typeof (props.leaveInfo))
}
}
const
[
checknew
,
setChecknew
]
=
useState
([])
//
const [checknew, setChecknew] = useState([])
const
[
unreadnumber
,
setUnreadnumber
]
=
useState
([
''
])
//
const [unreadnumber, setUnreadnumber] = useState([''])
async
function
dbChat
()
{
//
async function dbChat() {
for
(
let
i
=
0
;
i
<=
props
.
closedlist
.
length
-
1
;
i
++
)
{
//
for (let i = 0; i <= props.closedlist.length - 1; i++) {
const
respond
=
await
axios
.
get
(
'
/room/dbChat
'
,
{
params
:
{
'
roomId
'
:
props
.
closedlist
[
i
].
roomId
}
})
//
const respond = await axios.get('/room/dbChat', { params: { 'roomId': props.closedlist[i].roomId } })
setChecknew
(
respond
.
data
)
//
setChecknew(respond.data)
}
//
}
}
//
}
useEffect
(()
=>
{
//
useEffect(() => {
dbChat
()
//
dbChat()
},
[
props
.
singleChat
,
props
.
recievedMsg
])
//
}, [props.singleChat, props.recievedMsg])
useEffect
(()
=>
{
//
useEffect(() => {
// console.log('chat 클라이언트 변경!')
//
// console.log('chat 클라이언트 변경!')
unreadMessage
()
//
unreadMessage()
},
[
checknew
])
//
}, [checknew])
async
function
unreadMessage
()
{
//
async function unreadMessage() {
//여기서 나간시간과 db의 메세지와 시간비교해서 개수를 count해주면 됨
//
//여기서 나간시간과 db의 메세지와 시간비교해서 개수를 count해주면 됨
//물론 그 방 별로 찾아서 list를 맵써서 하던?
//
//물론 그 방 별로 찾아서 list를 맵써서 하던?
// console.log('ddddddddd', list[0].roomId)
//
// console.log('ddddddddd', list[0].roomId)
setUnreadnumber
([
''
])
//
setUnreadnumber([''])
let
arr
=
[]
//
let arr = []
for
(
let
i
=
0
;
i
<=
props
.
closedlist
.
length
-
1
;
i
++
)
{
//
for (let i = 0; i <= props.closedlist.length - 1; i++) {
const
respond
=
await
axios
.
get
(
'
/room/unreadMessage
'
,
{
params
:
{
'
leaveInfo
'
:
props
.
leaveInfo
,
'
roomId
'
:
props
.
closedlist
[
i
].
roomId
}
})
//
const respond = await axios.get('/room/unreadMessage', { params: { 'leaveInfo': props.leaveInfo, 'roomId': props.closedlist[i].roomId } })
// setUnreadnumber([...unreadnumber, respond.data])
//
// setUnreadnumber([...unreadnumber, respond.data])
arr
=
[...
arr
,
respond
.
data
]
//
arr = [...arr, respond.data]
}
//
}
setUnreadnumber
(
arr
)
//
setUnreadnumber(arr)
// console.log('클라이언트 클로즈드 카운드', unreadnumber, list.length)
//
// console.log('클라이언트 클로즈드 카운드', unreadnumber, list.length)
}
//
}
return
(
return
(
<
div
>
<
div
>
...
@@ -65,7 +65,7 @@ function ClosedList(props) {
...
@@ -65,7 +65,7 @@ function ClosedList(props) {
<
ListGroup
key
=
{
index
}
>
<
ListGroup
key
=
{
index
}
>
<
ListGroup
.
Item
action
onClick
=
{
enterChatRoomCH
}
name
=
{
item
.
roomId
}
value
=
{
item
.
roomName
}
>
<
ListGroup
.
Item
action
onClick
=
{
enterChatRoomCH
}
name
=
{
item
.
roomId
}
value
=
{
item
.
roomName
}
>
{
item
.
roomName
}
{
item
.
roomName
}
{
unreadnumber
[
index
]
?
<
Badge
className
=
'
ml-2
'
pill
variant
=
'
danger
'
>
{
unreadnumber
[
index
]}
<
/Badge> : ''
}
{
/* {
[index] ? <Badge className='ml-2' pill variant='danger'>{unreadnumber[index]}</Badge> : ''}
*/
}
<
/ListGroup.Item
>
<
/ListGroup.Item
>
<
/ListGroup
>
<
/ListGroup
>
)
)
...
...
server/server.js
View file @
9d342b6c
...
@@ -10,7 +10,6 @@ import { Server } from 'socket.io';
...
@@ -10,7 +10,6 @@ import { Server } from 'socket.io';
import
cors
from
"
cors
"
import
cors
from
"
cors
"
import
Room
from
'
./models/Room.js
'
import
Room
from
'
./models/Room.js
'
import
Chat
from
"
./models/Chat.js
"
import
Chat
from
"
./models/Chat.js
"
import
User
from
"
./models/User.js
"
connectDb
()
connectDb
()
...
...
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