From 0cb65c7d167ce71f8675c8e749703f86586baddb Mon Sep 17 00:00:00 2001 From: DIYgod Date: Sun, 21 Sep 2025 16:43:24 +0800 Subject: [PATCH] feat(ai-chat): add inline folo reference icons --- .../message/animated/AnimatedMarkdown.tsx | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/apps/desktop/layer/renderer/src/modules/ai-chat/components/message/animated/AnimatedMarkdown.tsx b/apps/desktop/layer/renderer/src/modules/ai-chat/components/message/animated/AnimatedMarkdown.tsx index 81ade95ba..70905ac11 100644 --- a/apps/desktop/layer/renderer/src/modules/ai-chat/components/message/animated/AnimatedMarkdown.tsx +++ b/apps/desktop/layer/renderer/src/modules/ai-chat/components/message/animated/AnimatedMarkdown.tsx @@ -13,6 +13,7 @@ import remarkGfm from "remark-gfm" import { MemoizedShikiCode } from "~/components/ui/code-highlighter" import { MarkdownLink } from "~/components/ui/markdown/renderers" +import { useNavigateEntry } from "~/hooks/biz/useNavigateEntry" import { usePeekModal } from "~/hooks/biz/usePeekModal" import { ANIMATION_STYLE as ANIMATION_STYLE_DEFAULT, DEFAULT_ANIMATION } from "./constants" @@ -93,6 +94,16 @@ export const MarkdownAnimateText: React.FC = ({ a: ({ node, ...props }) => { return React.createElement(RelatedEntryLink, { ...props } as any) }, + "folo-entry": ({ node, children, ...props }: any) => ( + + {children} + + ), + "folo-feed": ({ node, children, ...props }: any) => ( + + {children} + + ), text: ({ node, ...props }: any) => {animateText(props.children)}, h1: ({ node, ...props }: any) =>

{animateText(props.children)}

, @@ -179,6 +190,62 @@ export const MarkdownAnimateText: React.FC = ({ ) } +const InlineFoloReference: React.FC<{ + type: "entry" | "feed" + children?: React.ReactNode + className?: string + style?: React.CSSProperties +}> = ({ type, children, className, style }) => { + const peekModal = usePeekModal() + const navigateEntry = useNavigateEntry() + + const targetId = React.useMemo(() => { + return React.Children.toArray(children) + .map((child) => { + if (typeof child === "string" || typeof child === "number") { + return String(child) + } + return "" + }) + .join("") + .trim() + }, [children]) + + const handleClick = React.useCallback( + (event: React.MouseEvent) => { + event.preventDefault() + event.stopPropagation() + + if (!targetId) return + + if (type === "entry") { + peekModal(targetId, "modal") + } else { + navigateEntry({ feedId: targetId, entryId: null }) + } + }, + [navigateEntry, peekModal, targetId, type], + ) + + if (!targetId) return null + + const baseClassName = + "inline-flex items-center align-middle cursor-pointer text-text-secondary mx-[0.15em] opacity-80 transition-opacity hover:opacity-100 hover:text-text" + + return ( + + ) +} + const RelatedEntryLink = (props: LinkProps) => { const { href, children } = props const entryId = isBizId(href) ? href : null