From 607d6b3d5e3cdfa14113fc76340d57fe9790e60f Mon Sep 17 00:00:00 2001 From: Innei Date: Tue, 2 Sep 2025 22:29:37 +0800 Subject: [PATCH] fix(ai): restore ai summary card shown when chat panel closed - Updated the modal's close logic to call `readyToClose()` before proceeding with the close action, ensuring that the animation state is properly managed. - This change enhances the user experience by preventing premature closure of the modal during animations. Signed-off-by: Innei --- .../ui/ai-summary-card/AISummaryCardBase.tsx | 177 ++++++++++++++++++ .../components/ui/ai-summary-card/index.ts | 1 + .../src/components/ui/modal/stacked/modal.tsx | 8 +- .../components/welcome/EntrySummaryCard.tsx | 143 +++----------- .../modules/entry-column/AIEntryLayout.tsx | 1 - .../src/modules/entry-content/AISummary.tsx | 117 +++--------- .../entry-content/EntryContent.ai.tsx | 2 - .../components/layouts/ArticleLayout.tsx | 7 + locales/app/en.json | 1 + 9 files changed, 247 insertions(+), 210 deletions(-) create mode 100644 apps/desktop/layer/renderer/src/components/ui/ai-summary-card/AISummaryCardBase.tsx create mode 100644 apps/desktop/layer/renderer/src/components/ui/ai-summary-card/index.ts diff --git a/apps/desktop/layer/renderer/src/components/ui/ai-summary-card/AISummaryCardBase.tsx b/apps/desktop/layer/renderer/src/components/ui/ai-summary-card/AISummaryCardBase.tsx new file mode 100644 index 000000000..85a83e1ed --- /dev/null +++ b/apps/desktop/layer/renderer/src/components/ui/ai-summary-card/AISummaryCardBase.tsx @@ -0,0 +1,177 @@ +import { AutoResizeHeight } from "@follow/components/ui/auto-resize-height/index.js" +import { MotionButtonBase } from "@follow/components/ui/button/index.js" +import { cn } from "@follow/utils/utils" +import type { ReactNode } from "react" +import { useTranslation } from "react-i18next" + +import { CopyButton } from "~/components/ui/button/CopyButton" +import { Markdown } from "~/components/ui/markdown/Markdown" + +interface AISummaryCardBaseProps { + /** Summary content to display */ + content?: string | null + /** Whether the summary is currently loading */ + isLoading?: boolean + /** Additional className for the container */ + className?: string + /** Custom header content (replaces default AI Summary header) */ + headerContent?: ReactNode + /** Additional content to render below the summary */ + footerContent?: ReactNode + /** Custom loading state component */ + loadingComponent?: ReactNode + /** Custom empty state component */ + emptyComponent?: ReactNode + /** Title text for the AI Summary header */ + title?: string + /** Whether to show the copy button */ + showCopyButton?: boolean + /** Whether to show the Ask AI button when there's content */ + showAskAIButton?: boolean + /** Callback when Ask AI button is clicked */ + onAskAI?: () => void +} + +const DefaultLoadingState = () => ( +
+
+
+
+
+) + +const DefaultEmptyState = ({ message }: { message: string }) => ( +
+ +

{message}

+
+) + +export const AISummaryCardBase: React.FC = ({ + content, + isLoading = false, + className, + headerContent, + footerContent, + loadingComponent, + emptyComponent, + title = "AI Summary", + showCopyButton = true, + showAskAIButton = false, + onAskAI, +}) => { + const { t } = useTranslation("app") + + const hasContent = !isLoading && content + + return ( +
+ {/* Animated background gradient */} +
+ + {/* Header */} +
+ {headerContent || ( +
+ {/* Glowing AI icon */} +
+ +
+
+ + {title} + +
+ )} + +
+ {showAskAIButton && hasContent && onAskAI && ( + + + Ask AI + + )} + + {showCopyButton && hasContent && ( + + )} +
+
+ + {/* Content */} + + {isLoading ? ( + loadingComponent || + ) : hasContent ? ( + {String(content)} + ) : ( + emptyComponent || + )} + + + {/* Footer */} + {footerContent} +
+ ) +} diff --git a/apps/desktop/layer/renderer/src/components/ui/ai-summary-card/index.ts b/apps/desktop/layer/renderer/src/components/ui/ai-summary-card/index.ts new file mode 100644 index 000000000..c1ca9a5cb --- /dev/null +++ b/apps/desktop/layer/renderer/src/components/ui/ai-summary-card/index.ts @@ -0,0 +1 @@ +export { AISummaryCardBase } from "./AISummaryCardBase" diff --git a/apps/desktop/layer/renderer/src/components/ui/modal/stacked/modal.tsx b/apps/desktop/layer/renderer/src/components/ui/modal/stacked/modal.tsx index cee2b6de7..09e804f0e 100644 --- a/apps/desktop/layer/renderer/src/components/ui/modal/stacked/modal.tsx +++ b/apps/desktop/layer/renderer/src/components/ui/modal/stacked/modal.tsx @@ -90,15 +90,13 @@ export const ModalInternal = memo(function Modal({ const setStack = useSetAtom(modalStackAtom) // Animation controls - const { animateController, playNoticeAnimation, playExitAnimation, isClosing } = useModalAnimate( - !!isTop, - item.id, - ) + const { animateController, playNoticeAnimation, playExitAnimation, isClosing, readyToClose } = + useModalAnimate(!!isTop, item.id) // Simple dismiss logic const close = useEventCallback(async (forceClose = false) => { if (!canClose && !forceClose) return - + readyToClose() try { if (CustomModalComponent) { // Custom modals handle their own animation diff --git a/apps/desktop/layer/renderer/src/modules/ai-chat/components/welcome/EntrySummaryCard.tsx b/apps/desktop/layer/renderer/src/modules/ai-chat/components/welcome/EntrySummaryCard.tsx index 244e34b81..30fab23b9 100644 --- a/apps/desktop/layer/renderer/src/modules/ai-chat/components/welcome/EntrySummaryCard.tsx +++ b/apps/desktop/layer/renderer/src/modules/ai-chat/components/welcome/EntrySummaryCard.tsx @@ -1,15 +1,12 @@ import { Spring } from "@follow/components/constants/spring.js" import { AIShortcutButton } from "@follow/components/ui/ai-shortcut-button/index.js" -import { AutoResizeHeight } from "@follow/components/ui/auto-resize-height/index.js" import { usePrefetchSummary } from "@follow/store/summary/hooks" -import { cn } from "@follow/utils/utils" import { m } from "motion/react" import { useTranslation } from "react-i18next" import { useEntryIsInReadabilitySuccess } from "~/atoms/readability" import { useActionLanguage } from "~/atoms/settings/general" -import { CopyButton } from "~/components/ui/button/CopyButton" -import { Markdown } from "~/components/ui/markdown/Markdown" +import { AISummaryCardBase } from "~/components/ui/ai-summary-card" import { useSmartQuickActions } from "../../hooks/useSmartQuickActions" @@ -19,14 +16,6 @@ interface EntrySummaryCardProps { className?: string } -const SummaryLoadingState = () => ( -
-
-
-
-
-) - export const EntrySummaryCard: React.FC = ({ entryId, onSend, @@ -44,117 +33,39 @@ export const EntrySummaryCard: React.FC = ({ const quickActions = useSmartQuickActions(summary.data || null, entryId) + const footerContent = summary.data && quickActions.length > 0 && ( +
+
+ {t("conversation_starters", { defaultValue: "Conversation starters" })} +
+
+ {quickActions.map((action, index) => ( + onSend(action.prompt)} + animationDelay={index * 0.1} + > + {action.label} + + ))} +
+
+ ) + return ( - {/* Animated background gradient */} -
- - {/* Header with entry context */} -
-
-
- -
-
- - {t("ai_summary", { defaultValue: "AI Summary" })} - -
- - {summary.data && ( - - )} -
- - {/* Summary Content */} - - {summary.isLoading ? ( - - ) : summary.data ? ( -
- {String(summary.data)} -
- ) : ( -
- -

- {t("summary_not_available", { defaultValue: "Summary not available" })} -

-
- )} -
- - {/* Smart Quick Actions */} - {summary.data && quickActions.length > 0 && ( -
-
- {t("conversation_starters", { defaultValue: "Conversation starters" })} -
-
- {quickActions.map((action, index) => ( - onSend(action.prompt)} - animationDelay={index * 0.1} - > - {action.label} - - ))} -
-
- )} ) } diff --git a/apps/desktop/layer/renderer/src/modules/entry-column/AIEntryLayout.tsx b/apps/desktop/layer/renderer/src/modules/entry-column/AIEntryLayout.tsx index bb22ab229..5988f9fe4 100644 --- a/apps/desktop/layer/renderer/src/modules/entry-column/AIEntryLayout.tsx +++ b/apps/desktop/layer/renderer/src/modules/entry-column/AIEntryLayout.tsx @@ -174,7 +174,6 @@ export const AIEntryLayout = memo(function AIEntryLayout() { return ( - {/* AI Spline Button - available globally when floating AI chat is closed */} ) diff --git a/apps/desktop/layer/renderer/src/modules/entry-content/AISummary.tsx b/apps/desktop/layer/renderer/src/modules/entry-content/AISummary.tsx index 0393749bb..7272ee258 100644 --- a/apps/desktop/layer/renderer/src/modules/entry-content/AISummary.tsx +++ b/apps/desktop/layer/renderer/src/modules/entry-content/AISummary.tsx @@ -1,14 +1,17 @@ -import { AutoResizeHeight } from "@follow/components/ui/auto-resize-height/index.js" import { useEntry } from "@follow/store/entry/hooks" import { usePrefetchSummary } from "@follow/store/summary/hooks" -import { cn } from "@follow/utils/utils" import { useTranslation } from "react-i18next" import { useShowAISummary } from "~/atoms/ai-summary" import { useEntryIsInReadabilitySuccess } from "~/atoms/readability" +import { + AIChatPanelStyle, + setAIPanelVisibility, + useAIChatPanelStyle, + useAIPanelVisibility, +} from "~/atoms/settings/ai" import { useActionLanguage } from "~/atoms/settings/general" -import { CopyButton } from "~/components/ui/button/CopyButton" -import { Markdown } from "~/components/ui/markdown/Markdown" +import { AISummaryCardBase } from "~/components/ui/ai-summary-card" export function AISummary({ entryId }: { entryId: string }) { const { t } = useTranslation() @@ -16,6 +19,11 @@ export function AISummary({ entryId }: { entryId: string }) { const isInReadabilitySuccess = useEntryIsInReadabilitySuccess(entryId) const showAISummary = useShowAISummary(summarySetting) const actionLanguage = useActionLanguage() + + // AI Chat panel state + const aiChatPanelStyle = useAIChatPanelStyle() + const isAIPanelVisible = useAIPanelVisibility() + const summary = usePrefetchSummary({ actionLanguage, entryId, @@ -23,92 +31,29 @@ export function AISummary({ entryId }: { entryId: string }) { enabled: showAISummary, }) + // Show Ask AI button when: + // 1. Panel style is floating AND panel is not visible + // 2. OR panel style is fixed (since fixed panel can be toggled) + const shouldShowAskAI = + (aiChatPanelStyle === AIChatPanelStyle.Floating && !isAIPanelVisible) || + aiChatPanelStyle === AIChatPanelStyle.Fixed + + const handleAskAI = () => { + setAIPanelVisibility(true) + } + if (!showAISummary || (!summary.isLoading && !summary.data)) { return null } return ( -
-
- -
-
- {/* Glowing AI icon */} -
- -
-
- - {t("entry_content.ai_summary")} - -
- - {summary.data && ( - - )} -
- - - {summary.isLoading ? ( -
-
-
-
-
- ) : ( -
- {String(summary.data)} -
- )} - -
+ ) } diff --git a/apps/desktop/layer/renderer/src/modules/entry-content/components/entry-content/EntryContent.ai.tsx b/apps/desktop/layer/renderer/src/modules/entry-content/components/entry-content/EntryContent.ai.tsx index 1789231b2..a28c1a473 100644 --- a/apps/desktop/layer/renderer/src/modules/entry-content/components/entry-content/EntryContent.ai.tsx +++ b/apps/desktop/layer/renderer/src/modules/entry-content/components/entry-content/EntryContent.ai.tsx @@ -203,8 +203,6 @@ const EntryContentImpl: Component = ({ - - {/* {!isInPeekModal && } */}
) } diff --git a/apps/desktop/layer/renderer/src/modules/entry-content/components/layouts/ArticleLayout.tsx b/apps/desktop/layer/renderer/src/modules/entry-content/components/layouts/ArticleLayout.tsx index 4e279a3c7..95733a735 100644 --- a/apps/desktop/layer/renderer/src/modules/entry-content/components/layouts/ArticleLayout.tsx +++ b/apps/desktop/layer/renderer/src/modules/entry-content/components/layouts/ArticleLayout.tsx @@ -7,6 +7,7 @@ import { cn } from "@follow/utils" import { ErrorBoundary } from "@sentry/react" import { useCallback, useMemo, useRef, useState } from "react" +import { AIChatPanelStyle, useAIChatPanelStyle } from "~/atoms/settings/ai" import { useUISettingKey } from "~/atoms/settings/ui" import { ShadowDOM } from "~/components/common/ShadowDOM" import type { TocRef } from "~/components/ui/markdown/components/Toc" @@ -19,6 +20,7 @@ import { BlockSliceAction } from "~/modules/ai-chat/store/slices/block.slice" import { EntryContentHTMLRenderer } from "~/modules/renderer/html" import { WrappedElementProvider } from "~/providers/wrapped-element-provider" +import { AISummary } from "../../AISummary" import { useEntryContent, useEntryMediaInfo } from "../../hooks" import { ContainerToc } from "../entry-content/accessories/ContainerToc" import { EntryRenderError } from "../entry-content/EntryRenderError" @@ -73,6 +75,9 @@ export const ArticleLayout: React.FC = ({ removeBlock(BlockSliceAction.SPECIAL_TYPES.selectedText) }, [removeBlock]) + const aiChatPanelStyle = useAIChatPanelStyle() + + const shouldShowAISummary = aiChatPanelStyle === AIChatPanelStyle.Floating if (!entry) return null return ( @@ -89,6 +94,8 @@ export const ArticleLayout: React.FC = ({
+ + {shouldShowAISummary && } {showTranscript ? ( diff --git a/locales/app/en.json b/locales/app/en.json index 4463e8539..1f01de70a 100644 --- a/locales/app/en.json +++ b/locales/app/en.json @@ -26,6 +26,7 @@ "activation.plan.title": "Upgrade Plan", "activation.plan.upgrade": "Upgrade", "activation.title": "Invitation Code", + "ai.summary_not_available": "Summary not available", "app.copy_logo_svg": "Copy Logo SVG", "app.copy_logo_text_svg": "Copy Logo Text SVG", "app.toggle_sidebar": "Toggle Sidebar",