Skip to content

Commit

Permalink
Merge indexedAt and createdAt date indicators.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesleesaunders committed Jan 16, 2025
1 parent e01fc2f commit c68a0a1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 25 deletions.
4 changes: 4 additions & 0 deletions src/components/Admonition.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ export const colors = {
light: '#DFBC00',
dark: '#BFAF1F',
},
danger: {
light: '#df3f00',
dark: '#df3f00',
},
}

type Context = {
Expand Down
59 changes: 34 additions & 25 deletions src/view/com/post-thread/PostThreadItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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 = <DateNotBackdated post={post} />
if(isBackdated){
dateEl = <DateBackdated post={post} />
}

return (
<View style={[a.gap_md, a.pt_md, a.align_start]}>
<BackdatedPostIndicator post={post} />
<View style={[a.flex_row, a.align_center, a.flex_wrap, a.gap_sm]}>
<Text style={[a.text_sm, t.atoms.text_contrast_medium]}>
{niceDate(i18n, post.indexedAt)}
</Text>
<View style={[a.flex_row, a.align_center, a.flex_wrap, a.gap_sm, a.pt_md]}>
{dateEl}
{isRootPost && (
<WhoCanReply post={post} isThreadAuthor={isThreadAuthor} />
)}
Expand All @@ -774,12 +784,23 @@ function ExpandedPostDetails({
</InlineLinkText>
</>
)}
</View>
</View>
)
}

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 (
<Text style={[a.text_sm, t.atoms.text_contrast_medium]}>
{niceDate(i18n, indexedAt)}
</Text>
)
}

function DateBackdated({post}: {post: AppBskyFeedDefs.PostView}) {
const t = useTheme()
const {_, i18n} = useLingui()
const control = Prompt.usePromptControl()
Expand All @@ -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 (
<>
Expand Down Expand Up @@ -823,15 +838,9 @@ function BackdatedPostIndicator({post}: {post: AppBskyFeedDefs.PostView}) {
paddingVertical: 3,
},
]}>
<CalendarClockIcon fill={orange} size="sm" aria-hidden />
<Text
style={[
a.text_xs,
a.font_bold,
a.leading_tight,
t.atoms.text_contrast_medium,
]}>
<Trans>Archived from {niceDate(i18n, createdAt)}</Trans>
<CalendarClockIcon fill={danger} size="sm" aria-hidden />
<Text>
{niceDate(i18n, createdAt)}
</Text>
</View>
)}
Expand Down

0 comments on commit c68a0a1

Please sign in to comment.