From c68a0a191545599cd0fac84d6a5e42ec8134a0ac Mon Sep 17 00:00:00 2001 From: James Saunders Date: Wed, 15 Jan 2025 16:37:01 +0000 Subject: [PATCH] Merge indexedAt and createdAt date indicators. --- src/components/Admonition.tsx | 4 ++ src/view/com/post-thread/PostThreadItem.tsx | 59 ++++++++++++--------- 2 files changed, 38 insertions(+), 25 deletions(-) diff --git a/src/components/Admonition.tsx b/src/components/Admonition.tsx index 8b01a8abaf..1baad34e61 100644 --- a/src/components/Admonition.tsx +++ b/src/components/Admonition.tsx @@ -13,6 +13,10 @@ export const colors = { light: '#DFBC00', dark: '#BFAF1F', }, + danger: { + light: '#df3f00', + dark: '#df3f00', + }, } type Context = { diff --git a/src/view/com/post-thread/PostThreadItem.tsx b/src/view/com/post-thread/PostThreadItem.tsx index f04b9e225a..36ee947f33 100644 --- a/src/view/com/post-thread/PostThreadItem.tsx +++ b/src/view/com/post-thread/PostThreadItem.tsx @@ -736,7 +736,7 @@ function ExpandedPostDetails({ }) { const t = useTheme() const pal = usePalette('default') - const {_, i18n} = useLingui() + const {_} = useLingui() const openLink = useOpenLink() const isRootPost = !('reply' in post.record) @@ -749,13 +749,23 @@ function ExpandedPostDetails({ [openLink, translatorUrl], ) + const indexedAt = new Date(post.indexedAt) + const createdAt = AppBskyFeedPost.isRecord(post.record) + ? new Date(post.record.createdAt) + : new Date(post.indexedAt) + + // backdated if createdAt is 24 hours or more before indexedAt + const isBackdated = + indexedAt.getTime() - createdAt.getTime() > 24 * 60 * 60 * 1000 + + let dateEl = + if(isBackdated){ + dateEl = + } + return ( - - - - - {niceDate(i18n, post.indexedAt)} - + + {dateEl} {isRootPost && ( )} @@ -774,12 +784,23 @@ function ExpandedPostDetails({ )} - ) } -function BackdatedPostIndicator({post}: {post: AppBskyFeedDefs.PostView}) { +function DateNotBackdated({post}: {post: AppBskyFeedDefs.PostView}) { + const t = useTheme() + const {i18n} = useLingui() + + const indexedAt = new Date(post.indexedAt) + return ( + + {niceDate(i18n, indexedAt)} + + ) +} + +function DateBackdated({post}: {post: AppBskyFeedDefs.PostView}) { const t = useTheme() const {_, i18n} = useLingui() const control = Prompt.usePromptControl() @@ -789,13 +810,7 @@ function BackdatedPostIndicator({post}: {post: AppBskyFeedDefs.PostView}) { ? new Date(post.record.createdAt) : new Date(post.indexedAt) - // backdated if createdAt is 24 hours or more before indexedAt - const isBackdated = - indexedAt.getTime() - createdAt.getTime() > 24 * 60 * 60 * 1000 - - if (!isBackdated) return null - - const orange = t.name === 'light' ? colors.warning.dark : colors.warning.light + const danger = t.name === 'light' ? colors.danger.dark : colors.danger.light return ( <> @@ -823,15 +838,9 @@ function BackdatedPostIndicator({post}: {post: AppBskyFeedDefs.PostView}) { paddingVertical: 3, }, ]}> - - - Archived from {niceDate(i18n, createdAt)} + + + {niceDate(i18n, createdAt)} )}