mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-02-02 14:16:39 +01:00
Add one more case for scrolling
This commit is contained in:
parent
87f197fc88
commit
dd99d186bf
1 changed files with 16 additions and 6 deletions
|
@ -144,6 +144,8 @@ function StatusPage({ id }) {
|
||||||
})();
|
})();
|
||||||
}, [id, snapStates.reloadStatusPage]);
|
}, [id, snapStates.reloadStatusPage]);
|
||||||
|
|
||||||
|
const firstLoad = useRef(true);
|
||||||
|
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
if (!statuses.length) return;
|
if (!statuses.length) return;
|
||||||
const isLoading = uiState === 'loading';
|
const isLoading = uiState === 'loading';
|
||||||
|
@ -154,12 +156,18 @@ function StatusPage({ id }) {
|
||||||
console.log('Case 1');
|
console.log('Case 1');
|
||||||
heroStatusRef.current?.scrollIntoView();
|
heroStatusRef.current?.scrollIntoView();
|
||||||
} else if (isLoading && statuses.length > 1) {
|
} else if (isLoading && statuses.length > 1) {
|
||||||
// Case 2: User initiated, while statuses are loading, SMOOTH-SCROLL to hero status
|
if (firstLoad.current) {
|
||||||
console.log('Case 2');
|
// Case 2.1: User initiated, first load, don't smooth scroll anything
|
||||||
heroStatusRef.current?.scrollIntoView({
|
console.log('Case 2.1');
|
||||||
behavior: 'smooth',
|
heroStatusRef.current?.scrollIntoView();
|
||||||
block: 'start',
|
} else {
|
||||||
});
|
// Case 2.2: User initiated, while statuses are loading, SMOOTH-SCROLL to hero status
|
||||||
|
console.log('Case 2.2');
|
||||||
|
heroStatusRef.current?.scrollIntoView({
|
||||||
|
behavior: 'smooth',
|
||||||
|
block: 'start',
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const scrollPosition = states.scrollPositions.get(id);
|
const scrollPosition = states.scrollPositions.get(id);
|
||||||
|
@ -173,12 +181,14 @@ function StatusPage({ id }) {
|
||||||
isLoading,
|
isLoading,
|
||||||
userInitiated: userInitiated.current,
|
userInitiated: userInitiated.current,
|
||||||
statusesLength: statuses.length,
|
statusesLength: statuses.length,
|
||||||
|
firstLoad: firstLoad.current,
|
||||||
// scrollPosition,
|
// scrollPosition,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!isLoading) {
|
if (!isLoading) {
|
||||||
// Reset user initiated flag after statuses are loaded
|
// Reset user initiated flag after statuses are loaded
|
||||||
userInitiated.current = false;
|
userInitiated.current = false;
|
||||||
|
firstLoad.current = false;
|
||||||
}
|
}
|
||||||
}, [statuses, uiState]);
|
}, [statuses, uiState]);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue