Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
52a9da18f2 |
@@ -167,14 +167,21 @@ export function ClientRoot({ children }: ClientRootProps) {
|
||||
// first sync) can not leave the splash up forever.
|
||||
const splashDeadline = useRef<number | undefined>(undefined);
|
||||
|
||||
const scheduleHide = useCallback((reason?: string) => {
|
||||
if (splashHoldTimer.current !== undefined) return;
|
||||
// The splash particles animate for 450ms with up to 640ms of stagger. Hold only
|
||||
// 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 = undefined;
|
||||
setLoading(false);
|
||||
}, 1500);
|
||||
}, hold);
|
||||
}, []);
|
||||
|
||||
// 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.
|
||||
const roomsAtom = useAtomValue(allRoomsAtom);
|
||||
const directsAtom = useAtomValue(mDirectAtom);
|
||||
const chatsReady =
|
||||
roomsAtom.length > 0 &&
|
||||
directsAtom.size > 0 &&
|
||||
roomsAtom.some((roomId) => directsAtom.has(roomId));
|
||||
// An account with no direct chats can never satisfy a gate that requires one, so it
|
||||
// always waits for the deadline. Gate on the rooms only.
|
||||
const chatsReady = roomsAtom.length > 0;
|
||||
|
||||
const tryHide = useCallback(
|
||||
(reason: string): boolean => {
|
||||
@@ -285,12 +291,10 @@ export function ClientRoot({ children }: ClientRootProps) {
|
||||
}, 10000);
|
||||
}
|
||||
|
||||
const poll = window.setInterval(check, 400);
|
||||
mx.on(ClientEvent.Room, check);
|
||||
mx.on(ClientEvent.AccountData, check);
|
||||
|
||||
return () => {
|
||||
window.clearInterval(poll);
|
||||
mx.removeListener(ClientEvent.Room, check);
|
||||
mx.removeListener(ClientEvent.AccountData, check);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user