Skip to content

Commit

Permalink
improved mobile scroll (#3110)
Browse files Browse the repository at this point in the history
  • Loading branch information
pablodanswer authored Nov 12, 2024
1 parent f4a020b commit 942e47d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
24 changes: 11 additions & 13 deletions web/src/app/chat/ChatPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1603,9 +1601,9 @@ export function ChatPage({
scrollableDivRef,
scrollDist,
endDivRef,
distance,
debounceNumber,
waitForScrollRef,
mobile: settings?.isMobile,
});

// Virtualization + Scrolling related effects and functions
Expand Down
11 changes: 7 additions & 4 deletions web/src/app/chat/lib.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 942e47d

Please sign in to comment.