diff --git a/app/lish/[did]/[publication]/LocalizedDate.tsx b/app/lish/[did]/[publication]/LocalizedDate.tsx new file mode 100644 index 00000000..69d0cacb --- /dev/null +++ b/app/lish/[did]/[publication]/LocalizedDate.tsx @@ -0,0 +1,10 @@ +"use client"; +import { useLocalizedDate } from "src/hooks/useLocalizedDate"; + +export function LocalizedDate(props: { + dateString: string; + options?: Intl.DateTimeFormatOptions; +}) { + const formattedDate = useLocalizedDate(props.dateString, props.options); + return <>{formattedDate}; +} diff --git a/app/lish/[did]/[publication]/[rkey]/PostHeader/PostHeader.tsx b/app/lish/[did]/[publication]/[rkey]/PostHeader/PostHeader.tsx index 4a09c767..b59daecd 100644 --- a/app/lish/[did]/[publication]/[rkey]/PostHeader/PostHeader.tsx +++ b/app/lish/[did]/[publication]/[rkey]/PostHeader/PostHeader.tsx @@ -12,6 +12,7 @@ import { useIdentityData } from "components/IdentityProvider"; import { EditTiny } from "components/Icons/EditTiny"; import { SpeedyLink } from "components/SpeedyLink"; import { decodeQuotePosition } from "../quotePosition"; +import { useLocalizedDate } from "src/hooks/useLocalizedDate"; export function PostHeader(props: { data: PostPageData; @@ -26,6 +27,15 @@ export function PostHeader(props: { let pub = props.data?.documents_in_publications[0].publications; let pubRecord = pub?.record as PubLeafletPublication.Record; + const formattedDate = useLocalizedDate( + record.publishedAt || new Date().toISOString(), + { + year: "numeric", + month: "long", + day: "2-digit", + } + ); + if (!document?.data || !document.documents_in_publications[0].publications) return; return ( @@ -78,13 +88,7 @@ export function PostHeader(props: { {record.publishedAt ? ( <> | -

- {new Date(record.publishedAt).toLocaleDateString(undefined, { - year: "numeric", - month: "long", - day: "2-digit", - })} -

+

{formattedDate}

) : null} |{" "} diff --git a/app/lish/[did]/[publication]/dashboard/PublishedPostsLists.tsx b/app/lish/[did]/[publication]/dashboard/PublishedPostsLists.tsx index f7ea5be0..3d998853 100644 --- a/app/lish/[did]/[publication]/dashboard/PublishedPostsLists.tsx +++ b/app/lish/[did]/[publication]/dashboard/PublishedPostsLists.tsx @@ -17,6 +17,7 @@ import { ShareButton } from "components/ShareOptions"; import { SpeedyLink } from "components/SpeedyLink"; import { QuoteTiny } from "components/Icons/QuoteTiny"; import { CommentTiny } from "components/Icons/CommentTiny"; +import { useLocalizedDate } from "src/hooks/useLocalizedDate"; export function PublishedPostsList(props: { searchValue: string; @@ -97,17 +98,7 @@ export function PublishedPostsList(props: { ) : null}
{record.publishedAt ? ( -

- Published{" "} - {new Date(record.publishedAt).toLocaleDateString( - undefined, - { - year: "numeric", - month: "long", - day: "2-digit", - }, - )} -

+ ) : null} {(comments > 0 || quotes > 0) && record.publishedAt ? " | " @@ -238,3 +229,17 @@ function OptionsMenu(props: { document_uri: string }) { ); } } + +function PublishedDate(props: { dateString: string }) { + const formattedDate = useLocalizedDate(props.dateString, { + year: "numeric", + month: "long", + day: "2-digit", + }); + + return ( +

+ Published {formattedDate} +

+ ); +} diff --git a/app/lish/[did]/[publication]/page.tsx b/app/lish/[did]/[publication]/page.tsx index f1a34c74..0d217124 100644 --- a/app/lish/[did]/[publication]/page.tsx +++ b/app/lish/[did]/[publication]/page.tsx @@ -14,6 +14,7 @@ import { NotFoundLayout } from "components/PageLayouts/NotFoundLayout"; import { SpeedyLink } from "components/SpeedyLink"; import { QuoteTiny } from "components/Icons/QuoteTiny"; import { CommentTiny } from "components/Icons/CommentTiny"; +import { LocalizedDate } from "./LocalizedDate"; export default async function Publication(props: { params: Promise<{ publication: string; did: string }>; @@ -152,14 +153,16 @@ export default async function Publication(props: {

- {doc_record.publishedAt && - new Date( - doc_record.publishedAt, - ).toLocaleDateString(undefined, { - year: "numeric", - month: "long", - day: "2-digit", - })}{" "} + {doc_record.publishedAt && ( + + )}{" "}

{comments > 0 || quotes > 0 ? "| " : ""} {quotes > 0 && ( diff --git a/app/reader/ReaderContent.tsx b/app/reader/ReaderContent.tsx index 5297cf0f..669df6c6 100644 --- a/app/reader/ReaderContent.tsx +++ b/app/reader/ReaderContent.tsx @@ -20,6 +20,7 @@ import { getReaderFeed } from "./getReaderFeed"; import { useEffect, useRef } from "react"; import { useRouter } from "next/navigation"; import Link from "next/link"; +import { useLocalizedDate } from "src/hooks/useLocalizedDate"; export const ReaderContent = (props: { root_entity: string; @@ -198,17 +199,22 @@ const PostInfo = (props: { author: string; publishedAt: string | undefined; }) => { + const formattedDate = useLocalizedDate( + props.publishedAt || new Date().toISOString(), + { + year: "numeric", + month: "short", + day: "numeric", + } + ); + return (
{props.author} {props.publishedAt && ( <> - {new Date(props.publishedAt).toLocaleDateString("en-US", { - year: "numeric", - month: "short", - day: "numeric", - })}{" "} + {formattedDate}{" "} )}