diff --git a/apps/desktop/layer/renderer/src/modules/ai-chat/components/layouts/AIChatRoot.tsx b/apps/desktop/layer/renderer/src/modules/ai-chat/components/layouts/AIChatRoot.tsx index dc9ece230..f923b5026 100644 --- a/apps/desktop/layer/renderer/src/modules/ai-chat/components/layouts/AIChatRoot.tsx +++ b/apps/desktop/layer/renderer/src/modules/ai-chat/components/layouts/AIChatRoot.tsx @@ -36,6 +36,7 @@ const AIChatRootInner: FC = ({ children, chatId: externalChatId const inputRef = useRef(null!) const refsContext = useMemo(() => ({ panelRef, inputRef }), [panelRef, inputRef]) useAIShortcut() + if (!currentChatId) { return (
diff --git a/apps/desktop/layer/renderer/src/modules/ai-chat/components/layouts/ChatInterface.tsx b/apps/desktop/layer/renderer/src/modules/ai-chat/components/layouts/ChatInterface.tsx index d91ff8716..aa3ae881f 100644 --- a/apps/desktop/layer/renderer/src/modules/ai-chat/components/layouts/ChatInterface.tsx +++ b/apps/desktop/layer/renderer/src/modules/ai-chat/components/layouts/ChatInterface.tsx @@ -4,12 +4,11 @@ import { tracker } from "@follow/tracker" import { clsx, cn, nextFrame } from "@follow/utils" import type { BizUIMessage } from "@folo-services/ai-tools" import { ErrorBoundary } from "@sentry/react" -import { useSetAtom } from "jotai" import type { EditorState, LexicalEditor } from "lexical" import { AnimatePresence } from "motion/react" import { nanoid } from "nanoid" import type { FC, Ref } from "react" -import { Suspense, useCallback, useEffect, useRef, useState } from "react" +import { Suspense, useEffect, useRef, useState } from "react" import { useEventCallback } from "usehooks-ts" import { useAISettingKey } from "~/atoms/settings/ai" @@ -32,8 +31,7 @@ import { useMessages, } from "~/modules/ai-chat/store/hooks" -import { SCROLLED_BEYOND_THRESHOLD } from "../../constants" -import { useAIRootState } from "../../store/AIChatContext" +import { useAttachScrollBeyond } from "../../hooks/useAttachScrollBeyond" import type { AIChatContextBlock } from "../../store/types" import { convertLexicalToMarkdown } from "../../utils/lexical-markdown" import { GlobalFileDropZone } from "../file/GlobalFileDropZone" @@ -228,15 +226,7 @@ const ChatInterfaceContent = ({ centerInputOnEmpty }: ChatInterfaceProps) => { const shouldShowScrollToBottom = hasMessages && !isAtBottom && !isLoadingHistory - const { isScrolledBeyondThreshold } = useAIRootState() - const setIsScrolledBeyondThreshold = useSetAtom(isScrolledBeyondThreshold) - const handleScroll = useCallback( - (event: React.UIEvent) => { - const { scrollTop } = event.currentTarget - setIsScrolledBeyondThreshold(scrollTop > SCROLLED_BEYOND_THRESHOLD) - }, - [setIsScrolledBeyondThreshold], - ) + const { handleScroll } = useAttachScrollBeyond() return (
diff --git a/apps/desktop/layer/renderer/src/modules/ai-chat/components/layouts/WelcomeScreen.tsx b/apps/desktop/layer/renderer/src/modules/ai-chat/components/layouts/WelcomeScreen.tsx index b7ddf9d10..60439d1b5 100644 --- a/apps/desktop/layer/renderer/src/modules/ai-chat/components/layouts/WelcomeScreen.tsx +++ b/apps/desktop/layer/renderer/src/modules/ai-chat/components/layouts/WelcomeScreen.tsx @@ -1,18 +1,15 @@ import { Folo } from "@follow/components/icons/folo.js" import { ScrollArea } from "@follow/components/ui/scroll-area/ScrollArea.js" import { clsx } from "@follow/utils" -import { useSetAtom } from "jotai" import type { EditorState, LexicalEditor } from "lexical" import { AnimatePresence, m } from "motion/react" -import { useCallback } from "react" import { useTranslation } from "react-i18next" import { useAISettingValue } from "~/atoms/settings/ai" import { AISpline } from "~/modules/ai-chat/components/3d-models/AISpline" -import { SCROLLED_BEYOND_THRESHOLD } from "../../constants" +import { useAttachScrollBeyond } from "../../hooks/useAttachScrollBeyond" import { useMainEntryId } from "../../hooks/useMainEntryId" -import { useAIRootState } from "../../store/AIChatContext" import { DefaultWelcomeContent, EntrySummaryCard } from "../welcome" interface WelcomeScreenProps { @@ -28,15 +25,7 @@ export const WelcomeScreen = ({ onSend, centerInputOnEmpty }: WelcomeScreenProps const hasEntryContext = !!mainEntryId const enabledShortcuts = aiSettings.shortcuts?.filter((shortcut) => shortcut.enabled) || [] - const { isScrolledBeyondThreshold } = useAIRootState() - const setIsScrolledBeyondThreshold = useSetAtom(isScrolledBeyondThreshold) - const handleScroll = useCallback( - (event: React.UIEvent) => { - const { scrollTop } = event.currentTarget - setIsScrolledBeyondThreshold(scrollTop > SCROLLED_BEYOND_THRESHOLD) - }, - [setIsScrolledBeyondThreshold], - ) + const { handleScroll } = useAttachScrollBeyond() return ( { + const { isScrolledBeyondThreshold } = useAIRootState() + const setIsScrolledBeyondThreshold = useSetAtom(isScrolledBeyondThreshold) + const handleScroll = useCallback( + (event: React.UIEvent) => { + const { scrollTop } = event.currentTarget + setIsScrolledBeyondThreshold(scrollTop > SCROLLED_BEYOND_THRESHOLD) + }, + [setIsScrolledBeyondThreshold], + ) + const currentChatId = useCurrentChatId() + useEffect(() => { + if (currentChatId) { + setIsScrolledBeyondThreshold(false) + } + }, [currentChatId, setIsScrolledBeyondThreshold]) + return { handleScroll } +}