mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-11-11 04:48:00 +03:00
Merge pull request #4746 from urbit/lf/notifications-load
notifications: prevent race condition causing empty notifications
This commit is contained in:
commit
9bb3cfb90f
@ -11,6 +11,7 @@ export function distanceToBottom(el: HTMLElement) {
|
||||
|
||||
export function useLazyScroll(
|
||||
ref: RefObject<HTMLElement>,
|
||||
ready: boolean,
|
||||
margin: number,
|
||||
count: number,
|
||||
loadMore: () => Promise<boolean>
|
||||
@ -41,7 +42,7 @@ export function useLazyScroll(
|
||||
}, [count]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!ref.current || isDone) {
|
||||
if (!ref.current || isDone || !ready) {
|
||||
return;
|
||||
}
|
||||
const scroll = ref.current;
|
||||
@ -57,7 +58,7 @@ export function useLazyScroll(
|
||||
return () => {
|
||||
ref.current?.removeEventListener('scroll', onScroll);
|
||||
};
|
||||
}, [ref?.current, count]);
|
||||
}, [ref?.current, count, ready]);
|
||||
|
||||
return { isDone, isLoading };
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ import { Invites } from './invites';
|
||||
import { useLazyScroll } from '~/logic/lib/useLazyScroll';
|
||||
import useHarkState from '~/logic/state/hark';
|
||||
import useInviteState from '~/logic/state/invite';
|
||||
import useMetadataState from '~/logic/state/metadata';
|
||||
|
||||
type DatedTimebox = [BigInteger, Timebox];
|
||||
|
||||
@ -64,6 +65,10 @@ export default function Inbox(props: {
|
||||
};
|
||||
}, []);
|
||||
|
||||
const ready = useHarkState(
|
||||
s => Object.keys(s.unreads.graph).length > 0
|
||||
);
|
||||
|
||||
const notificationState = useHarkState(state => state.notifications);
|
||||
const archivedNotifications = useHarkState(state => state.archivedNotifications);
|
||||
|
||||
@ -109,6 +114,7 @@ export default function Inbox(props: {
|
||||
|
||||
const { isDone, isLoading } = useLazyScroll(
|
||||
scrollRef,
|
||||
ready,
|
||||
0.2,
|
||||
_.flatten(notifications).length,
|
||||
loadMore
|
||||
|
Loading…
Reference in New Issue
Block a user