Gate the splash on rooms only and hold only the remaining animation time.
This commit is contained in:
@@ -167,14 +167,21 @@ export function ClientRoot({ children }: ClientRootProps) {
|
|||||||
// first sync) can not leave the splash up forever.
|
// first sync) can not leave the splash up forever.
|
||||||
const splashDeadline = useRef<number | undefined>(undefined);
|
const splashDeadline = useRef<number | undefined>(undefined);
|
||||||
|
|
||||||
const scheduleHide = useCallback((reason?: string) => {
|
// The splash particles animate for 450ms with up to 640ms of stagger. Hold only
|
||||||
if (splashHoldTimer.current !== undefined) return;
|
// for whatever is left of that, so a load that already took longer swaps at once.
|
||||||
|
const splashShownAt = useRef(performance.now());
|
||||||
|
const splashHidden = useRef(false);
|
||||||
|
|
||||||
if (reason) console.log(`[ClientRoot] Hiding splash: ${reason}`);
|
const scheduleHide = useCallback((reason?: string) => {
|
||||||
|
if (splashHidden.current) return;
|
||||||
|
|
||||||
|
const hold = Math.max(0, 1100 - (performance.now() - splashShownAt.current));
|
||||||
|
if (reason) console.log(`[ClientRoot] Hiding splash: ${reason} (hold ${Math.round(hold)}ms)`);
|
||||||
|
splashHidden.current = true;
|
||||||
splashHoldTimer.current = window.setTimeout(() => {
|
splashHoldTimer.current = window.setTimeout(() => {
|
||||||
splashHoldTimer.current = undefined;
|
splashHoldTimer.current = undefined;
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}, 1500);
|
}, hold);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// The UI renders chats from the room-list atoms, which are filled by
|
// The UI renders chats from the room-list atoms, which are filled by
|
||||||
@@ -182,10 +189,9 @@ export function ClientRoot({ children }: ClientRootProps) {
|
|||||||
// so the first paint after the splash already contains the chats.
|
// so the first paint after the splash already contains the chats.
|
||||||
const roomsAtom = useAtomValue(allRoomsAtom);
|
const roomsAtom = useAtomValue(allRoomsAtom);
|
||||||
const directsAtom = useAtomValue(mDirectAtom);
|
const directsAtom = useAtomValue(mDirectAtom);
|
||||||
const chatsReady =
|
// An account with no direct chats can never satisfy a gate that requires one, so it
|
||||||
roomsAtom.length > 0 &&
|
// always waits for the deadline. Gate on the rooms only.
|
||||||
directsAtom.size > 0 &&
|
const chatsReady = roomsAtom.length > 0;
|
||||||
roomsAtom.some((roomId) => directsAtom.has(roomId));
|
|
||||||
|
|
||||||
const tryHide = useCallback(
|
const tryHide = useCallback(
|
||||||
(reason: string): boolean => {
|
(reason: string): boolean => {
|
||||||
@@ -285,12 +291,10 @@ export function ClientRoot({ children }: ClientRootProps) {
|
|||||||
}, 10000);
|
}, 10000);
|
||||||
}
|
}
|
||||||
|
|
||||||
const poll = window.setInterval(check, 400);
|
|
||||||
mx.on(ClientEvent.Room, check);
|
mx.on(ClientEvent.Room, check);
|
||||||
mx.on(ClientEvent.AccountData, check);
|
mx.on(ClientEvent.AccountData, check);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
window.clearInterval(poll);
|
|
||||||
mx.removeListener(ClientEvent.Room, check);
|
mx.removeListener(ClientEvent.Room, check);
|
||||||
mx.removeListener(ClientEvent.AccountData, check);
|
mx.removeListener(ClientEvent.AccountData, check);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user