Skip to content

Commit

Permalink
fix: use localized relative time hook
Browse files Browse the repository at this point in the history
  • Loading branch information
robinpyon authored and rexxars committed Dec 19, 2023
1 parent 5d6ec16 commit 1061d86
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions packages/sanity/src/core/hooks/useDocumentStatusTimeAgo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {PreviewValue, SanityDocument} from '@sanity/types'
import {useTimeAgo} from './useTimeAgo'
import {useRelativeTime} from './useRelativeTime'

/**
* React hook which returns a human readable string of the provided document's status.
Expand All @@ -19,12 +19,19 @@ export function useDocumentStatusTimeAgo({
const draftUpdatedAt = draft && '_updatedAt' in draft ? draft._updatedAt : ''
const publishedUpdatedAt = published && '_updatedAt' in published ? published._updatedAt : ''

const updatedDateTimeAgo = useTimeAgo(draftUpdatedAt || '', {minimal: true, agoSuffix: true})
const publishedTimeAgo = useTimeAgo(publishedUpdatedAt || '', {minimal: true, agoSuffix: true})
const updatedDateTimeAgo = useRelativeTime(draftUpdatedAt || '', {
minimal: true,
useTemporalPhrase: true,
})
const publishedTimeAgo = useRelativeTime(publishedUpdatedAt || '', {
minimal: true,
useTemporalPhrase: true,
})

let label

// Published with no changes
// @todo: localize correctly
if (!draftUpdatedAt && publishedTimeAgo) {
label = `Published${hidePublishedDate ? '' : ` ${publishedTimeAgo}`}`
}
Expand Down

0 comments on commit 1061d86

Please sign in to comment.