From 5d1bd0f8f9e6e28e8751b25e767cb22ae66c87c4 Mon Sep 17 00:00:00 2001 From: Ruidy Nemausat Date: Wed, 20 May 2020 14:31:06 +0200 Subject: [PATCH] connect to redux store --- src/pages/Post.tsx | 101 +++++++++++++++++++++++++++++---------------- 1 file changed, 66 insertions(+), 35 deletions(-) diff --git a/src/pages/Post.tsx b/src/pages/Post.tsx index 4b593a1..9bfbeab 100644 --- a/src/pages/Post.tsx +++ b/src/pages/Post.tsx @@ -1,45 +1,60 @@ import React, {FC} from 'react'; -import Post, {dummyPost as post} from '../models/Post'; +// Routing +import {useParams, Link} from 'react-router-dom'; +// Redux +import {compose} from '@reduxjs/toolkit'; +import {connect} from 'react-redux'; +import {firestoreConnect} from 'react-redux-firebase'; +import {RootState} from '../store'; +import Collections from '../constants/collections'; +// Typing +import Post from '../models/Post'; import Comment from '../types/Comment'; +import Routes from '../constants/routes'; +interface IProps { + post: Post; +} /** * Display a Post and the related comments. Shows a form to add a comment. */ -const PostPage: FC = () => ( -
- - Back To Posts - +const PostPage: FC = ({post}) => { + console.log(post); + return ( +
+ + Back To Posts + -
-
- - {post.name} -

{post.name}

-
+
+
+ + {post.name} +

{post.name}

+ +
+
+

{post.text}

+
-
-

{post.text}

-
-
-
-
-

Leave A Comment

+
+
+

Leave A Comment

+
+
+ + +
-
- - -
-
-
- {post.comments.map((c: Comment, i: number) => ( + {/*
+ {post.comments?.map((c: Comment, i: number) => ( ))} -
-
-); + */} +
+ ); +}; -export default PostPage; +/** + * Container to fetch id params from thr URI and pass it to Profile page + */ +const PostPageContainer: FC = () => { + const {id} = useParams(); + const Component = compose( + firestoreConnect(() => [`${Collections.POSTS}/${id}`]), + connect(({firestore: {data}}: RootState) => ({ + post: data.posts && data.posts[id], + })), + )(PostPage); + + return ; +}; + +export default PostPageContainer;