Skip to content

Commit

Permalink
format ago using F1
Browse files Browse the repository at this point in the history
  • Loading branch information
sauldom102 committed Jan 3, 2025
1 parent c49e58e commit 65cfe94
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Meta, StoryObj } from "@storybook/react"
import { subMonths } from "date-fns"
import { CommunityPost } from "."

const meta: Meta<typeof CommunityPost> = {
Expand Down Expand Up @@ -31,7 +32,7 @@ export const Default: Story = {
title: "All company",
url: "https://google.com/",
},
ago: "a month ago",
createdAt: subMonths(new Date(), 1),
title: "Title",
description:
"Description with a maximum of two lines visible.<br />Like this one :)<br />This shouldn't be visible",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { PersonAvatar } from "@/experimental/Information/Avatars/PersonAvatar"
import { Reactions, ReactionsProps } from "@/experimental/Information/Reactions"
import { Dropdown } from "@/experimental/Navigation/Dropdown"
import { EllipsisHorizontal } from "@/icons/app"
import { getAgo } from "@/lib/date"
import { withSkeleton } from "@/lib/skeleton"
import { Skeleton } from "@/ui/skeleton"
import { PostEvent, PostEventProps } from "../PostEvent"
Expand All @@ -19,7 +20,7 @@ type CommunityPostProps = {
title: string
url: string
}
ago: string
createdAt: Date

title: string
description?: string
Expand All @@ -45,7 +46,7 @@ type CommunityPostProps = {
export const BaseCommunityPost = ({
author,
group,
ago,
createdAt,
title,
description,
onClick,
Expand All @@ -60,6 +61,8 @@ export const BaseCommunityPost = ({
.filter(Boolean)
.join(" · ")

const ago = getAgo(createdAt)

return (
<div
className="flex w-full cursor-pointer flex-row gap-3 rounded-xl border border-solid border-transparent p-3 pt-2 hover:bg-f1-background-hover focus:border-f1-border-secondary focus:outline focus:outline-1 focus:outline-offset-1 focus:outline-f1-border-selected-bold md:pb-4 md:pt-3"
Expand Down
6 changes: 5 additions & 1 deletion lib/lib/date.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { format } from "date-fns"
import { format, formatDistanceToNowStrict } from "date-fns"

export function formatTime(date: Date) {
return format(date, "p")
Expand All @@ -11,3 +11,7 @@ export function getAbbreviateMonth(date: Date) {
export function getDayOfMonth(date: Date) {
return date.getDate()
}

export function getAgo(date: Date) {
return formatDistanceToNowStrict(date, { addSuffix: true })
}

0 comments on commit 65cfe94

Please sign in to comment.