feat: implement timeline summarization feature and update related UI components
This commit is contained in:
@@ -111,7 +111,7 @@ export const isServerShortcut = (shortcut: AIShortcut) => !!shortcut.defaultProm
|
||||
export const createDefaultSettings = (): WebAISettings => ({
|
||||
...defaultAISettings,
|
||||
shortcuts: normalizeShortcuts(defaultAISettings.shortcuts),
|
||||
panelStyle: AIChatPanelStyle.Fixed,
|
||||
panelStyle: AIChatPanelStyle.Floating,
|
||||
showSplineButton: true,
|
||||
})
|
||||
|
||||
@@ -224,5 +224,4 @@ export const removeMCPService = (id: string) => {
|
||||
//// Enhance Init Ai Settings
|
||||
export const initializeDefaultAISettings = () => {
|
||||
initializeDefaultSettings()
|
||||
if (getAISettings().panelStyle === AIChatPanelStyle.Fixed) setAIPanelVisibility(true)
|
||||
}
|
||||
|
||||
+1
-1
@@ -109,7 +109,7 @@ export const AISplineLoader = ({ className }: { className?: string }) => {
|
||||
)
|
||||
|
||||
return (
|
||||
<div ref={containerRef} className={cn("size-20", className)}>
|
||||
<div ref={containerRef} className={cn("size-16", className)}>
|
||||
<Spline scene={resolvedAIIconUrl} onLoad={handleLoad} className="size-full" />
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -19,7 +19,6 @@ import { useActionLanguage } from "~/atoms/settings/general"
|
||||
import { ROUTE_FEED_IN_FOLDER } from "~/constants"
|
||||
import { getRouteParams } from "~/hooks/biz/useRouteParams"
|
||||
import { useAutoScroll } from "~/modules/ai-chat/hooks/useAutoScroll"
|
||||
import { useAutoTimelineSummaryShortcut } from "~/modules/ai-chat/hooks/useAutoTimelineSummaryShortcut"
|
||||
import { useLoadMessages } from "~/modules/ai-chat/hooks/useLoadMessages"
|
||||
import { useMainEntryId } from "~/modules/ai-chat/hooks/useMainEntryId"
|
||||
import {
|
||||
@@ -51,8 +50,6 @@ const ChatInterfaceContent = ({ centerInputOnEmpty }: ChatInterfaceProps) => {
|
||||
const error = useChatError()
|
||||
const messages = useMessages()
|
||||
|
||||
useAutoTimelineSummaryShortcut()
|
||||
|
||||
const isFocusWithIn = useFocusable()
|
||||
|
||||
const aiPanelRefs = use(AIPanelRefsContext)
|
||||
|
||||
-329
@@ -1,329 +0,0 @@
|
||||
import { convertLexicalToMarkdown } from "@follow/components/ui/lexical-rich-editor/utils.js"
|
||||
import { FeedViewType } from "@follow/constants"
|
||||
import { DEFAULT_SUMMARIZE_TIMELINE_SHORTCUT_ID } from "@follow/shared/settings/defaults"
|
||||
import { getCategoryFeedIds } from "@follow/store/subscription/getter"
|
||||
import { asyncableNextFrame } from "@follow/utils"
|
||||
import type { LexicalEditor } from "lexical"
|
||||
import { $createParagraphNode, $getRoot, createEditor } from "lexical"
|
||||
import { nanoid } from "nanoid"
|
||||
import { useEffect, useMemo, useRef } from "react"
|
||||
|
||||
import { useIsInMASReview } from "~/atoms/server-configs"
|
||||
import { getShortcutEffectivePrompt, useAISettingValue } from "~/atoms/settings/ai"
|
||||
import { useGeneralSettingKey } from "~/atoms/settings/general"
|
||||
import { ROUTE_FEED_IN_FOLDER, ROUTE_FEED_PENDING } from "~/constants"
|
||||
import { useRouteParamsSelector } from "~/hooks/biz/useRouteParams"
|
||||
|
||||
import { AI_CHAT_SPECIAL_ID_PREFIX } from "../constants"
|
||||
import { LexicalAIEditorNodes, ShortcutNode } from "../editor"
|
||||
import { AIPersistService } from "../services"
|
||||
import { useAIChatStore } from "../store/AIChatContext"
|
||||
import { useBlockActions, useChatActions, useCurrentChatId } from "../store/hooks"
|
||||
import { BlockSliceAction } from "../store/slices/block.slice"
|
||||
import type { AIChatContextBlock, SendingUIMessage } from "../store/types"
|
||||
import { isTimelineSummaryAutoContext } from "./useTimelineSummaryAutoContext"
|
||||
|
||||
const INTERVAL = 5 * 60 * 60 * 1000
|
||||
|
||||
const buildSummaryMessage = (
|
||||
editor: LexicalEditor,
|
||||
contextBlocks: AIChatContextBlock[],
|
||||
messageId: string,
|
||||
): SendingUIMessage => {
|
||||
const parts: SendingUIMessage["parts"] = []
|
||||
|
||||
if (contextBlocks.length > 0) {
|
||||
parts.push({
|
||||
type: "data-block",
|
||||
data: contextBlocks,
|
||||
})
|
||||
}
|
||||
|
||||
parts.push({
|
||||
type: "data-rich-text",
|
||||
data: {
|
||||
state: JSON.stringify(editor.getEditorState().toJSON()),
|
||||
text: convertLexicalToMarkdown(editor),
|
||||
},
|
||||
})
|
||||
|
||||
return {
|
||||
id: messageId,
|
||||
role: "user",
|
||||
parts,
|
||||
}
|
||||
}
|
||||
|
||||
const buildTimelineSummaryChatId = ({
|
||||
view,
|
||||
feedId,
|
||||
timelineId,
|
||||
unreadOnly,
|
||||
seed,
|
||||
}: {
|
||||
view: number
|
||||
feedId: string
|
||||
timelineId?: string | null
|
||||
unreadOnly: boolean
|
||||
seed: string
|
||||
}) => {
|
||||
const normalizedTimelineId = timelineId ?? "all"
|
||||
const unreadSegment = unreadOnly ? "unread" : "all"
|
||||
const prefix = AI_CHAT_SPECIAL_ID_PREFIX.TIMELINE_SUMMARY
|
||||
return `${prefix}${view}:${feedId}:${normalizedTimelineId}:${unreadSegment}:${seed}`
|
||||
}
|
||||
|
||||
export const useAutoTimelineSummaryShortcut = () => {
|
||||
const aiSettings = useAISettingValue()
|
||||
const unreadOnly = useGeneralSettingKey("unreadOnly")
|
||||
const isInMASReview = useIsInMASReview()
|
||||
|
||||
const { view, feedId, entryId, timelineId } = useRouteParamsSelector((params) => ({
|
||||
view: params.view,
|
||||
feedId: params.feedId,
|
||||
entryId: params.entryId,
|
||||
timelineId: params.timelineId,
|
||||
}))
|
||||
|
||||
const chatActions = useChatActions()
|
||||
const blockActions = useBlockActions()
|
||||
const currentChatId = useCurrentChatId()
|
||||
const timelineSummaryManualOverride = useAIChatStore()(
|
||||
(state) => state.timelineSummaryManualOverride,
|
||||
)
|
||||
const timelineSummaryWasInAutoContext = useAIChatStore()(
|
||||
(state) => state.timelineSummaryWasInAutoContext,
|
||||
)
|
||||
const setTimelineSummaryWasInAutoContext = useAIChatStore()(
|
||||
(state) => state.chatActions.setTimelineSummaryWasInAutoContext,
|
||||
)
|
||||
|
||||
const automationStateRef = useRef<{
|
||||
contextKey: string | null
|
||||
promise: Promise<void> | null
|
||||
failed: boolean
|
||||
}>({
|
||||
contextKey: null,
|
||||
promise: null,
|
||||
failed: false,
|
||||
})
|
||||
const previousContextKeyRef = useRef<string | null>(null)
|
||||
|
||||
const isAllTimeline = isTimelineSummaryAutoContext({ entryId })
|
||||
|
||||
const defaultShortcut = useMemo(() => {
|
||||
const shortcuts = aiSettings.shortcuts ?? []
|
||||
return shortcuts.find(
|
||||
(shortcut) => shortcut.id === DEFAULT_SUMMARIZE_TIMELINE_SHORTCUT_ID && shortcut.enabled,
|
||||
)
|
||||
}, [aiSettings.shortcuts])
|
||||
|
||||
const normalizedFeedId = feedId ?? ROUTE_FEED_PENDING
|
||||
|
||||
const contextKey = useMemo(() => {
|
||||
if (!isAllTimeline) return null
|
||||
const keyParts = [
|
||||
`timeline:${timelineId ?? "all"}`,
|
||||
`feed:${normalizedFeedId}`,
|
||||
`unread:${unreadOnly ? "1" : "0"}`,
|
||||
]
|
||||
return keyParts.join("|")
|
||||
}, [isAllTimeline, timelineId, normalizedFeedId, unreadOnly])
|
||||
|
||||
useEffect(() => {
|
||||
if (previousContextKeyRef.current !== contextKey) {
|
||||
chatActions.setTimelineSummaryManualOverride(false)
|
||||
previousContextKeyRef.current = contextKey
|
||||
}
|
||||
}, [chatActions, contextKey])
|
||||
|
||||
useEffect(() => {
|
||||
if (
|
||||
timelineSummaryWasInAutoContext &&
|
||||
!isAllTimeline &&
|
||||
currentChatId &&
|
||||
currentChatId.startsWith(AI_CHAT_SPECIAL_ID_PREFIX.TIMELINE_SUMMARY)
|
||||
) {
|
||||
blockActions.clearBlocks({ keepSpecialTypes: true })
|
||||
chatActions.newChat()
|
||||
}
|
||||
setTimelineSummaryWasInAutoContext(isAllTimeline)
|
||||
}, [
|
||||
blockActions,
|
||||
chatActions,
|
||||
currentChatId,
|
||||
isAllTimeline,
|
||||
setTimelineSummaryWasInAutoContext,
|
||||
timelineSummaryWasInAutoContext,
|
||||
])
|
||||
|
||||
const contextBlocks = useMemo<AIChatContextBlock[]>(() => {
|
||||
if (!isAllTimeline) return []
|
||||
|
||||
const blocks: AIChatContextBlock[] = []
|
||||
|
||||
if (typeof view === "number") {
|
||||
blocks.push({
|
||||
id: BlockSliceAction.SPECIAL_TYPES.mainView,
|
||||
type: "mainView",
|
||||
value: `${view}`,
|
||||
})
|
||||
}
|
||||
|
||||
if (normalizedFeedId && normalizedFeedId !== ROUTE_FEED_PENDING) {
|
||||
let value = normalizedFeedId
|
||||
if (normalizedFeedId.startsWith(ROUTE_FEED_IN_FOLDER)) {
|
||||
const categoryName = normalizedFeedId.slice(ROUTE_FEED_IN_FOLDER.length)
|
||||
const ids = getCategoryFeedIds(categoryName, FeedViewType.All)
|
||||
if (ids.length > 0) {
|
||||
value = ids.join(",")
|
||||
}
|
||||
}
|
||||
|
||||
blocks.push({
|
||||
id: BlockSliceAction.SPECIAL_TYPES.mainFeed,
|
||||
type: "mainFeed",
|
||||
value,
|
||||
})
|
||||
}
|
||||
|
||||
if (unreadOnly) {
|
||||
blocks.push({
|
||||
id: BlockSliceAction.SPECIAL_TYPES.unreadOnly,
|
||||
type: "unreadOnly",
|
||||
value: "true",
|
||||
})
|
||||
}
|
||||
|
||||
return blocks
|
||||
}, [isAllTimeline, normalizedFeedId, unreadOnly, view])
|
||||
|
||||
useEffect(() => {
|
||||
if (isInMASReview) {
|
||||
return
|
||||
}
|
||||
|
||||
if (!contextKey || !defaultShortcut) {
|
||||
if (!contextKey) {
|
||||
automationStateRef.current = { contextKey: null, promise: null, failed: false }
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if (automationStateRef.current.contextKey !== contextKey) {
|
||||
automationStateRef.current = {
|
||||
contextKey,
|
||||
promise: null,
|
||||
failed: false,
|
||||
}
|
||||
} else {
|
||||
if (automationStateRef.current.promise) {
|
||||
return
|
||||
}
|
||||
if (automationStateRef.current.failed) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if (timelineSummaryManualOverride) {
|
||||
return
|
||||
}
|
||||
|
||||
const run = async () => {
|
||||
try {
|
||||
const prompt = getShortcutEffectivePrompt(defaultShortcut)
|
||||
const { id, name } = defaultShortcut
|
||||
|
||||
const existingSession = await AIPersistService.findTimelineSummarySession({
|
||||
view,
|
||||
feedId: normalizedFeedId,
|
||||
timelineId: timelineId ?? null,
|
||||
unreadOnly,
|
||||
})
|
||||
const now = Date.now()
|
||||
|
||||
if (existingSession) {
|
||||
const lastUpdatedAt = existingSession.updatedAt?.getTime?.() ?? existingSession.updatedAt
|
||||
if (typeof lastUpdatedAt === "number" && now - lastUpdatedAt < INTERVAL) {
|
||||
if (currentChatId !== existingSession.chatId) {
|
||||
await chatActions.switchToChat(existingSession.chatId)
|
||||
}
|
||||
automationStateRef.current.failed = false
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
const timelineSummaryChatId = buildTimelineSummaryChatId({
|
||||
view,
|
||||
feedId: normalizedFeedId,
|
||||
timelineId: timelineId ?? null,
|
||||
unreadOnly,
|
||||
seed: nanoid(6),
|
||||
})
|
||||
|
||||
await AIPersistService.ensureSession(timelineSummaryChatId, {
|
||||
title: "Timeline Summary",
|
||||
})
|
||||
|
||||
await chatActions.switchToChat(timelineSummaryChatId)
|
||||
|
||||
await asyncableNextFrame(async () => {
|
||||
// wait switch to chat completed
|
||||
if (chatActions.get().chatId !== timelineSummaryChatId) {
|
||||
return
|
||||
}
|
||||
blockActions.clearBlocks({ keepSpecialTypes: true })
|
||||
|
||||
const tempEditor = createEditor({
|
||||
nodes: LexicalAIEditorNodes,
|
||||
})
|
||||
|
||||
tempEditor.update(
|
||||
() => {
|
||||
const root = $getRoot()
|
||||
root.clear()
|
||||
const paragraph = $createParagraphNode()
|
||||
const shortcutNode = new ShortcutNode({ id, name, prompt })
|
||||
paragraph.append(shortcutNode)
|
||||
root.append(paragraph)
|
||||
},
|
||||
{
|
||||
discrete: true,
|
||||
},
|
||||
)
|
||||
|
||||
const message = buildSummaryMessage(tempEditor, contextBlocks, nanoid())
|
||||
|
||||
await chatActions.sendMessage(message, {
|
||||
body: { scene: "general" },
|
||||
})
|
||||
|
||||
automationStateRef.current.failed = false
|
||||
})
|
||||
} catch (error) {
|
||||
automationStateRef.current.failed = true
|
||||
console.error("[AI Chat] Failed to auto-run timeline summary shortcut:", error)
|
||||
} finally {
|
||||
if (automationStateRef.current.contextKey === contextKey) {
|
||||
automationStateRef.current.promise = null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const promise = run()
|
||||
automationStateRef.current.promise = promise
|
||||
}, [
|
||||
blockActions,
|
||||
chatActions,
|
||||
contextBlocks,
|
||||
contextKey,
|
||||
currentChatId,
|
||||
defaultShortcut,
|
||||
normalizedFeedId,
|
||||
timelineId,
|
||||
unreadOnly,
|
||||
view,
|
||||
timelineSummaryManualOverride,
|
||||
isInMASReview,
|
||||
])
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
import { convertLexicalToMarkdown } from "@follow/components/ui/lexical-rich-editor/utils.js"
|
||||
import { DEFAULT_SUMMARIZE_TIMELINE_SHORTCUT_ID } from "@follow/shared/settings/defaults"
|
||||
import { getCategoryFeedIds } from "@follow/store/subscription/getter"
|
||||
import type { EditorState } from "lexical"
|
||||
import { $createParagraphNode, $getRoot, createEditor } from "lexical"
|
||||
import { nanoid } from "nanoid"
|
||||
import { useCallback, useMemo } from "react"
|
||||
|
||||
import {
|
||||
getShortcutEffectivePrompt,
|
||||
setAIPanelVisibility,
|
||||
useAISettingKey,
|
||||
} from "~/atoms/settings/ai"
|
||||
import { ROUTE_FEED_IN_FOLDER } from "~/constants"
|
||||
import { getRouteParams } from "~/hooks/biz/useRouteParams"
|
||||
import type { ShortcutData } from "~/modules/ai-chat/editor"
|
||||
import { LexicalAIEditorNodes, ShortcutNode } from "~/modules/ai-chat/editor"
|
||||
import { useBlockActions, useChatActions } from "~/modules/ai-chat/store/hooks"
|
||||
import type { AIChatContextBlock, SendingUIMessage } from "~/modules/ai-chat/store/types"
|
||||
|
||||
export const useSummarizeTimeline = () => {
|
||||
const shortcuts = useAISettingKey("shortcuts")
|
||||
const chatActions = useChatActions()
|
||||
const blockActions = useBlockActions()
|
||||
|
||||
const defaultSummarizeShortcut = useMemo<ShortcutData | null>(() => {
|
||||
const allShortcuts = shortcuts ?? []
|
||||
const shortcut = allShortcuts.find(
|
||||
(item) => item.id === DEFAULT_SUMMARIZE_TIMELINE_SHORTCUT_ID && item.enabled,
|
||||
)
|
||||
|
||||
if (!shortcut) {
|
||||
return null
|
||||
}
|
||||
|
||||
const prompt = getShortcutEffectivePrompt(shortcut).trim()
|
||||
if (!prompt) {
|
||||
return null
|
||||
}
|
||||
|
||||
return {
|
||||
id: shortcut.id,
|
||||
name: shortcut.name || "Summarize timeline",
|
||||
prompt,
|
||||
hotkey: shortcut.hotkey,
|
||||
displayTargets: shortcut.displayTargets,
|
||||
}
|
||||
}, [shortcuts])
|
||||
|
||||
const staticEditor = useMemo(() => {
|
||||
return createEditor({
|
||||
nodes: LexicalAIEditorNodes,
|
||||
})
|
||||
}, [])
|
||||
|
||||
const createShortcutEditorState = useCallback((shortcutData: ShortcutData): EditorState => {
|
||||
const tempEditor = createEditor({
|
||||
nodes: LexicalAIEditorNodes,
|
||||
})
|
||||
|
||||
tempEditor.update(
|
||||
() => {
|
||||
const root = $getRoot()
|
||||
root.clear()
|
||||
const paragraph = $createParagraphNode()
|
||||
const shortcutNode = new ShortcutNode(shortcutData)
|
||||
paragraph.append(shortcutNode)
|
||||
root.append(paragraph)
|
||||
},
|
||||
{
|
||||
discrete: true,
|
||||
},
|
||||
)
|
||||
|
||||
return tempEditor.getEditorState()
|
||||
}, [])
|
||||
|
||||
const buildContextBlocks = useCallback((): AIChatContextBlock[] => {
|
||||
const blocks: AIChatContextBlock[] = []
|
||||
|
||||
for (const block of blockActions.getBlocks()) {
|
||||
if (block.type === "fileAttachment" && block.attachment.serverUrl) {
|
||||
blocks.push({
|
||||
...block,
|
||||
attachment: {
|
||||
id: block.attachment.id,
|
||||
name: block.attachment.name,
|
||||
type: block.attachment.type,
|
||||
size: block.attachment.size,
|
||||
serverUrl: block.attachment.serverUrl,
|
||||
},
|
||||
})
|
||||
} else if (block.type === "mainFeed" && block.value.startsWith(ROUTE_FEED_IN_FOLDER)) {
|
||||
const categoryName = block.value.slice(ROUTE_FEED_IN_FOLDER.length)
|
||||
const { view } = getRouteParams()
|
||||
const feedIds = getCategoryFeedIds(categoryName, view)
|
||||
blocks.push({
|
||||
...block,
|
||||
value: feedIds.join(","),
|
||||
})
|
||||
} else {
|
||||
blocks.push(block)
|
||||
}
|
||||
}
|
||||
|
||||
return blocks.filter((block) => !block.disabled)
|
||||
}, [blockActions])
|
||||
|
||||
const sendShortcutMessage = useCallback(
|
||||
(editorState: EditorState) => {
|
||||
const contextBlocks = buildContextBlocks()
|
||||
|
||||
staticEditor.setEditorState(editorState)
|
||||
|
||||
const parts: SendingUIMessage["parts"] = [
|
||||
{
|
||||
type: "data-block",
|
||||
data: contextBlocks,
|
||||
},
|
||||
{
|
||||
type: "data-rich-text",
|
||||
data: {
|
||||
state: JSON.stringify(editorState.toJSON()),
|
||||
text: convertLexicalToMarkdown(staticEditor),
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
const message: SendingUIMessage = {
|
||||
parts,
|
||||
role: "user",
|
||||
id: nanoid(),
|
||||
}
|
||||
|
||||
void chatActions.sendMessage(message)
|
||||
},
|
||||
[buildContextBlocks, chatActions, staticEditor],
|
||||
)
|
||||
|
||||
const summarizeTimeline = useCallback(() => {
|
||||
setAIPanelVisibility(true)
|
||||
|
||||
if (!defaultSummarizeShortcut) {
|
||||
return
|
||||
}
|
||||
|
||||
void (async () => {
|
||||
await chatActions.newChat()
|
||||
const editorState = createShortcutEditorState(defaultSummarizeShortcut)
|
||||
sendShortcutMessage(editorState)
|
||||
})()
|
||||
}, [chatActions, createShortcutEditorState, defaultSummarizeShortcut, sendShortcutMessage])
|
||||
|
||||
return {
|
||||
summarizeTimeline,
|
||||
hasSummarizeShortcut: !!defaultSummarizeShortcut,
|
||||
}
|
||||
}
|
||||
+3
-15
@@ -9,12 +9,7 @@ import type { CSSProperties } from "react"
|
||||
import { memo, useCallback, useEffect, useMemo, useRef } from "react"
|
||||
import { useResizable } from "react-resizable-layout"
|
||||
|
||||
import {
|
||||
AIChatPanelStyle,
|
||||
setAIPanelVisibility,
|
||||
useAIChatPanelStyle,
|
||||
useAIPanelVisibility,
|
||||
} from "~/atoms/settings/ai"
|
||||
import { AIChatPanelStyle, useAIChatPanelStyle, useAIPanelVisibility } from "~/atoms/settings/ai"
|
||||
import { getUISettings, setUISetting, useUISettingKey } from "~/atoms/settings/ui"
|
||||
import { m } from "~/components/common/Motion"
|
||||
import { ROUTE_ENTRY_PENDING } from "~/constants"
|
||||
@@ -122,16 +117,9 @@ const AIEnhancedTimelineLayoutImpl = () => {
|
||||
window.dispatchEvent(new Event("resize"))
|
||||
}, [resolvePreferredWidth, setAiPanelWidth])
|
||||
|
||||
useEffect(() => {
|
||||
if (isAllView && !isAIPanelVisible) {
|
||||
setAIPanelVisibility(true)
|
||||
}
|
||||
}, [isAllView, isAIPanelVisible])
|
||||
|
||||
const effectivePanelStyle = isAllView ? AIChatPanelStyle.Fixed : aiPanelStyle
|
||||
const showEntryContentOnRight = showEntryDetailsColumn && hasSelectedEntry
|
||||
const isFixedPanelStyle = effectivePanelStyle === AIChatPanelStyle.Fixed
|
||||
const shouldShowFixedAI = isAllView || (isFixedPanelStyle && isAIPanelVisible)
|
||||
const isFixedPanelStyle = aiPanelStyle === AIChatPanelStyle.Fixed
|
||||
const shouldShowFixedAI = isFixedPanelStyle && isAIPanelVisible
|
||||
const showEntryContentOnLeft = !showEntryDetailsColumn && hasSelectedEntry
|
||||
|
||||
const shouldRenderRightColumn = showEntryDetailsColumn || shouldShowFixedAI
|
||||
|
||||
+4
-1
@@ -1,8 +1,11 @@
|
||||
import { AnimatePresence, LayoutGroup, m } from "motion/react"
|
||||
|
||||
import { useSummarizeTimeline } from "~/modules/ai-chat/hooks/useSummarizeTimeline"
|
||||
import { EntryPlaceholderLogo } from "~/modules/entry-content/components/EntryPlaceholderLogo"
|
||||
|
||||
export const EntryContentPlaceholder = () => {
|
||||
const { summarizeTimeline } = useSummarizeTimeline()
|
||||
|
||||
return (
|
||||
<LayoutGroup>
|
||||
<AnimatePresence>
|
||||
@@ -11,7 +14,7 @@ export const EntryContentPlaceholder = () => {
|
||||
initial={{ opacity: 0.01, y: 300 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
>
|
||||
<EntryPlaceholderLogo />
|
||||
<EntryPlaceholderLogo onAskAI={summarizeTimeline} />
|
||||
</m.div>
|
||||
</AnimatePresence>
|
||||
</LayoutGroup>
|
||||
|
||||
@@ -18,8 +18,10 @@ import { previewBackPath } from "~/atoms/preview"
|
||||
import { useGeneralSettingKey } from "~/atoms/settings/general"
|
||||
import { useSubscriptionColumnShow } from "~/atoms/sidebar"
|
||||
import { ROUTE_ENTRY_PENDING } from "~/constants"
|
||||
import { useFeature } from "~/hooks/biz/useFeature"
|
||||
import { useFollow } from "~/hooks/biz/useFollow"
|
||||
import { getRouteParams, useRouteParams } from "~/hooks/biz/useRouteParams"
|
||||
import { useSummarizeTimeline } from "~/modules/ai-chat/hooks/useSummarizeTimeline"
|
||||
import { COMMAND_ID } from "~/modules/command/commands/id"
|
||||
import { useRunCommandFn } from "~/modules/command/hooks/use-command"
|
||||
import { useCommandShortcut } from "~/modules/command/hooks/use-command-binding"
|
||||
@@ -43,9 +45,11 @@ export const EntryListHeader: FC<{
|
||||
const { t } = useTranslation()
|
||||
|
||||
const unreadOnly = useGeneralSettingKey("unreadOnly")
|
||||
const aiEnabled = useFeature("ai")
|
||||
|
||||
const { feedId, entryId, view, isCollection } = routerParams
|
||||
const isPreview = useIsPreviewFeed()
|
||||
const isWideMode = !!getView(view)?.wideMode
|
||||
|
||||
const headerTitle = useFeedHeaderTitle()
|
||||
const feedIcon = useFeedHeaderIcon()
|
||||
@@ -86,6 +90,10 @@ export const EntryListHeader: FC<{
|
||||
|
||||
const { isScrolledBeyondThreshold } = useEntryRootState()
|
||||
const isScrolledBeyondThresholdValue = useAtomValue(isScrolledBeyondThreshold)
|
||||
const { summarizeTimeline } = useSummarizeTimeline()
|
||||
const showEntryHeader = isWideMode && !!entryId && entryId !== ROUTE_ENTRY_PENDING
|
||||
const showTimelineSummaryButton = isWideMode && aiEnabled
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
@@ -112,9 +120,17 @@ export const EntryListHeader: FC<{
|
||||
)}
|
||||
onClick={stopPropagation}
|
||||
>
|
||||
{getView(view)?.wideMode && entryId && entryId !== ROUTE_ENTRY_PENDING && (
|
||||
{isWideMode && (showEntryHeader || showTimelineSummaryButton) && (
|
||||
<>
|
||||
<EntryHeader entryId={entryId} />
|
||||
{showEntryHeader && <EntryHeader entryId={entryId} />}
|
||||
{showTimelineSummaryButton && (
|
||||
<ActionButton
|
||||
tooltip={t("entry_list_header.timeline_summary")}
|
||||
onClick={summarizeTimeline}
|
||||
>
|
||||
<i className="i-mingcute-ai-line text-purple-600 dark:text-purple-400" />
|
||||
</ActionButton>
|
||||
)}
|
||||
<DividerVertical className="mx-2 w-px" />
|
||||
</>
|
||||
)}
|
||||
|
||||
+40
-2
@@ -1,10 +1,28 @@
|
||||
import { Logo } from "@follow/components/icons/logo.jsx"
|
||||
import { MotionButtonBase } from "@follow/components/ui/button/index.js"
|
||||
import { stopPropagation } from "@follow/utils/dom"
|
||||
import { cn } from "@follow/utils/utils"
|
||||
|
||||
import { setAIPanelVisibility } from "~/atoms/settings/ai"
|
||||
import { useFeature } from "~/hooks/biz/useFeature"
|
||||
import { useFeedHeaderTitle } from "~/store/feed/hooks"
|
||||
|
||||
export const EntryPlaceholderLogo = () => {
|
||||
interface EntryPlaceholderLogoProps {
|
||||
onAskAI?: () => void
|
||||
}
|
||||
|
||||
export const EntryPlaceholderLogo = ({ onAskAI }: EntryPlaceholderLogoProps) => {
|
||||
const title = useFeedHeaderTitle()
|
||||
const aiEnabled = useFeature("ai")
|
||||
|
||||
const handleAskAI = () => {
|
||||
if (onAskAI) {
|
||||
onAskAI()
|
||||
return
|
||||
}
|
||||
|
||||
setAIPanelVisibility(true)
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
@@ -14,8 +32,28 @@ export const EntryPlaceholderLogo = () => {
|
||||
"flex w-full min-w-0 flex-col items-center justify-center gap-2 px-12 pb-6 text-center text-lg font-medium text-text-secondary duration-500"
|
||||
}
|
||||
>
|
||||
<Logo className="size-16 opacity-40 grayscale" />
|
||||
<Logo className="size-14 opacity-40 grayscale" />
|
||||
<div className="line-clamp-3 w-[60ch] max-w-full opacity-70">{title}</div>
|
||||
|
||||
{aiEnabled && (
|
||||
<MotionButtonBase
|
||||
onClick={handleAskAI}
|
||||
className={cn(
|
||||
"mt-8 flex h-10 items-center gap-1.5 rounded-xl px-4 text-sm font-medium",
|
||||
"bg-gradient-to-r from-purple-500/10 to-blue-500/10",
|
||||
"border border-purple-200/30 dark:border-purple-800/30",
|
||||
"text-purple-600 dark:text-purple-400",
|
||||
"hover:from-purple-500/20 hover:to-blue-500/20",
|
||||
"hover:border-purple-300/50 dark:hover:border-purple-700/50",
|
||||
"transition-all duration-200",
|
||||
"backdrop-blur-sm",
|
||||
"sm:duration-300 sm:group-hover:translate-y-0",
|
||||
)}
|
||||
>
|
||||
<i className="i-mingcute-ai-line text-base" />
|
||||
<span>Summarize the current timeline</span>
|
||||
</MotionButtonBase>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -481,7 +481,7 @@ const PlanComparisonTable = ({ plans }: { plans: PaymentPlan[] }) => {
|
||||
<table className="w-full">
|
||||
<thead>
|
||||
<tr className="border-b border-fill-tertiary bg-fill-secondary/50">
|
||||
<th className="sticky left-0 z-10 bg-fill-secondary/50 px-4 py-3 text-left text-sm font-semibold">
|
||||
<th className="sticky left-0 z-10 w-48 bg-fill-secondary/50 px-4 py-3 text-left text-sm font-semibold">
|
||||
Features
|
||||
</th>
|
||||
{plans.map((plan) => (
|
||||
|
||||
@@ -187,6 +187,7 @@
|
||||
"entry_list_header.refresh": "Refresh",
|
||||
"entry_list_header.show_all": "Show all",
|
||||
"entry_list_header.show_unread_only": "Show unread Only",
|
||||
"entry_list_header.timeline_summary": "Summarize timeline",
|
||||
"entry_list_header.unread": "unread",
|
||||
"feed.actions.follow": "Follow",
|
||||
"feed.actions.followed": "Followed",
|
||||
|
||||
@@ -186,6 +186,7 @@
|
||||
"entry_list_header.refresh": "更新",
|
||||
"entry_list_header.show_all": "すべて表示",
|
||||
"entry_list_header.show_unread_only": "未読のみ表示",
|
||||
"entry_list_header.timeline_summary": "タイムラインを要約",
|
||||
"entry_list_header.unread": "未読",
|
||||
"feed.actions.follow": "フォロー",
|
||||
"feed.actions.followed": "フォロー済み",
|
||||
|
||||
@@ -186,6 +186,7 @@
|
||||
"entry_list_header.refresh": "刷新",
|
||||
"entry_list_header.show_all": "显示全部",
|
||||
"entry_list_header.show_unread_only": "仅显示未读",
|
||||
"entry_list_header.timeline_summary": "总结时间线",
|
||||
"entry_list_header.unread": "未读",
|
||||
"feed.actions.follow": "订阅",
|
||||
"feed.actions.followed": "已订阅",
|
||||
|
||||
@@ -184,6 +184,7 @@
|
||||
"entry_list_header.refresh": "重新整理",
|
||||
"entry_list_header.show_all": "顯示全部",
|
||||
"entry_list_header.show_unread_only": "僅顯示未讀",
|
||||
"entry_list_header.timeline_summary": "摘要時間線",
|
||||
"entry_list_header.unread": "未讀",
|
||||
"feed.actions.follow": "跟隨",
|
||||
"feed.actions.followed": "已跟隨",
|
||||
|
||||
Reference in New Issue
Block a user