diff --git a/client-solid/src/Components/PostSegment.tsx b/client-solid/src/Components/PostSegment.tsx new file mode 100644 index 0000000..200cb6c --- /dev/null +++ b/client-solid/src/Components/PostSegment.tsx @@ -0,0 +1,47 @@ +import { useNavigate } from "@solidjs/router"; +import { JSXElement, Show } from "solid-js"; + +import { Arrow, EngagementIcon } from "../Util/Icons"; +import { Post } from "../Util/api"; + +/** + * PostSegment is used to display posts in both the main feed and the post view + * + * @param {Object} props The properties for the PostSegment component. + * @param {Post} props.post The post to display. + * @returns {JSXElement} A JSXElement of a post + */ +export function PostSegment({ post }: { post: Post }): JSXElement { + const nav = useNavigate(); + + const dateOfCreation = new Date(post.createdAt).toDateString(); + const isEdited = !(post.createdAt == post.updatedAt); + + return ( +
+
+

{dateOfCreation}

+ +

This post has been edited

+
+

{post.content}

+
+ + +
+
+
+ ); +} diff --git a/client-solid/src/Components/Posts.tsx b/client-solid/src/Components/Posts.tsx index 4f7bc6b..8dbf287 100644 --- a/client-solid/src/Components/Posts.tsx +++ b/client-solid/src/Components/Posts.tsx @@ -1,9 +1,13 @@ -import { useNavigate } from "@solidjs/router"; import { For, JSXElement, Show, createSignal } from "solid-js"; -import { Arrow, EngagementIcon, loadSpinner } from "../Util/Icons"; +import { loadSpinner } from "../Util/Icons"; import { Post, getPosts } from "../Util/api"; +import { PostSegment } from "./PostSegment"; +/** + * Posts is a component that displays a collection of posts. + * @returns {JSXElement} A JSXElement that contains a collection of posts. + */ export function Posts(): JSXElement { const [posts, setPosts] = createSignal([] as Post[]); const [loading, setLoading] = createSignal(true); @@ -21,43 +25,3 @@ export function Posts(): JSXElement { ); } - -// This is the card container for a post -export function PostSegment({ post } : { post: Post }): JSXElement { - const nav = useNavigate(); - - const dateOfCreation = new Date(post.createdAt).toDateString() - const isEdited = ! (post.createdAt == post.updatedAt) - - return ( -
-
-

- {dateOfCreation} -

- -

This post has been edited

-
-

- {post.content} -

-
- - -
-
-
- ); -} diff --git a/client-solid/src/Components/SinglePost.tsx b/client-solid/src/Components/SinglePost.tsx index d734a33..89fc019 100644 --- a/client-solid/src/Components/SinglePost.tsx +++ b/client-solid/src/Components/SinglePost.tsx @@ -12,8 +12,12 @@ import { loadSpinner } from "../Util/Icons"; import { getPost } from "../Util/api"; import { CommentSection } from "./CommentSection"; import { NewCommentInputArea } from "./NewComment"; -import { PostSegment } from "./Posts"; +import { PostSegment } from "./PostSegment"; +/** + * This is the view for a single post along with its comments. + * @returns {JSXElement} A JSXElement + */ export function SinglePost(): JSXElement { const params = useParams(); const [post] = createResource(params.postid, getPost); @@ -24,7 +28,10 @@ export function SinglePost(): JSXElement { - +