generated from uofa-cmput404/project-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
16: Initial posts UI for homepage & added callback to update posts wh…
…en one is created (#57) ### Backend - In `PostsSerializer` GET method, order posts by `published` descending - Some smol cleanup on Post model ### Frontend - Refactor: moving homepage to a feed directory - Adding interface and enums for typing in TypeScript, feel free to change as you see fit - Adding `<PostLists />` component, which is called in the home page to display a list of posts given an author - Note that the `AUTHOR_ID` is still hardcoded, added a TODO once able to get `author_id` of current user - Also added callback in `MakePostModal` comp to fetch posts once a post is made - Added UI changes in existing HomePage component ### Example https://github.com/uofa-cmput404/404f23project-404-team-not-found/assets/40973251/612221ad-ac32-4738-97e7-363fc7183953
- Loading branch information
Showing
10 changed files
with
156 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import React from 'react'; | ||
import { Post } from "../../interfaces/interfaces"; | ||
import { Avatar, Card, CardContent, CardHeader, Typography } from "@mui/material"; | ||
import { theme } from "../../index"; | ||
import { formatDateTime } from "../../utils/dateUtils"; | ||
|
||
const PostsList = ({ | ||
posts, | ||
}: { | ||
posts: Post[]; | ||
}) => { | ||
return ( | ||
<> | ||
{ posts.map(post => ( | ||
<Card key={post.id} | ||
style={{ | ||
margin: "auto", | ||
width: "40vw", | ||
borderRadius: 0, | ||
borderBottom: 0 | ||
}} | ||
variant='outlined'> | ||
<CardHeader | ||
avatar={ | ||
<Avatar sx={{ bgcolor: theme.palette.primary.main }} aria-label="recipe"> | ||
{post.author.displayName[0]} | ||
</Avatar> | ||
} | ||
title={post.author.displayName} | ||
subheader={formatDateTime(post.published)} | ||
sx = {{marginTop:2}} | ||
/> | ||
<CardContent sx={{marginBottom:10}}> | ||
<Typography variant="h6">{post.title}</Typography> | ||
<Typography variant="body1">{post.description}</Typography> | ||
<Typography variant="body1">{post.content}</Typography> | ||
</CardContent> | ||
</Card> | ||
))} | ||
</> | ||
); | ||
}; | ||
|
||
export default PostsList; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export enum ContentType { | ||
BASE64 = "application/base64", | ||
JPEG = "image/jpeg;base64", | ||
MARKDOWN = "text/markdown", | ||
PLAIN = "text/plain", | ||
PNG = "image/png;base64", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { ContentType } from "../enums/enums"; | ||
|
||
export interface Author { | ||
id: string; | ||
createdAt: string; | ||
displayName: string; | ||
github?: string | null; | ||
host: string; | ||
profileImage: string; | ||
url: string; | ||
} | ||
|
||
export interface Category { | ||
category: string; | ||
} | ||
|
||
export interface Post { | ||
id: string; | ||
author: Author; | ||
categories: Category[]; | ||
content?: string | null; | ||
contentType: ContentType; | ||
description: string; | ||
title: string; | ||
source: string; | ||
origin: string; | ||
published: string; | ||
updatedAt?: string | null; | ||
visibility: string; | ||
unlisted: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export function formatDateTime(date_str: string): string { | ||
// TypeScript Date Object: https://www.javatpoint.com/typescript-date-object | ||
const date = new Date(date_str); | ||
const months = [ | ||
"January", "February", "March", "April", "May", "June", | ||
"July", "August", "September", "October", "November", "December" | ||
]; | ||
|
||
const hours = date.getHours(); | ||
const minutes = String(date.getMinutes()).padStart(2, '0'); | ||
|
||
// Convert 24-hour format to 12-hour format and determine AM or PM | ||
const twelveHour = hours % 12 || 12; | ||
const amOrPm = hours < 12 ? "AM" : "PM"; | ||
|
||
return `${twelveHour}:${minutes} ${amOrPm}, ${months[date.getMonth()]} ${date.getDate()}, ${date.getFullYear()}`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters