Skip to content

Commit

Permalink
refactor: simplify useDocumentStatusTimeAgo
Browse files Browse the repository at this point in the history
  • Loading branch information
robinpyon authored and rexxars committed Dec 19, 2023
1 parent 23c3ba7 commit 78fd1ee
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions packages/sanity/src/core/hooks/useDocumentStatusTimeAgo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,16 @@ export function useDocumentStatusTimeAgo({
useTemporalPhrase: true,
})

let label

// Published with no changes
// @todo: localize correctly
if (!draftUpdatedAt && publishedTimeAgo) {
label = `Published${hidePublishedDate ? '' : ` ${publishedTimeAgo}`}`
}
// Draft, but no published document
if (draftUpdatedAt && !publishedTimeAgo) {
label = `Not published`
}
// Published with draft changes
if (draftUpdatedAt && publishedTimeAgo) {
label = `Published${hidePublishedDate ? '' : ` ${publishedTimeAgo}`}`
}
// Append draft last updated date
if (label && updatedDateTimeAgo) {
label += ` (Updated ${updatedDateTimeAgo})`
}

return label
const documentStatus = [
// Published status
publishedTimeAgo
? `Published${hidePublishedDate ? '' : ` ${publishedTimeAgo}`}`
: `Not published`,
// Last updated (draft) status
...(updatedDateTimeAgo ? [`(Updated ${updatedDateTimeAgo})`] : []),
]

return documentStatus.join(' ')
}

0 comments on commit 78fd1ee

Please sign in to comment.