Merge pull request #77 from v0l/profile-loading

fix: rerender user timeline on pubkey change
This commit is contained in:
Alejandro 2023-01-17 11:22:56 +01:00 committed by GitHub
commit a11372c9ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 6 deletions

View File

@ -15,7 +15,7 @@ export interface NoteReactionProps {
root?: TaggedRawEvent root?: TaggedRawEvent
} }
export default function NoteReaction(props: NoteReactionProps) { export default function NoteReaction(props: NoteReactionProps) {
const ev = props["data-ev"] || new NEvent(props.data); const ev = useMemo(() => props["data-ev"] || new NEvent(props.data), [props.data, props["data-ev"]])
const refEvent = useMemo(() => { const refEvent = useMemo(() => {
if (ev) { if (ev) {
@ -71,6 +71,7 @@ export default function NoteReaction(props: NoteReactionProps) {
showHeader: ev?.Kind === EventKind.Repost, showHeader: ev?.Kind === EventKind.Repost,
showFooter: ev?.Kind === EventKind.Repost, showFooter: ev?.Kind === EventKind.Repost,
}; };
return ( return (
<div className="reaction"> <div className="reaction">
<div className="header flex"> <div className="header flex">

View File

@ -14,15 +14,15 @@ export interface TimelineProps {
* A list of notes by pubkeys * A list of notes by pubkeys
*/ */
export default function Timeline({ global, pubkeys }: TimelineProps) { export default function Timeline({ global, pubkeys }: TimelineProps) {
const feed = useTimelineFeed(pubkeys, global); const { main, others } = useTimelineFeed(pubkeys, global);
function reaction(id: u256, kind = EventKind.Reaction) { function reaction(id: u256, kind = EventKind.Reaction) {
return feed?.others?.filter(a => a.kind === kind && a.tags.some(b => b[0] === "e" && b[1] === id)); return others?.filter(a => a.kind === kind && a.tags.some(b => b[0] === "e" && b[1] === id));
} }
const mainFeed = useMemo(() => { const mainFeed = useMemo(() => {
return feed.main?.sort((a, b) => b.created_at - a.created_at); return main?.sort((a, b) => b.created_at - a.created_at);
}, [feed]); }, [main]);
function eventElement(e: TaggedRawEvent) { function eventElement(e: TaggedRawEvent) {
switch (e.kind) { switch (e.kind) {

View File

@ -83,7 +83,8 @@ export default function ProfilePage() {
function tabContent() { function tabContent() {
switch (tab) { switch (tab) {
case ProfileTab.Notes: return <Timeline pubkeys={[id]} global={false} />; case ProfileTab.Notes:
return <Timeline key={id} pubkeys={[id]} global={false} />;
case ProfileTab.Follows: { case ProfileTab.Follows: {
if (isMe) { if (isMe) {
return ( return (