Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 22 additions & 20 deletions src/Components/Post.jsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import React, { useState } from 'react';
import { Query } from '@apollo/react-components';
import {
Button, Container, Card, Row, Jumbotron, Spinner, Form,
} from 'react-bootstrap';
import { get } from 'lodash';
import { DateTime } from 'luxon';
import PropTypes from 'prop-types';

import queries from '../query';

const Post = ({ postId }) => {
const [commentContent, setCommentContent] = useState('');
const [commentCreateIsLoading] = useState(false);

// TODO: TASK 3. EXTRA query post with hook
console.log(postId);
const postIsLoading = false;
const post = {};

// TODO: TASK 4. query comments
const commentIsLoading = false;
const comments = [];
Expand All @@ -28,21 +26,25 @@ const Post = ({ postId }) => {

return (
<Container className="post">
{/* TODO: TASK 3. query post with component */}
{postIsLoading
? <div className="post-loader"><Spinner animation="border" /></div>
: (
<Jumbotron>
<h1>{post.title}</h1>
<footer className="blockquote-footer">
{get(post, 'author.username')}
<div>{DateTime.fromISO(post.timestamp).toFormat('HH:mm - dd/LL/yyyy')}</div>
</footer>
<br />
<p>{post.description}</p>
<p>{post.content}</p>
</Jumbotron>
)}
<Query query={queries.post.GET_POSTS_QUERY} variables={{ filters: [{ field: 'id', operation: 'eq', value: postId }], limit: 1 }}>
{({ loading: postIsLoading, data: postsData }) => {
const post = get(postsData, 'posts.edges[0].node', {});
return (postIsLoading
? <div className="post-loader"><Spinner animation="border" /></div>
: (
<Jumbotron>
<h1>{post.title}</h1>
<footer className="blockquote-footer">
{get(post, 'author.username')}
<div>{DateTime.fromISO(post.timestamp).toFormat('HH:mm - dd/LL/yyyy')}</div>
</footer>
<br />
<p>{post.description}</p>
<p>{post.content}</p>
</Jumbotron>
));
}}
</Query>
<div className="post-commentForm">
<h4>Write a comment</h4>
<Form onSubmit={handleCreateComment}>
Expand Down