Skip to content

The Open Standard for Generative UI

scrolltobottom, threadlistfilter

abhishek83a391394baf
diff --git a/frontend-sdk/packages/react-ui/src/components/fullscreen/Fullscreen.tsx b/frontend-sdk/packages/react-ui/src/components/fullscreen/Fullscreen.tsx
index 3d2fbdcc0..4217596d8 100644
--- a/frontend-sdk/packages/react-ui/src/components/fullscreen/Fullscreen.tsx
+++ b/frontend-sdk/packages/react-ui/src/components/fullscreen/Fullscreen.tsx
@@ -152,7 +152,7 @@ export const ThreadButton = ({
};
export const ThreadList = ({ className }: { className?: string }) => {
- const { threads } = useThreadListState();
+ let { threads } = useThreadListState();
const { load } = useThreadListActions();
const { searchText } = useContext(SidebarContext);
@@ -160,6 +160,8 @@ export const ThreadList = ({ className }: { className?: string }) => {
load();
}, []);
+ threads = threads.filter((thread) => thread.title.includes(searchText));
+
const groupThreads = () => {
const now = new Date();
const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
@@ -243,11 +245,12 @@ export const ScrollArea = ({
className,
}: React.PropsWithChildren<{ className?: string }>) => {
const ref = useRef<HTMLDivElement>(null);
- useScrollToBottom(ref);
+ const { messages } = useThreadState();
+ useScrollToBottom(ref, messages.length);
return (
- <div className={clsx("cui-fullscreen-scroll-area", className)}>
- <div ref={ref}>{children}</div>
+ <div ref={ref} className={clsx("cui-fullscreen-scroll-area", className)}>
+ {children}
</div>
);
};
diff --git a/frontend-sdk/packages/react-ui/src/hooks/useScrollToBottom.ts b/frontend-sdk/packages/react-ui/src/hooks/useScrollToBottom.ts
index 5b936eae7..336d05dc0 100644
--- a/frontend-sdk/packages/react-ui/src/hooks/useScrollToBottom.ts
+++ b/frontend-sdk/packages/react-ui/src/hooks/useScrollToBottom.ts
@@ -1,28 +1,17 @@
import { RefObject, useEffect } from "react";
-export const useScrollToBottom = <T extends HTMLElement | null>(ref: RefObject<T>) => {
+export const useScrollToBottom = <T extends HTMLElement | null>(
+ ref: RefObject<T>,
+ // if the triggerValue changes, scroll to bottom
+ triggerValue: any,
+) => {
useEffect(() => {
const element = ref.current;
if (!element) return;
- // Function to scroll to bottom
- const scrollToBottom = () => {
- element.scrollTop = element.scrollHeight;
- };
-
- // Create ResizeObserver to watch for height changes
- const observer = new ResizeObserver(() => {
- scrollToBottom();
- });
-
- // Start observing the element
- observer.observe(element, {
- box: "border-box",
+ element.scrollTo({
+ top: element.scrollHeight,
+ behavior: "smooth",
});
-
- // Cleanup
- return () => {
- observer.disconnect();
- };
- }, [ref]);
+ }, [ref, triggerValue]);
};