tangled
alpha
login
or
join now
leaflet.pub
/
leaflet
289
fork
atom
a tool for shared writing and social publishing
289
fork
atom
overview
issues
29
pulls
pipelines
use hook/component for localized dates
awarm.space
4 months ago
7d8f6e60
b5e24f10
+59
-31
5 changed files
expand all
collapse all
unified
split
app
lish
[did]
[publication]
LocalizedDate.tsx
[rkey]
PostHeader
PostHeader.tsx
dashboard
PublishedPostsLists.tsx
page.tsx
reader
ReaderContent.tsx
+10
app/lish/[did]/[publication]/LocalizedDate.tsx
···
1
1
+
"use client";
2
2
+
import { useLocalizedDate } from "src/hooks/useLocalizedDate";
3
3
+
4
4
+
export function LocalizedDate(props: {
5
5
+
dateString: string;
6
6
+
options?: Intl.DateTimeFormatOptions;
7
7
+
}) {
8
8
+
const formattedDate = useLocalizedDate(props.dateString, props.options);
9
9
+
return <>{formattedDate}</>;
10
10
+
}
+11
-7
app/lish/[did]/[publication]/[rkey]/PostHeader/PostHeader.tsx
···
12
12
import { EditTiny } from "components/Icons/EditTiny";
13
13
import { SpeedyLink } from "components/SpeedyLink";
14
14
import { decodeQuotePosition } from "../quotePosition";
15
15
+
import { useLocalizedDate } from "src/hooks/useLocalizedDate";
15
16
16
17
export function PostHeader(props: {
17
18
data: PostPageData;
···
25
26
let profile = props.profile;
26
27
let pub = props.data?.documents_in_publications[0].publications;
27
28
let pubRecord = pub?.record as PubLeafletPublication.Record;
29
29
+
30
30
+
const formattedDate = useLocalizedDate(
31
31
+
record.publishedAt || new Date().toISOString(),
32
32
+
{
33
33
+
year: "numeric",
34
34
+
month: "long",
35
35
+
day: "2-digit",
36
36
+
}
37
37
+
);
28
38
29
39
if (!document?.data || !document.documents_in_publications[0].publications)
30
40
return;
···
78
88
{record.publishedAt ? (
79
89
<>
80
90
|
81
81
-
<p>
82
82
-
{new Date(record.publishedAt).toLocaleDateString(undefined, {
83
83
-
year: "numeric",
84
84
-
month: "long",
85
85
-
day: "2-digit",
86
86
-
})}
87
87
-
</p>
91
91
+
<p>{formattedDate}</p>
88
92
</>
89
93
) : null}
90
94
|{" "}
+16
-11
app/lish/[did]/[publication]/dashboard/PublishedPostsLists.tsx
···
17
17
import { SpeedyLink } from "components/SpeedyLink";
18
18
import { QuoteTiny } from "components/Icons/QuoteTiny";
19
19
import { CommentTiny } from "components/Icons/CommentTiny";
20
20
+
import { useLocalizedDate } from "src/hooks/useLocalizedDate";
20
21
21
22
export function PublishedPostsList(props: {
22
23
searchValue: string;
···
97
98
) : null}
98
99
<div className="text-sm text-tertiary flex gap-1 flex-wrap pt-3">
99
100
{record.publishedAt ? (
100
100
-
<p className="text-sm text-tertiary">
101
101
-
Published{" "}
102
102
-
{new Date(record.publishedAt).toLocaleDateString(
103
103
-
undefined,
104
104
-
{
105
105
-
year: "numeric",
106
106
-
month: "long",
107
107
-
day: "2-digit",
108
108
-
},
109
109
-
)}
110
110
-
</p>
101
101
+
<PublishedDate dateString={record.publishedAt} />
111
102
) : null}
112
103
{(comments > 0 || quotes > 0) && record.publishedAt
113
104
? " | "
···
238
229
);
239
230
}
240
231
}
232
232
+
233
233
+
function PublishedDate(props: { dateString: string }) {
234
234
+
const formattedDate = useLocalizedDate(props.dateString, {
235
235
+
year: "numeric",
236
236
+
month: "long",
237
237
+
day: "2-digit",
238
238
+
});
239
239
+
240
240
+
return (
241
241
+
<p className="text-sm text-tertiary">
242
242
+
Published {formattedDate}
243
243
+
</p>
244
244
+
);
245
245
+
}
+11
-8
app/lish/[did]/[publication]/page.tsx
···
14
14
import { SpeedyLink } from "components/SpeedyLink";
15
15
import { QuoteTiny } from "components/Icons/QuoteTiny";
16
16
import { CommentTiny } from "components/Icons/CommentTiny";
17
17
+
import { LocalizedDate } from "./LocalizedDate";
17
18
18
19
export default async function Publication(props: {
19
20
params: Promise<{ publication: string; did: string }>;
···
152
153
153
154
<div className="text-sm text-tertiary flex gap-1 flex-wrap pt-2">
154
155
<p className="text-sm text-tertiary ">
155
155
-
{doc_record.publishedAt &&
156
156
-
new Date(
157
157
-
doc_record.publishedAt,
158
158
-
).toLocaleDateString(undefined, {
159
159
-
year: "numeric",
160
160
-
month: "long",
161
161
-
day: "2-digit",
162
162
-
})}{" "}
156
156
+
{doc_record.publishedAt && (
157
157
+
<LocalizedDate
158
158
+
dateString={doc_record.publishedAt}
159
159
+
options={{
160
160
+
year: "numeric",
161
161
+
month: "long",
162
162
+
day: "2-digit",
163
163
+
}}
164
164
+
/>
165
165
+
)}{" "}
163
166
</p>
164
167
{comments > 0 || quotes > 0 ? "| " : ""}
165
168
{quotes > 0 && (
+11
-5
app/reader/ReaderContent.tsx
···
20
20
import { useEffect, useRef } from "react";
21
21
import { useRouter } from "next/navigation";
22
22
import Link from "next/link";
23
23
+
import { useLocalizedDate } from "src/hooks/useLocalizedDate";
23
24
24
25
export const ReaderContent = (props: {
25
26
root_entity: string;
···
198
199
author: string;
199
200
publishedAt: string | undefined;
200
201
}) => {
202
202
+
const formattedDate = useLocalizedDate(
203
203
+
props.publishedAt || new Date().toISOString(),
204
204
+
{
205
205
+
year: "numeric",
206
206
+
month: "short",
207
207
+
day: "numeric",
208
208
+
}
209
209
+
);
210
210
+
201
211
return (
202
212
<div className="flex flex-wrap gap-2 grow items-center shrink-0">
203
213
{props.author}
204
214
{props.publishedAt && (
205
215
<>
206
216
<Separator classname="h-4 !min-h-0" />
207
207
-
{new Date(props.publishedAt).toLocaleDateString("en-US", {
208
208
-
year: "numeric",
209
209
-
month: "short",
210
210
-
day: "numeric",
211
211
-
})}{" "}
217
217
+
{formattedDate}{" "}
212
218
</>
213
219
)}
214
220
</div>