Showing
1 changed file
with
23 additions
and
12 deletions
... | @@ -2,30 +2,40 @@ import React from "react"; | ... | @@ -2,30 +2,40 @@ import React from "react"; |
2 | import { useMutation, useQuery } from "@apollo/react-hooks"; | 2 | import { useMutation, useQuery } from "@apollo/react-hooks"; |
3 | import ChatPresenter from "./ChatPresenter"; | 3 | import ChatPresenter from "./ChatPresenter"; |
4 | import { withRouter } from "react-router-dom"; | 4 | import { withRouter } from "react-router-dom"; |
5 | -import { CREATE_MESSAGE, GET_ROOM_BY_NAME } from "./ChatQueries"; | 5 | +import { |
6 | + CREATE_MESSAGE, | ||
7 | + GET_ROOM_BY_NAME, | ||
8 | + SEE_ALL_MESSAGE, | ||
9 | +} from "./ChatQueries"; | ||
6 | import useInput from "../../Hooks/useInput"; | 10 | import useInput from "../../Hooks/useInput"; |
7 | import { toast } from "react-toastify"; | 11 | import { toast } from "react-toastify"; |
8 | 12 | ||
9 | export default withRouter(({ location }) => { | 13 | export default withRouter(({ location }) => { |
10 | const { pathname } = location; | 14 | const { pathname } = location; |
11 | const roomName = pathname.slice(1, pathname.length); | 15 | const roomName = pathname.slice(1, pathname.length); |
16 | + const [createMsg] = useMutation(CREATE_MESSAGE); | ||
17 | + //const { data } = useSubscription(SUBSCRIPTION_MSG); | ||
18 | + | ||
19 | + const message = useInput(""); | ||
12 | 20 | ||
13 | - let messageObj, roomNum, messageText, messageTime, newMsgObj; | 21 | + let messageObj, roomNum, messageText, messageTime, newMsgObj, messageArray; |
14 | 22 | ||
15 | - if (roomName !== undefined) { | 23 | + const { data: getRoom } = useQuery(GET_ROOM_BY_NAME, { |
16 | - const { data } = useQuery(GET_ROOM_BY_NAME, { variables: { roomName } }); | 24 | + variables: { roomName }, |
17 | - if (data !== undefined) { | 25 | + }); |
26 | + if (getRoom !== undefined) { | ||
18 | const { | 27 | const { |
19 | getRoomByName: { id: roomId }, | 28 | getRoomByName: { id: roomId }, |
20 | - } = data; | 29 | + } = getRoom; |
21 | roomNum = Number(roomId); | 30 | roomNum = Number(roomId); |
22 | } | 31 | } |
23 | - } | ||
24 | 32 | ||
25 | - const [createMsg] = useMutation(CREATE_MESSAGE); | 33 | + const { data: messageList } = useQuery(SEE_ALL_MESSAGE, { |
26 | - //const { data } = useSubscription(SUBSCRIPTION_MSG); | 34 | + variables: { roomId: roomNum }, |
27 | - | 35 | + }); |
28 | - const message = useInput(""); | 36 | + if (messageList !== undefined) { |
37 | + messageArray = messageList; | ||
38 | + } | ||
29 | 39 | ||
30 | const onSubmit = async (e) => { | 40 | const onSubmit = async (e) => { |
31 | e.preventDefault(); | 41 | e.preventDefault(); |
... | @@ -61,7 +71,8 @@ export default withRouter(({ location }) => { | ... | @@ -61,7 +71,8 @@ export default withRouter(({ location }) => { |
61 | onSubmit={onSubmit} | 71 | onSubmit={onSubmit} |
62 | messageText={messageText} | 72 | messageText={messageText} |
63 | messageTime={messageTime} | 73 | messageTime={messageTime} |
64 | - newMsgObj={sendingMsgObj} | 74 | + newMsgObj={newMsgObj} |
75 | + messageArray={messageArray} | ||
65 | /> | 76 | /> |
66 | ); | 77 | ); |
67 | }); | 78 | }); | ... | ... |
-
Please register or login to post a comment