sdy

move useQuery to RoomPresenter

1 import React, { useState } from "react"; 1 import React, { useState } from "react";
2 -import { useQuery, useMutation } from "@apollo/react-hooks"; 2 +import { useMutation } from "@apollo/react-hooks";
3 import { withRouter } from "react-router-dom"; 3 import { withRouter } from "react-router-dom";
4 import RoomPresenter from "./RoomPresenter"; 4 import RoomPresenter from "./RoomPresenter";
5 -import { GET_ROOMS, CREATE_ROOM } from "./RoomQueries"; 5 +import { CREATE_ROOM } from "./RoomQueries";
6 import useInput from "../../Hooks/useInput"; 6 import useInput from "../../Hooks/useInput";
7 import { toast } from "react-toastify"; 7 import { toast } from "react-toastify";
8 8
...@@ -11,14 +11,9 @@ export default withRouter(() => { ...@@ -11,14 +11,9 @@ export default withRouter(() => {
11 11
12 const roomName = useInput(""); 12 const roomName = useInput("");
13 13
14 - const { data } = useQuery(GET_ROOMS);
15 const [createRoom] = useMutation(CREATE_ROOM); 14 const [createRoom] = useMutation(CREATE_ROOM);
16 15
17 - let roomArray, newRoomObj; 16 + let newRoomObj;
18 - if (data !== undefined) {
19 - const { getRooms } = data;
20 - roomArray = getRooms;
21 - }
22 17
23 const onSubmit = async (e) => { 18 const onSubmit = async (e) => {
24 e.preventDefault(); 19 e.preventDefault();
...@@ -43,7 +38,6 @@ export default withRouter(() => { ...@@ -43,7 +38,6 @@ export default withRouter(() => {
43 38
44 return ( 39 return (
45 <RoomPresenter 40 <RoomPresenter
46 - roomArray={roomArray}
47 action={action} 41 action={action}
48 setAction={setAction} 42 setAction={setAction}
49 onSubmit={onSubmit} 43 onSubmit={onSubmit}
......
...@@ -6,6 +6,8 @@ import { Link } from "react-router-dom"; ...@@ -6,6 +6,8 @@ import { Link } from "react-router-dom";
6 import Header from "../../Components/Header"; 6 import Header from "../../Components/Header";
7 import Input from "../../Components/Input"; 7 import Input from "../../Components/Input";
8 import Button from "../../Components/Button"; 8 import Button from "../../Components/Button";
9 +import { useQuery } from "@apollo/react-hooks";
10 +import { GET_ROOMS } from "./RoomQueries";
9 11
10 const Wrapper = styled.div` 12 const Wrapper = styled.div`
11 display: flex; 13 display: flex;
...@@ -85,7 +87,7 @@ const RoomContainer = styled.div` ...@@ -85,7 +87,7 @@ const RoomContainer = styled.div`
85 flex-direction: column; 87 flex-direction: column;
86 width: 100%; 88 width: 100%;
87 overflow-y: scroll; 89 overflow-y: scroll;
88 - min-height: 70px; 90 + max-height: 85px;
89 justify-content: center; 91 justify-content: center;
90 align-items: center; 92 align-items: center;
91 &::-webkit-scrollbar { 93 &::-webkit-scrollbar {
...@@ -134,6 +136,9 @@ const StyledLink = styled(Link)` ...@@ -134,6 +136,9 @@ const StyledLink = styled(Link)`
134 text-decoration: none; 136 text-decoration: none;
135 cursor: pointer; 137 cursor: pointer;
136 color: #079992; 138 color: #079992;
139 + &:not(:last-child) {
140 + margin-bottom: 10px;
141 + }
137 svg { 142 svg {
138 color: #079992; 143 color: #079992;
139 &:hover { 144 &:hover {
...@@ -153,7 +158,15 @@ const StyledLink = styled(Link)` ...@@ -153,7 +158,15 @@ const StyledLink = styled(Link)`
153 } 158 }
154 `; 159 `;
155 160
156 -export default ({ roomArray, action, setAction, onSubmit, roomName }) => { 161 +export default ({ action, setAction, onSubmit, roomName }) => {
162 + const { data } = useQuery(GET_ROOMS);
163 +
164 + let roomArray;
165 + if (data !== undefined) {
166 + const { getRooms } = data;
167 + roomArray = getRooms;
168 + }
169 +
157 return ( 170 return (
158 <Wrapper> 171 <Wrapper>
159 <Header text={"KhuChat"}></Header> 172 <Header text={"KhuChat"}></Header>
......