diff --git a/src/components/NewNotesButton/index.tsx b/src/components/NewNotesButton/index.tsx new file mode 100644 index 00000000..d9406826 --- /dev/null +++ b/src/components/NewNotesButton/index.tsx @@ -0,0 +1,84 @@ +import React, { useState, useEffect } from 'react' +import UserAvatar from '@/components/UserAvatar' +import { useScreenSize } from '@/providers/ScreenSizeProvider' +import { useDeepBrowsing } from '@/providers/DeepBrowsingProvider' + +export type User = { + pubkey: string +} + +interface NewNotesButtonProps { + users?: User[] + eventCount?: number + onShowEvents?: () => void +} + +const NewNotesButton: React.FC = ({ + users = [], + eventCount: initialEventCount = 0, + onShowEvents +}) => { + const [newNotesCount, setNewNotesCount] = useState(initialEventCount) + const { isSmallScreen } = useScreenSize() + const { deepBrowsing } = useDeepBrowsing() + + useEffect(() => { + setNewNotesCount(initialEventCount) + }, [initialEventCount]) + + const handleClick = () => { + if (onShowEvents) { + onShowEvents() + } else { + console.log('Showing new notes...') + } + setNewNotesCount(0) + } + + const getDesktopPosition = () => { + return deepBrowsing + ? 'absolute left-0 right-0 top-[3.5rem] w-full flex justify-center z-50' + : 'absolute left-0 right-0 top-[6.5rem] w-full flex justify-center z-50' + } + + return ( + <> + {newNotesCount > 0 && ( +
+ +
+ )} + + ) +} + +export default NewNotesButton diff --git a/src/components/NoteList/index.tsx b/src/components/NoteList/index.tsx index a2a94733..1b31281b 100644 --- a/src/components/NoteList/index.tsx +++ b/src/components/NoteList/index.tsx @@ -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 (
- {events.length > 0 && - newEvents.filter((event: Event) => { - return ( - (!filterMutedNotes || !mutePubkeys.includes(event.pubkey)) && - (listMode !== 'posts' || !isReplyNoteEvent(event)) - ) - }).length > 0 && } + {filteredNewEventsCount > 0 && ( + + )} { 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 ( -
800 ? '-translate-y-10' : '' - )} - > - -
- ) -} - function ListModeSwitch({ listMode, setListMode