diff --git a/app/src/components/FileProvider.tsx b/app/src/components/FileProvider.tsx index 7a0b408..adaa59d 100644 --- a/app/src/components/FileProvider.tsx +++ b/app/src/components/FileProvider.tsx @@ -65,7 +65,7 @@ function FileProvider({ value, onChange }: FileProviderProps) { return ( - + 0 ? "active" : ""}> diff --git a/app/src/components/home/ChatInterface.tsx b/app/src/components/home/ChatInterface.tsx index 8633b85..5b16098 100644 --- a/app/src/components/home/ChatInterface.tsx +++ b/app/src/components/home/ChatInterface.tsx @@ -17,6 +17,7 @@ function ChatInterface({ setTarget, setWorking }: ChatInterfaceProps) { const messages: Message[] = useSelector(selectMessages); const current: number = useSelector(selectCurrent); const [scrollable, setScrollable] = React.useState(true); + const [position, setPosition] = React.useState(0); useEffect( function () { @@ -38,8 +39,12 @@ function ChatInterface({ setTarget, setWorking }: ChatInterfaceProps) { if (!ref.current) return; const el = ref.current as HTMLDivElement; - const event = () => - setScrollable(el.scrollTop + el.clientHeight >= el.scrollHeight); + const event = () => { + const offset = el.scrollTop - position; + setPosition(el.scrollTop); + if (offset < 0) setScrollable(false); + else setScrollable(el.scrollTop + el.clientHeight + 20 >= el.scrollHeight); + }; return addEventListeners( el, ["scroll", "scrollend", "resize", "touchend"], diff --git a/app/src/components/home/assemblies/ScrollAction.tsx b/app/src/components/home/assemblies/ScrollAction.tsx index 14cc276..4667e48 100644 --- a/app/src/components/home/assemblies/ScrollAction.tsx +++ b/app/src/components/home/assemblies/ScrollAction.tsx @@ -4,6 +4,9 @@ import { chatEvent } from "@/events/chat.ts"; import { addEventListeners, scrollDown } from "@/utils/dom.ts"; import { ChatAction } from "@/components/home/assemblies/ChatAction.tsx"; import { useTranslation } from "react-i18next"; +import {Message} from "@/api/types.ts"; +import {useSelector} from "react-redux"; +import {selectMessages} from "@/store/chat.ts"; type ScrollActionProps = { visible: boolean; @@ -13,9 +16,14 @@ type ScrollActionProps = { function ScrollAction({ visible, target, setVisibility }: ScrollActionProps) { const { t } = useTranslation(); + const messages: Message[] = useSelector(selectMessages); useEffect(() => { - if (!target) return; + if (messages.length === 0) return setVisibility(false); + }, [messages]); + + useEffect(() => { + if (!target) return setVisibility(false); addEventListeners(target, ["scroll", "resize"], listenScrollingAction); }, [target]);