Skip to content

Commit 942e47d

Browse files
authored
improved mobile scroll (#3110)
1 parent f4a020b commit 942e47d

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

web/src/app/chat/ChatPage.tsx

+11-13
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,16 @@ export function ChatPage({
142142
refreshChatSessions,
143143
} = useChatContext();
144144

145+
// handle redirect if chat page is disabled
146+
// NOTE: this must be done here, in a client component since
147+
// settings are passed in via Context and therefore aren't
148+
// available in server-side components
149+
const settings = useContext(SettingsContext);
150+
const enterpriseSettings = settings?.enterpriseSettings;
151+
if (settings?.settings?.chat_page_enabled === false) {
152+
router.push("/search");
153+
}
154+
145155
const { assistants: availableAssistants, finalAssistants } = useAssistants();
146156

147157
const [showApiKeyModal, setShowApiKeyModal] = useState(
@@ -881,7 +891,6 @@ export function ChatPage({
881891
}, 1500);
882892
};
883893

884-
const distance = 500; // distance that should "engage" the scroll
885894
const debounceNumber = 100; // time for debouncing
886895

887896
const [hasPerformedInitialScroll, setHasPerformedInitialScroll] = useState(
@@ -1545,17 +1554,6 @@ export function ChatPage({
15451554
}
15461555
});
15471556
};
1548-
1549-
// handle redirect if chat page is disabled
1550-
// NOTE: this must be done here, in a client component since
1551-
// settings are passed in via Context and therefore aren't
1552-
// available in server-side components
1553-
const settings = useContext(SettingsContext);
1554-
const enterpriseSettings = settings?.enterpriseSettings;
1555-
if (settings?.settings?.chat_page_enabled === false) {
1556-
router.push("/search");
1557-
}
1558-
15591557
const [showDocSidebar, setShowDocSidebar] = useState(false); // State to track if sidebar is open
15601558

15611559
// Used to maintain a "time out" for history sidebar so our existing refs can have time to process change
@@ -1603,9 +1601,9 @@ export function ChatPage({
16031601
scrollableDivRef,
16041602
scrollDist,
16051603
endDivRef,
1606-
distance,
16071604
debounceNumber,
16081605
waitForScrollRef,
1606+
mobile: settings?.isMobile,
16091607
});
16101608

16111609
// Virtualization + Scrolling related effects and functions

web/src/app/chat/lib.tsx

+7-4
Original file line numberDiff line numberDiff line change
@@ -639,19 +639,22 @@ export async function useScrollonStream({
639639
scrollableDivRef,
640640
scrollDist,
641641
endDivRef,
642-
distance,
643642
debounceNumber,
644-
waitForScrollRef,
643+
mobile,
645644
}: {
646645
chatState: ChatState;
647646
scrollableDivRef: RefObject<HTMLDivElement>;
648647
waitForScrollRef: RefObject<boolean>;
649648
scrollDist: MutableRefObject<number>;
650649
endDivRef: RefObject<HTMLDivElement>;
651-
distance: number;
652650
debounceNumber: number;
653651
mobile?: boolean;
654652
}) {
653+
const mobileDistance = 900; // distance that should "engage" the scroll
654+
const desktopDistance = 500; // distance that should "engage" the scroll
655+
656+
const distance = mobile ? mobileDistance : desktopDistance;
657+
655658
const preventScrollInterference = useRef<boolean>(false);
656659
const preventScroll = useRef<boolean>(false);
657660
const blockActionRef = useRef<boolean>(false);
@@ -692,7 +695,7 @@ export async function useScrollonStream({
692695
endDivRef.current
693696
) {
694697
// catch up if necessary!
695-
const scrollAmount = scrollDist.current + 10000;
698+
const scrollAmount = scrollDist.current + (mobile ? 1000 : 10000);
696699
if (scrollDist.current > 300) {
697700
// if (scrollDist.current > 140) {
698701
endDivRef.current.scrollIntoView();

0 commit comments

Comments
 (0)