sdy

move useQuery to RoomPresenter

import React, { useState } from "react";
import { useQuery, useMutation } from "@apollo/react-hooks";
import { useMutation } from "@apollo/react-hooks";
import { withRouter } from "react-router-dom";
import RoomPresenter from "./RoomPresenter";
import { GET_ROOMS, CREATE_ROOM } from "./RoomQueries";
import { CREATE_ROOM } from "./RoomQueries";
import useInput from "../../Hooks/useInput";
import { toast } from "react-toastify";
......@@ -11,14 +11,9 @@ export default withRouter(() => {
const roomName = useInput("");
const { data } = useQuery(GET_ROOMS);
const [createRoom] = useMutation(CREATE_ROOM);
let roomArray, newRoomObj;
if (data !== undefined) {
const { getRooms } = data;
roomArray = getRooms;
}
let newRoomObj;
const onSubmit = async (e) => {
e.preventDefault();
......@@ -43,7 +38,6 @@ export default withRouter(() => {
return (
<RoomPresenter
roomArray={roomArray}
action={action}
setAction={setAction}
onSubmit={onSubmit}
......
......@@ -6,6 +6,8 @@ import { Link } from "react-router-dom";
import Header from "../../Components/Header";
import Input from "../../Components/Input";
import Button from "../../Components/Button";
import { useQuery } from "@apollo/react-hooks";
import { GET_ROOMS } from "./RoomQueries";
const Wrapper = styled.div`
display: flex;
......@@ -85,7 +87,7 @@ const RoomContainer = styled.div`
flex-direction: column;
width: 100%;
overflow-y: scroll;
min-height: 70px;
max-height: 85px;
justify-content: center;
align-items: center;
&::-webkit-scrollbar {
......@@ -134,6 +136,9 @@ const StyledLink = styled(Link)`
text-decoration: none;
cursor: pointer;
color: #079992;
&:not(:last-child) {
margin-bottom: 10px;
}
svg {
color: #079992;
&:hover {
......@@ -153,7 +158,15 @@ const StyledLink = styled(Link)`
}
`;
export default ({ roomArray, action, setAction, onSubmit, roomName }) => {
export default ({ action, setAction, onSubmit, roomName }) => {
const { data } = useQuery(GET_ROOMS);
let roomArray;
if (data !== undefined) {
const { getRooms } = data;
roomArray = getRooms;
}
return (
<Wrapper>
<Header text={"KhuChat"}></Header>
......