-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from ostyjs/performance-to-the-moon
Performance to the moon
- Loading branch information
Showing
8 changed files
with
208 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 43 additions & 37 deletions
80
templates/react-shadcn/src/features/note-widget/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,53 @@ | ||
import { NDKEvent } from '@nostr-dev-kit/ndk'; | ||
import { useNdk } from 'nostr-hooks'; | ||
import { useEffect, useState } from 'react'; | ||
import { memo, useEffect, useState } from 'react'; | ||
|
||
import { Spinner } from '@/shared/components/spinner'; | ||
|
||
import { NoteContent, NoteFooter, NoteHeader } from './components'; | ||
|
||
export const NoteByEvent = ({ event }: { event: NDKEvent | null | undefined }) => { | ||
if (event === undefined) { | ||
return <Spinner />; | ||
} | ||
|
||
if (event === null) { | ||
return <div className="px-2 border-b">Note not found</div>; | ||
} | ||
|
||
if (event) { | ||
return ( | ||
<> | ||
<div className="px-2"> | ||
<NoteHeader event={event} /> | ||
<NoteContent event={event} /> | ||
<NoteFooter event={event} /> | ||
</div> | ||
</> | ||
); | ||
} | ||
}; | ||
|
||
export const NoteByNoteId = ({ noteId }: { noteId: string | undefined }) => { | ||
const [event, setEvent] = useState<NDKEvent | null | undefined>(undefined); | ||
|
||
const { ndk } = useNdk(); | ||
|
||
useEffect(() => { | ||
if (!ndk || !noteId) { | ||
return; | ||
export const NoteByEvent = memo( | ||
({ event }: { event: NDKEvent | null | undefined }) => { | ||
if (event === undefined) { | ||
return <Spinner />; | ||
} | ||
|
||
ndk.fetchEvent(noteId).then((event) => { | ||
setEvent(event); | ||
}); | ||
}, [noteId, ndk, setEvent]); | ||
if (event === null) { | ||
return <div className="px-2 border-b">Note not found</div>; | ||
} | ||
|
||
return <NoteByEvent event={event} />; | ||
}; | ||
if (event) { | ||
return ( | ||
<> | ||
<div className="px-2"> | ||
<NoteHeader event={event} /> | ||
<NoteContent event={event} /> | ||
<NoteFooter event={event} /> | ||
</div> | ||
</> | ||
); | ||
} | ||
}, | ||
(prev, next) => prev.event?.id === next.event?.id, | ||
); | ||
|
||
export const NoteByNoteId = memo( | ||
({ noteId }: { noteId: string | undefined }) => { | ||
const [event, setEvent] = useState<NDKEvent | null | undefined>(undefined); | ||
|
||
const { ndk } = useNdk(); | ||
|
||
useEffect(() => { | ||
if (!ndk || !noteId) { | ||
return; | ||
} | ||
|
||
ndk.fetchEvent(noteId).then((event) => { | ||
setEvent(event); | ||
}); | ||
}, [noteId, ndk, setEvent]); | ||
|
||
return <NoteByEvent event={event} />; | ||
}, | ||
(prev, next) => prev.noteId === next.noteId, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.