improved mobile scroll (#3110)

This commit is contained in:
pablodanswer 2024-11-11 17:57:49 -08:00 committed by GitHub
parent f4a020b599
commit 942e47db29
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 17 deletions

View File

@ -142,6 +142,16 @@ export function ChatPage({
refreshChatSessions,
} = useChatContext();
// handle redirect if chat page is disabled
// NOTE: this must be done here, in a client component since
// settings are passed in via Context and therefore aren't
// available in server-side components
const settings = useContext(SettingsContext);
const enterpriseSettings = settings?.enterpriseSettings;
if (settings?.settings?.chat_page_enabled === false) {
router.push("/search");
}
const { assistants: availableAssistants, finalAssistants } = useAssistants();
const [showApiKeyModal, setShowApiKeyModal] = useState(
@ -881,7 +891,6 @@ export function ChatPage({
}, 1500);
};
const distance = 500; // distance that should "engage" the scroll
const debounceNumber = 100; // time for debouncing
const [hasPerformedInitialScroll, setHasPerformedInitialScroll] = useState(
@ -1545,17 +1554,6 @@ export function ChatPage({
}
});
};
// handle redirect if chat page is disabled
// NOTE: this must be done here, in a client component since
// settings are passed in via Context and therefore aren't
// available in server-side components
const settings = useContext(SettingsContext);
const enterpriseSettings = settings?.enterpriseSettings;
if (settings?.settings?.chat_page_enabled === false) {
router.push("/search");
}
const [showDocSidebar, setShowDocSidebar] = useState(false); // State to track if sidebar is open
// 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({
scrollableDivRef,
scrollDist,
endDivRef,
distance,
debounceNumber,
waitForScrollRef,
mobile: settings?.isMobile,
});
// Virtualization + Scrolling related effects and functions

View File

@ -639,19 +639,22 @@ export async function useScrollonStream({
scrollableDivRef,
scrollDist,
endDivRef,
distance,
debounceNumber,
waitForScrollRef,
mobile,
}: {
chatState: ChatState;
scrollableDivRef: RefObject<HTMLDivElement>;
waitForScrollRef: RefObject<boolean>;
scrollDist: MutableRefObject<number>;
endDivRef: RefObject<HTMLDivElement>;
distance: number;
debounceNumber: number;
mobile?: boolean;
}) {
const mobileDistance = 900; // distance that should "engage" the scroll
const desktopDistance = 500; // distance that should "engage" the scroll
const distance = mobile ? mobileDistance : desktopDistance;
const preventScrollInterference = useRef<boolean>(false);
const preventScroll = useRef<boolean>(false);
const blockActionRef = useRef<boolean>(false);
@ -692,7 +695,7 @@ export async function useScrollonStream({
endDivRef.current
) {
// catch up if necessary!
const scrollAmount = scrollDist.current + 10000;
const scrollAmount = scrollDist.current + (mobile ? 1000 : 10000);
if (scrollDist.current > 300) {
// if (scrollDist.current > 140) {
endDivRef.current.scrollIntoView();