From 321f0baefaaff1d736685bcaab6d32a29ed5be98 Mon Sep 17 00:00:00 2001 From: Roland Szoke Date: Thu, 19 Sep 2019 13:21:22 +0200 Subject: [PATCH] Task_3_Done_Hook --- src/Components/Post.jsx | 46 +++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/src/Components/Post.jsx b/src/Components/Post.jsx index 5cfa399..b0eda95 100644 --- a/src/Components/Post.jsx +++ b/src/Components/Post.jsx @@ -1,5 +1,5 @@ import React, { useState } from 'react'; -import { Query } from '@apollo/react-components'; +import { useQuery } from '@apollo/react-hooks'; import { Button, Container, Card, Row, Jumbotron, Spinner, Form, } from 'react-bootstrap'; @@ -13,6 +13,17 @@ const Post = ({ postId }) => { const [commentContent, setCommentContent] = useState(''); const [commentCreateIsLoading] = useState(false); + const { + loading: postIsLoading, + data: postsData, + } = useQuery(queries.post.GET_POSTS_QUERY, { + variables: { + filters: [{ field: 'id', operation: 'eq', value: postId }], + limit: 1, + }, + }); + const post = get(postsData, 'posts.edges[0].node', {}); + // TODO: TASK 4. query comments const commentIsLoading = false; const comments = []; @@ -26,25 +37,20 @@ const Post = ({ postId }) => { return ( - - {({ loading: postIsLoading, data: postsData }) => { - const post = get(postsData, 'posts.edges[0].node', {}); - return (postIsLoading - ?
- : ( - -

{post.title}

-
- {get(post, 'author.username')} -
{DateTime.fromISO(post.timestamp).toFormat('HH:mm - dd/LL/yyyy')}
-
-
-

{post.description}

-

{post.content}

-
- )); - }} -
+ {postIsLoading + ?
+ : ( + +

{post.title}

+
+ {get(post, 'author.username')} +
{DateTime.fromISO(post.timestamp).toFormat('HH:mm - dd/LL/yyyy')}
+
+
+

{post.description}

+

{post.content}

+
+ )}

Write a comment