constant onClick param in some Notes

This commit is contained in:
Martti Malmi
2024-01-08 16:33:03 +02:00
parent 8a75b5bce8
commit ca2cb76380
9 changed files with 38 additions and 28 deletions

View File

@ -1,7 +1,7 @@
import "./Deck.css";
import { NostrLink, TaggedNostrEvent } from "@snort/system";
import { createContext, useEffect, useState } from "react";
import { createContext, useCallback, useEffect, useState } from "react";
import { FormattedMessage } from "react-intl";
import { Link, Outlet, useNavigate } from "react-router-dom";
@ -176,6 +176,13 @@ function ArticlesCol() {
}
function MediaCol({ setThread }: { setThread: (e: NostrLink) => void }) {
const noteOnClick = useCallback(
e => {
setThread(NostrLink.fromEvent(e));
},
[setThread],
);
return (
<div>
<div className="flex items-center gap-2 p-2 border-b border-border-color">
@ -192,7 +199,7 @@ function MediaCol({ setThread }: { setThread: (e: NostrLink) => void }) {
}}
displayAs="grid"
showDisplayAsSelector={false}
noteOnClick={e => setThread(NostrLink.fromEvent(e))}
noteOnClick={noteOnClick}
/>
</div>
);

View File

@ -102,17 +102,17 @@ export function Header() {
function NoteTitle({ link }: { link: NostrLink }) {
const ev = useEventFeed(link);
const values = useMemo(() => {
return { name: <DisplayName pubkey={ev.data?.pubkey ?? ""} /> };
}, [ev.data?.pubkey]);
if (!ev.data?.pubkey) {
return <FormattedMessage defaultMessage="Note" id="qMePPG" />;
}
return (
<>
<FormattedMessage
defaultMessage="Note by {name}"
id="ALdW69"
values={{ name: <DisplayName pubkey={ev.data.pubkey} /> }}
/>
<FormattedMessage defaultMessage="Note by {name}" id="ALdW69" values={values} />
</>
);
}

View File

@ -2,9 +2,9 @@ import "./ProfilePage.css";
import { fetchNip05Pubkey, LNURL } from "@snort/shared";
import {
CachedMetadata,
encodeTLVEntries,
EventKind,
CachedMetadata,
NostrPrefix,
TLVEntryType,
tryParseNostrLink,

View File

@ -1,7 +1,7 @@
import { unixNow } from "@snort/shared";
import { NostrLink } from "@snort/system";
import { SnortContext } from "@snort/system-react";
import { lazy, useContext, useEffect, useState } from "react";
import { lazy, useContext, useEffect, useMemo, useState } from "react";
import { FormattedMessage } from "react-intl";
import { Link, Outlet, RouteObject, useParams } from "react-router-dom";
@ -164,20 +164,20 @@ export const NotesTab = () => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const deckContext = useContext(DeckContext);
const noteOnClick = useMemo(() => {
if (deckContext) {
return ev => {
deckContext.setThread(NostrLink.fromEvent(ev));
};
}
return undefined;
}, [deckContext]);
return (
<>
<FollowsHint />
<TaskList />
<TimelineFollows
postsOnly={true}
noteOnClick={
deckContext
? ev => {
deckContext.setThread(NostrLink.fromEvent(ev));
}
: undefined
}
/>
<TimelineFollows postsOnly={true} noteOnClick={noteOnClick} />
</>
);
};