refactor(dry-F2): centralize shared UI primitives (relative-time, toast, download-status)
- utils/date.js: add formatRelative(iso, {future,nullText}); migrate 6 sites
(SourceRow, SubscriptionsTab, SourceHealthDot, SchedulerStatusBar +
thin adapters in BackupRunsTable/SystemActivityTab for their '—' null text).
PostCard (30d->absolute) and CredentialCard (mo/y buckets) intentionally
keep bespoke formatters.
- utils/toast.js: toast(opts) wraps the globalThis.window?.__fcToast?.(...)
incantation; migrate 63 call sites across 24 files.
- utils/downloadStatus.js: single source for the download-event status enum
-> label/color/icon; collapse the 3 duplicate maps (DownloadStatChips,
DownloadsFilterPopover, DownloadEventRow).
Net -33 lines. Platform metadata was already centralized in platformColor.js.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
|
||||
<script setup>
|
||||
import { computed } from 'vue'
|
||||
import { formatRelative } from '../../utils/date.js'
|
||||
|
||||
const props = defineProps({
|
||||
source: { type: Object, required: true },
|
||||
@@ -38,28 +39,13 @@ const level = computed(() => {
|
||||
|
||||
const ariaLabel = computed(() => `source health: ${level.value}`)
|
||||
|
||||
function relativeTime(iso) {
|
||||
if (!iso) return 'Never'
|
||||
const then = new Date(iso).getTime()
|
||||
const now = Date.now()
|
||||
const diff = Math.abs(now - then) / 1000
|
||||
if (diff < 60) return `${Math.floor(diff)}s`
|
||||
if (diff < 3600) return `${Math.floor(diff / 60)}m`
|
||||
if (diff < 86400) return `${Math.floor(diff / 3600)}h`
|
||||
return `${Math.floor(diff / 86400)}d`
|
||||
}
|
||||
const lastCheckedText = computed(() => formatRelative(props.source.last_checked_at))
|
||||
|
||||
const lastCheckedText = computed(() => {
|
||||
if (!props.source.last_checked_at) return 'Never'
|
||||
return `${relativeTime(props.source.last_checked_at)} ago`
|
||||
})
|
||||
|
||||
const nextCheckText = computed(() => {
|
||||
if (!props.source.next_check_at) return null
|
||||
const due = new Date(props.source.next_check_at).getTime()
|
||||
if (due <= Date.now()) return 'imminent'
|
||||
return `in ~${relativeTime(props.source.next_check_at)}`
|
||||
})
|
||||
const nextCheckText = computed(() =>
|
||||
props.source.next_check_at
|
||||
? formatRelative(props.source.next_check_at, { future: true })
|
||||
: null,
|
||||
)
|
||||
|
||||
const truncatedError = computed(() => {
|
||||
const e = props.source.last_error || ''
|
||||
|
||||
Reference in New Issue
Block a user