-
-
Notifications
You must be signed in to change notification settings - Fork 146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[fix] Post Sorting and Timestamp Display in Your Posts Section #1095
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,7 +113,7 @@ const MyPosts = () => { | |
|
||
{selectedTabData.status === "success" && | ||
selectedTabData.data?.map( | ||
({ id, title, excerpt, readTimeMins, slug, published }) => { | ||
({ id, title, excerpt, readTimeMins, slug, published, updatedAt }) => { | ||
const postStatus = published | ||
? getPostStatus(new Date(published)) | ||
: PostStatus.DRAFT; | ||
|
@@ -154,18 +154,44 @@ const MyPosts = () => { | |
</small> | ||
) : published && postStatus === PostStatus.PUBLISHED ? ( | ||
<small> | ||
Published on{" "} | ||
{new Date(published).toLocaleDateString()} at{" "} | ||
{new Date(published).toLocaleTimeString( | ||
navigator.language, | ||
{ | ||
hour: "2-digit", | ||
minute: "2-digit", | ||
hour12: false, | ||
}, | ||
{/*If updatedAt is greater than published by more than on minutes show updated at else show published | ||
as on updating published updatedAt is automatically updated and is greater than published*/} | ||
{(new Date(updatedAt).getTime() - new Date(published).getTime()) >= 60000 ? ( | ||
<> | ||
{"Last updated on "} | ||
{new Date(updatedAt).toLocaleDateString()} at{" "} | ||
{new Date(updatedAt).toLocaleTimeString(navigator.language, { | ||
hour: "2-digit", | ||
minute: "2-digit", | ||
hour12: false, | ||
})} | ||
</> | ||
) : ( | ||
<> | ||
{"Published on "} | ||
{new Date(published).toLocaleDateString()} at{" "} | ||
{new Date(published).toLocaleTimeString(navigator.language, { | ||
hour: "2-digit", | ||
minute: "2-digit", | ||
hour12: false, | ||
})} | ||
</> | ||
)} | ||
</small> | ||
) : null} | ||
): postStatus === PostStatus.DRAFT ? ( | ||
<small> | ||
Last Updated on {" "} | ||
{new Date(updatedAt).toLocaleDateString()} at{" "} | ||
{new Date(updatedAt).toLocaleTimeString( | ||
navigator.language, | ||
{ | ||
hour: "2-digit", | ||
minute: "2-digit", | ||
hour12: false, | ||
}, | ||
)} | ||
</small> | ||
): null} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Refactor date rendering logic in draft posts Similar to the previous suggestion, the code for rendering the "Last Updated on" date in draft posts can also utilize the helper function to avoid duplication. Update your code as follows: <small>
- Last Updated on {" "}
- {new Date(updatedAt).toLocaleDateString()} at{" "}
- {new Date(updatedAt).toLocaleTimeString(
- navigator.language,
- {
- hour: "2-digit",
- minute: "2-digit",
- hour12: false,
- },
- )}
+ {renderDate("Last Updated on", updatedAt)}
</small>
|
||
</div> | ||
|
||
<Menu | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Refactor date rendering logic to improve maintainability
The rendering logic for displaying dates is duplicated and can be consolidated to reduce repetition. Consider abstracting this logic into a helper function or component.
Suggested refactor:
Define a helper function to render date and time:
Update the rendering code: