sdy

update onSubmit function

......@@ -4,21 +4,37 @@ import ChatPresenter from "./ChatPresenter";
import { withRouter } from "react-router-dom";
import { NEW_MESSAGE, SUBSCRIPTION_MSG } from "./ChatQueries";
import useInput from "../../Hooks/useInput";
import { toast } from "react-toastify";
export default withRouter(({ location }) => {
const [createMsg] = useMutation(NEW_MESSAGE);
const { data } = useSubscription(SUBSCRIPTION_MSG);
const message = useInput("");
let messageObj, outcomingMsg;
const onSubmit = async (e) => {
e.preventDefault();
if (message.value !== undefined || message.value !== "") {
try {
messageObj = await createMsg({
variables: {
message: message.value,
},
});
const { text } = messageObj;
outcomingMsg = text;
} catch {
toast.error("text must be not empty");
}
}
};
console.log(data);
console.log(createMsg);
return (
<ChatPresenter location={location} message={message} onSubmit={onSubmit} />
<ChatPresenter
location={location}
message={message}
onSubmit={onSubmit}
outcomingMsg={outcomingMsg}
/>
);
});
......