diff --git a/src/app/note/components/mentions/user.tsx b/src/app/note/components/mentions/user.tsx index 9eff234e..33dace1c 100644 --- a/src/app/note/components/mentions/user.tsx +++ b/src/app/note/components/mentions/user.tsx @@ -1,8 +1,15 @@ import { useProfile } from "@utils/hooks/useProfile"; import { shortenKey } from "@utils/shortenKey"; +const hexRegex = /[0-9A-Fa-f]{6}/g; + export function MentionUser(props: { children: any[] }) { - const pubkey = props.children[0]; + const pubkey = props.children[0].match(hexRegex) ? props.children[0] : null; + + if (!pubkey) { + return null; + } + const { user } = useProfile(pubkey); return ( diff --git a/src/app/threads/components/author.tsx b/src/app/threads/components/author.tsx index f1e351ff..cb75c84d 100644 --- a/src/app/threads/components/author.tsx +++ b/src/app/threads/components/author.tsx @@ -1,11 +1,40 @@ +import { Image } from "@shared/image"; +import { DEFAULT_AVATAR, IMGPROXY_URL } from "@stores/constants"; +import { useProfile } from "@utils/hooks/useProfile"; +import { shortenKey } from "@utils/shortenKey"; +import dayjs from "dayjs"; + export function ThreadAuthor({ pubkey, time, }: { pubkey: string; time: number }) { + const { user } = useProfile(pubkey); + return ( -
-

{pubkey}

- {time} +
+
+ {pubkey} +
+
+
+
+ {user?.display_name || user?.name || ( +
+ )} +
+
+ {user?.nip05 || shortenKey(pubkey)} + + {dayjs().to(dayjs.unix(time), true)} +
+
+
); } diff --git a/src/app/threads/components/base.tsx b/src/app/threads/components/base.tsx index c8308bc9..2845e0a9 100644 --- a/src/app/threads/components/base.tsx +++ b/src/app/threads/components/base.tsx @@ -1,18 +1,37 @@ import { ThreadAuthor } from "@app/threads/components/author"; +import { Image } from "@shared/image"; export function ThreadBase({ event }: { event: any }) { - const metadata = JSON.parse(event.metadata); - const title = metadata.find((i: any) => i[0] === "title")[1]; - const summary = metadata.find((i: any) => i[0] === "summary")[1] || ""; + const metadata = JSON.parse(event.tags); + const title = metadata.find((i: any) => i[0] === "title")?.[1]; + const summary = metadata.find((i: any) => i[0] === "summary")?.[1]; + const image = metadata.find((i: any) => i[0] === "image")?.[1]; + + if (!title) { + return null; + } return (
-

{title}

-

{summary}

+
+
+

{title}

+
+

{summary}

+
+
+
+ {title} +
+
-
+
diff --git a/src/app/threads/pages/index.page.tsx b/src/app/threads/pages/index.page.tsx index bbabd391..05028553 100644 --- a/src/app/threads/pages/index.page.tsx +++ b/src/app/threads/pages/index.page.tsx @@ -8,6 +8,15 @@ import { useEffect, useRef } from "react"; const ITEM_PER_PAGE = 10; const TIME = Math.floor(Date.now() / 1000); +function isJSON(str: string) { + try { + JSON.parse(str); + } catch (e) { + return false; + } + return true; +} + export function Page() { const { status, @@ -56,7 +65,7 @@ export function Page() { return (
{status === "loading" ? ( @@ -69,7 +78,7 @@ export function Page() {
{error.message}
) : (
{rowVirtualizer.getVirtualItems().map((virtualRow) => { const note = allRows[virtualRow.index]; - if (note) { + if (note && isJSON(note.tags)) { return (