feat: improve interaction after clicking show new notes button
This commit is contained in:
parent
1ec68f5696
commit
7cc159f583
1 changed files with 31 additions and 3 deletions
|
|
@ -77,6 +77,7 @@ const UserAggregationList = forwardRef<
|
||||||
const [since, setSince] = useState(() => dayjs().subtract(1, 'day').unix())
|
const [since, setSince] = useState(() => dayjs().subtract(1, 'day').unix())
|
||||||
const [events, setEvents] = useState<Event[]>([])
|
const [events, setEvents] = useState<Event[]>([])
|
||||||
const [newEvents, setNewEvents] = useState<Event[]>([])
|
const [newEvents, setNewEvents] = useState<Event[]>([])
|
||||||
|
const [newEventPubkeys, setNewEventPubkeys] = useState<Set<string>>(new Set())
|
||||||
const [timelineKey, setTimelineKey] = useState<string | undefined>(undefined)
|
const [timelineKey, setTimelineKey] = useState<string | undefined>(undefined)
|
||||||
const [loading, setLoading] = useState(true)
|
const [loading, setLoading] = useState(true)
|
||||||
const [showLoadingBar, setShowLoadingBar] = useState(true)
|
const [showLoadingBar, setShowLoadingBar] = useState(true)
|
||||||
|
|
@ -89,6 +90,7 @@ const UserAggregationList = forwardRef<
|
||||||
}, [JSON.stringify(subRequests), JSON.stringify(showKinds)])
|
}, [JSON.stringify(subRequests), JSON.stringify(showKinds)])
|
||||||
const bottomRef = useRef<HTMLDivElement | null>(null)
|
const bottomRef = useRef<HTMLDivElement | null>(null)
|
||||||
const topRef = useRef<HTMLDivElement | null>(null)
|
const topRef = useRef<HTMLDivElement | null>(null)
|
||||||
|
const nonPinnedTopRef = useRef<HTMLDivElement | null>(null)
|
||||||
|
|
||||||
const scrollToTop = (behavior: ScrollBehavior = 'instant') => {
|
const scrollToTop = (behavior: ScrollBehavior = 'instant') => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
|
@ -322,6 +324,11 @@ const UserAggregationList = forwardRef<
|
||||||
const handleViewUser = (agg: TUserAggregation) => {
|
const handleViewUser = (agg: TUserAggregation) => {
|
||||||
// Mark as viewed when user clicks
|
// Mark as viewed when user clicks
|
||||||
userAggregationService.markAsViewed(feedId, agg.pubkey)
|
userAggregationService.markAsViewed(feedId, agg.pubkey)
|
||||||
|
setNewEventPubkeys((prev) => {
|
||||||
|
const newSet = new Set(prev)
|
||||||
|
newSet.delete(agg.pubkey)
|
||||||
|
return newSet
|
||||||
|
})
|
||||||
|
|
||||||
if (agg.count === 1) {
|
if (agg.count === 1) {
|
||||||
const evt = agg.events[0]
|
const evt = agg.events[0]
|
||||||
|
|
@ -340,10 +347,23 @@ const UserAggregationList = forwardRef<
|
||||||
}
|
}
|
||||||
|
|
||||||
const showNewEvents = () => {
|
const showNewEvents = () => {
|
||||||
|
const pubkeySet = new Set<string>()
|
||||||
|
let hasPinnedUser = false
|
||||||
|
newEvents.forEach((evt) => {
|
||||||
|
pubkeySet.add(evt.pubkey)
|
||||||
|
if (pinnedPubkeySet.has(evt.pubkey)) {
|
||||||
|
hasPinnedUser = true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
setNewEventPubkeys(pubkeySet)
|
||||||
setEvents((oldEvents) => [...newEvents, ...oldEvents])
|
setEvents((oldEvents) => [...newEvents, ...oldEvents])
|
||||||
setNewEvents([])
|
setNewEvents([])
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
scrollToTop('smooth')
|
if (hasPinnedUser) {
|
||||||
|
scrollToTop('smooth')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
nonPinnedTopRef.current?.scrollIntoView({ behavior: 'smooth', block: 'start' })
|
||||||
}, 0)
|
}, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -355,15 +375,18 @@ const UserAggregationList = forwardRef<
|
||||||
feedId={feedId}
|
feedId={feedId}
|
||||||
aggregation={agg}
|
aggregation={agg}
|
||||||
onClick={() => handleViewUser(agg)}
|
onClick={() => handleViewUser(agg)}
|
||||||
|
isNew={newEventPubkeys.has(agg.pubkey)}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
|
|
||||||
|
<div ref={nonPinnedTopRef} className="scroll-mt-[calc(6rem+1px)]" />
|
||||||
{normalAggregations.map((agg) => (
|
{normalAggregations.map((agg) => (
|
||||||
<UserAggregationItem
|
<UserAggregationItem
|
||||||
key={agg.pubkey}
|
key={agg.pubkey}
|
||||||
feedId={feedId}
|
feedId={feedId}
|
||||||
aggregation={agg}
|
aggregation={agg}
|
||||||
onClick={() => handleViewUser(agg)}
|
onClick={() => handleViewUser(agg)}
|
||||||
|
isNew={newEventPubkeys.has(agg.pubkey)}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
|
|
||||||
|
|
@ -436,11 +459,13 @@ export default UserAggregationList
|
||||||
function UserAggregationItem({
|
function UserAggregationItem({
|
||||||
feedId,
|
feedId,
|
||||||
aggregation,
|
aggregation,
|
||||||
onClick
|
onClick,
|
||||||
|
isNew
|
||||||
}: {
|
}: {
|
||||||
feedId: string
|
feedId: string
|
||||||
aggregation: TUserAggregation
|
aggregation: TUserAggregation
|
||||||
onClick: () => void
|
onClick: () => void
|
||||||
|
isNew?: boolean
|
||||||
}) {
|
}) {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const supportTouch = useMemo(() => isTouchDevice(), [])
|
const supportTouch = useMemo(() => isTouchDevice(), [])
|
||||||
|
|
@ -487,7 +512,10 @@ function UserAggregationItem({
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className="group relative flex items-center gap-4 px-4 py-3 border-b hover:bg-accent/30 cursor-pointer transition-all duration-200"
|
className={cn(
|
||||||
|
'group relative flex items-center gap-4 px-4 py-3 border-b hover:bg-accent/30 cursor-pointer transition-all duration-200',
|
||||||
|
isNew && 'bg-primary/15 hover:bg-primary/20'
|
||||||
|
)}
|
||||||
onClick={onClick}
|
onClick={onClick}
|
||||||
>
|
>
|
||||||
{supportTouch ? (
|
{supportTouch ? (
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue