mirror of
https://github.com/NanmiCoder/cc-haha
synced 2026-07-18 13:23:33 +08:00
commit
c9ad1efbb0
@ -1,7 +1,6 @@
|
|||||||
import { Check, Copy, GitFork } from 'lucide-react'
|
import { Check, Copy, GitFork } from 'lucide-react'
|
||||||
import { useTranslation } from '../../i18n'
|
|
||||||
import { useSettingsStore } from '../../stores/settingsStore'
|
import { useSettingsStore } from '../../stores/settingsStore'
|
||||||
import { formatExactMessageTimestamp, formatMessageTimestamp } from '../../lib/formatMessageTimestamp'
|
import { formatExactMessageTimestamp, formatMessageHoverTime } from '../../lib/formatMessageTimestamp'
|
||||||
import { CopyButton } from '../shared/CopyButton'
|
import { CopyButton } from '../shared/CopyButton'
|
||||||
|
|
||||||
export type MessageBranchAction = {
|
export type MessageBranchAction = {
|
||||||
@ -25,11 +24,10 @@ export function MessageActionBar({
|
|||||||
align = 'start',
|
align = 'start',
|
||||||
timestamp,
|
timestamp,
|
||||||
}: Props) {
|
}: Props) {
|
||||||
const t = useTranslation()
|
|
||||||
const locale = useSettingsStore((state) => state.locale)
|
const locale = useSettingsStore((state) => state.locale)
|
||||||
const hasCopy = Boolean(copyText?.trim())
|
const hasCopy = Boolean(copyText?.trim())
|
||||||
const timeLabel = typeof timestamp === 'number'
|
const hoverTimeLabel = typeof timestamp === 'number'
|
||||||
? formatMessageTimestamp(timestamp, t, locale)
|
? formatMessageHoverTime(timestamp, locale)
|
||||||
: ''
|
: ''
|
||||||
const exactTimeLabel = typeof timestamp === 'number'
|
const exactTimeLabel = typeof timestamp === 'number'
|
||||||
? formatExactMessageTimestamp(timestamp, locale)
|
? formatExactMessageTimestamp(timestamp, locale)
|
||||||
@ -69,12 +67,12 @@ export function MessageActionBar({
|
|||||||
<GitFork size={13} strokeWidth={2.2} aria-hidden="true" />
|
<GitFork size={13} strokeWidth={2.2} aria-hidden="true" />
|
||||||
</button>
|
</button>
|
||||||
) : null}
|
) : null}
|
||||||
{timeLabel ? (
|
{hoverTimeLabel ? (
|
||||||
<span
|
<span
|
||||||
className="ml-1 inline-flex items-center text-[11px] font-medium tabular-nums text-[var(--color-text-tertiary)]"
|
className="ml-1 inline-flex items-center text-[11px] font-medium tabular-nums text-[var(--color-text-tertiary)]"
|
||||||
title={exactTimeLabel || timeLabel}
|
title={exactTimeLabel || hoverTimeLabel}
|
||||||
>
|
>
|
||||||
{timeLabel}
|
{hoverTimeLabel}
|
||||||
</span>
|
</span>
|
||||||
) : null}
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -46,6 +46,18 @@ export function formatExactMessageTimestamp(value: number | string | Date, local
|
|||||||
}).format(date)
|
}).format(date)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function formatMessageHoverTime(
|
||||||
|
value: number | string | Date,
|
||||||
|
locale: Locale,
|
||||||
|
now = Date.now(),
|
||||||
|
): string {
|
||||||
|
const date = coerceDate(value)
|
||||||
|
if (!date) return ''
|
||||||
|
return isSameLocalYear(date, new Date(now))
|
||||||
|
? formatMonthDayTime(date, locale)
|
||||||
|
: formatYearMonthDayTime(date, locale)
|
||||||
|
}
|
||||||
|
|
||||||
function coerceDate(value: number | string | Date): Date | null {
|
function coerceDate(value: number | string | Date): Date | null {
|
||||||
const date = value instanceof Date ? value : new Date(value)
|
const date = value instanceof Date ? value : new Date(value)
|
||||||
return Number.isFinite(date.getTime()) ? date : null
|
return Number.isFinite(date.getTime()) ? date : null
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user