blob: df3b8f9a820f49d77f267ea4f2cc4ca3cf3d7565 [file] [log] [blame]
Earl Lee2e463fb2025-04-17 11:22:22 -07001/**
2 * Check if the page should scroll to the bottom based on current view position
3 * @param isFirstLoad If this is the first load of the timeline
4 * @returns Boolean indicating if we should scroll to the bottom
5 */
6export function checkShouldScroll(isFirstLoad: boolean): boolean {
7 // Always scroll on first load
8 if (isFirstLoad) {
9 return true;
10 }
11
12 // Check if user is already near the bottom of the page
13 // Account for the fixed top bar and chat bar
14 return (
15 window.innerHeight + window.scrollY >= document.body.offsetHeight - 200
16 );
17}
18
19/**
20 * Scroll to the bottom of the timeline if shouldScrollToBottom is true
21 * @param shouldScrollToBottom Flag indicating if we should scroll
22 */
23export function scrollToBottom(shouldScrollToBottom: boolean): void {
24 // Find the timeline container
25 const timeline = document.getElementById("timeline");
26
27 // Scroll the window to the bottom based on our pre-determined value
28 if (timeline && shouldScrollToBottom) {
29 // Get the last message or element in the timeline
30 const lastElement = timeline.lastElementChild;
31
32 if (lastElement) {
33 // Scroll to the bottom of the page
34 window.scrollTo({
35 top: document.body.scrollHeight,
36 behavior: "smooth",
37 });
38 }
39 }
40}