mirror of
https://github.com/dergigi/boris.git
synced 2025-12-18 15:14:20 +01:00
feat(ui): ultra-compact date format for bookmarks sidebar (now, 5m, 3h, 2d, 1mo, 1y)
This commit is contained in:
@@ -2,7 +2,7 @@ import React from 'react'
|
|||||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
||||||
import { faBookmark, faUserLock, faGlobe } from '@fortawesome/free-solid-svg-icons'
|
import { faBookmark, faUserLock, faGlobe } from '@fortawesome/free-solid-svg-icons'
|
||||||
import { IndividualBookmark } from '../../types/bookmarks'
|
import { IndividualBookmark } from '../../types/bookmarks'
|
||||||
import { formatDate } from '../../utils/bookmarkUtils'
|
import { formatDateCompact } from '../../utils/bookmarkUtils'
|
||||||
import ContentWithResolvedProfiles from '../ContentWithResolvedProfiles'
|
import ContentWithResolvedProfiles from '../ContentWithResolvedProfiles'
|
||||||
import { IconGetter } from './shared'
|
import { IconGetter } from './shared'
|
||||||
|
|
||||||
@@ -75,7 +75,7 @@ export const CompactView: React.FC<CompactViewProps> = ({
|
|||||||
<ContentWithResolvedProfiles content={displayText.slice(0, 60) + (displayText.length > 60 ? '…' : '')} />
|
<ContentWithResolvedProfiles content={displayText.slice(0, 60) + (displayText.length > 60 ? '…' : '')} />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<span className="bookmark-date-compact">{formatDate(bookmark.created_at)}</span>
|
<span className="bookmark-date-compact">{formatDateCompact(bookmark.created_at)}</span>
|
||||||
{isClickable && (
|
{isClickable && (
|
||||||
<button
|
<button
|
||||||
className="compact-read-btn"
|
className="compact-read-btn"
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { formatDistanceToNow } from 'date-fns'
|
import { formatDistanceToNow, differenceInSeconds, differenceInMinutes, differenceInHours, differenceInDays, differenceInMonths, differenceInYears } from 'date-fns'
|
||||||
import { ParsedContent, ParsedNode } from '../types/bookmarks'
|
import { ParsedContent, ParsedNode } from '../types/bookmarks'
|
||||||
import ResolvedMention from '../components/ResolvedMention'
|
import ResolvedMention from '../components/ResolvedMention'
|
||||||
// Note: ContentWithResolvedProfiles is imported by components directly to keep this file component-only for fast refresh
|
// Note: ContentWithResolvedProfiles is imported by components directly to keep this file component-only for fast refresh
|
||||||
@@ -9,6 +9,26 @@ export const formatDate = (timestamp: number) => {
|
|||||||
return formatDistanceToNow(date, { addSuffix: true })
|
return formatDistanceToNow(date, { addSuffix: true })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ultra-compact date format for tight spaces (e.g., compact view)
|
||||||
|
export const formatDateCompact = (timestamp: number) => {
|
||||||
|
const date = new Date(timestamp * 1000)
|
||||||
|
const now = new Date()
|
||||||
|
|
||||||
|
const seconds = differenceInSeconds(now, date)
|
||||||
|
const minutes = differenceInMinutes(now, date)
|
||||||
|
const hours = differenceInHours(now, date)
|
||||||
|
const days = differenceInDays(now, date)
|
||||||
|
const months = differenceInMonths(now, date)
|
||||||
|
const years = differenceInYears(now, date)
|
||||||
|
|
||||||
|
if (seconds < 60) return 'now'
|
||||||
|
if (minutes < 60) return `${minutes}m`
|
||||||
|
if (hours < 24) return `${hours}h`
|
||||||
|
if (days < 30) return `${days}d`
|
||||||
|
if (months < 12) return `${months}mo`
|
||||||
|
return `${years}y`
|
||||||
|
}
|
||||||
|
|
||||||
// Component to render content with resolved nprofile names
|
// Component to render content with resolved nprofile names
|
||||||
// Intentionally no exports except components and render helpers
|
// Intentionally no exports except components and render helpers
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user