feat: improve "show new notes" button (#268)

This commit is contained in:
Ali Raza
2025-04-14 06:32:22 +05:00
committed by GitHub
parent 192fd144e8
commit 8c141bbbe4
2 changed files with 115 additions and 25 deletions

View File

@@ -4,6 +4,7 @@ import { ExtendedKind } from '@/constants'
import { isReplyNoteEvent } from '@/lib/event'
import { checkAlgoRelay } from '@/lib/relay'
import { cn } from '@/lib/utils'
import NewNotesButton from '@/components/NewNotesButton'
import { useDeepBrowsing } from '@/providers/DeepBrowsingProvider'
import { useMuteList } from '@/providers/MuteListProvider'
import { useNostr } from '@/providers/NostrProvider'
@@ -167,6 +168,29 @@ export default function NoteList({
setNewEvents([])
}
const newUsers = useMemo(() => {
return newEvents
.filter((event: Event) => {
return (
(!filterMutedNotes || !mutePubkeys.includes(event.pubkey)) &&
(listMode !== 'posts' || !isReplyNoteEvent(event))
)
})
.slice(0, 3)
.map((event) => {
return {
pubkey: event.pubkey
}
})
}, [newEvents, filterMutedNotes, mutePubkeys, listMode])
const filteredNewEventsCount = newEvents.filter((event: Event) => {
return (
(!filterMutedNotes || !mutePubkeys.includes(event.pubkey)) &&
(listMode !== 'posts' || !isReplyNoteEvent(event))
)
}).length
return (
<div className={className}>
<ListModeSwitch
@@ -179,13 +203,13 @@ export default function NoteList({
}}
/>
<div ref={topRef} />
{events.length > 0 &&
newEvents.filter((event: Event) => {
return (
(!filterMutedNotes || !mutePubkeys.includes(event.pubkey)) &&
(listMode !== 'posts' || !isReplyNoteEvent(event))
)
}).length > 0 && <ShowNewButton onClick={showNewEvents} />}
{filteredNewEventsCount > 0 && (
<NewNotesButton
users={newUsers}
eventCount={filteredNewEventsCount}
onShowEvents={showNewEvents}
/>
)}
<PullToRefresh
onRefresh={async () => {
setRefreshCount((count) => count + 1)
@@ -236,24 +260,6 @@ export default function NoteList({
)
}
function ShowNewButton({ onClick }: { onClick: () => void }) {
const { t } = useTranslation()
const { deepBrowsing, lastScrollTop } = useDeepBrowsing()
return (
<div
className={cn(
'sticky top-[6.25rem] flex justify-center w-full my-2 z-30 duration-700 transition-transform',
deepBrowsing && lastScrollTop > 800 ? '-translate-y-10' : ''
)}
>
<Button size="lg" onClick={onClick} className="drop-shadow-xl shadow-primary/50">
{t('show new notes')}
</Button>
</div>
)
}
function ListModeSwitch({
listMode,
setListMode