Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2020-1-capstone-design1
/
Triz_Project1
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
1
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
sdy
2020-05-25 00:35:19 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
5791f7eb495c4115580d3f359521f80f496761ef
5791f7eb
1 parent
6c768bf2
add queries, variables
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
4 deletions
front/src/Routes/Chat/ChatContainer.js
front/src/Routes/Chat/ChatContainer.js
View file @
5791f7e
import
React
from
"react"
;
import
{
useSubscription
,
useMutation
}
from
"@apollo/react-hooks"
;
import
{
useSubscription
,
useMutation
,
useQuery
}
from
"@apollo/react-hooks"
;
import
ChatPresenter
from
"./ChatPresenter"
;
import
{
withRouter
}
from
"react-router-dom"
;
import
{
NEW_MESSAGE
,
SUBSCRIPTION_MSG
}
from
"./ChatQueries"
;
import
{
SUBSCRIPTION_MSG
,
WHOLE_MESSAGE
,
GET_ROOM_BY_NAME
,
}
from
"./ChatQueries"
;
import
useInput
from
"../../Hooks/useInput"
;
import
{
toast
}
from
"react-toastify"
;
import
getRoomByName
from
"../../../../back/src/api/Room/getRoomByName/getRoomByName"
;
export
default
withRouter
(({
location
})
=>
{
const
[
createMsg
]
=
useMutation
(
NEW_MESSAGE
);
const
{
pathname
}
=
location
;
const
roomName
=
pathname
.
slice
(
1
,
pathname
.
length
);
let
messageObj
,
outcomingMsg
,
roomId
;
if
(
roomName
!==
undefined
)
{
const
{
data
:
{
getRoomByName
},
}
=
useQuery
(
GET_ROOM_BY_NAME
,
{
variables
:
{
roomName
}
});
roomId
=
getRoomByName
.
id
;
}
const
[
createMsg
]
=
useMutation
(
WHOLE_MESSAGE
);
const
{
data
}
=
useSubscription
(
SUBSCRIPTION_MSG
);
const
message
=
useInput
(
""
);
let
messageObj
,
outcomingMsg
;
const
onSubmit
=
async
(
e
)
=>
{
e
.
preventDefault
();
...
...
@@ -20,10 +36,12 @@ export default withRouter(({ location }) => {
messageObj
=
await
createMsg
({
variables
:
{
message
:
message
.
value
,
roomId
,
},
});
const
{
text
}
=
messageObj
;
outcomingMsg
=
text
;
console
.
log
(
messageObj
);
}
catch
{
toast
.
error
(
"text must be not empty"
);
}
...
...
Please
register
or
login
to post a comment