feat: add unread only context
This commit is contained in:
+41
-7
@@ -75,33 +75,58 @@ type ValueBlockOf<Type extends ValueContextBlock["type"]> = Omit<ValueContextBlo
|
||||
|
||||
type MainViewBlock = ValueBlockOf<"mainView">
|
||||
type MainFeedBlock = ValueBlockOf<"mainFeed">
|
||||
type UnreadOnlyBlock = ValueBlockOf<"unreadOnly">
|
||||
|
||||
export const MainViewFeedContextBlock: FC<{
|
||||
export const CombinedContextBlock: FC<{
|
||||
viewBlock: MainViewBlock
|
||||
feedBlock: MainFeedBlock
|
||||
}> = memo(({ viewBlock, feedBlock }) => {
|
||||
feedBlock?: MainFeedBlock
|
||||
unreadOnlyBlock?: UnreadOnlyBlock
|
||||
}> = memo(({ viewBlock, feedBlock, unreadOnlyBlock }) => {
|
||||
const { t } = useTranslation("common")
|
||||
const blockActions = useChatBlockActions()
|
||||
|
||||
const viewIcon = views.find((v) => v.view === Number(viewBlock.value))?.icon.props.className
|
||||
|
||||
const canRemove =
|
||||
!blockTypeCanNotBeRemoved.has(viewBlock.type) && !blockTypeCanNotBeRemoved.has(feedBlock.type)
|
||||
!blockTypeCanNotBeRemoved.has(viewBlock.type) &&
|
||||
(!feedBlock || !blockTypeCanNotBeRemoved.has(feedBlock.type))
|
||||
|
||||
const handleRemove = () => {
|
||||
blockActions.removeBlock(viewBlock.id)
|
||||
blockActions.removeBlock(feedBlock.id)
|
||||
if (feedBlock) {
|
||||
blockActions.removeBlock(feedBlock.id)
|
||||
}
|
||||
if (unreadOnlyBlock) {
|
||||
blockActions.removeBlock(unreadOnlyBlock.id)
|
||||
}
|
||||
}
|
||||
|
||||
// Determine what to display
|
||||
const displayContent = feedBlock ? (
|
||||
<span className="flex items-center gap-1">
|
||||
<FeedTitle feedId={feedBlock.value} fallback={feedBlock.value} />
|
||||
{unreadOnlyBlock && <i className="i-mgc-round-cute-fi size-3" title="Unread Only" />}
|
||||
</span>
|
||||
) : (
|
||||
<span className="flex items-center gap-1">
|
||||
{(() => {
|
||||
const viewName = views.find((v) => v.view === Number(viewBlock.value))?.name
|
||||
return viewName ? t(viewName) : viewBlock.value
|
||||
})()}
|
||||
{unreadOnlyBlock && <i className="i-mgc-round-cute-fi size-3" title="Unread Only" />}
|
||||
</span>
|
||||
)
|
||||
|
||||
return (
|
||||
<BlockContainer
|
||||
icon={viewIcon}
|
||||
canRemove={canRemove}
|
||||
onRemove={handleRemove}
|
||||
content={<FeedTitle feedId={feedBlock.value} fallback={feedBlock.value} />}
|
||||
content={displayContent}
|
||||
/>
|
||||
)
|
||||
})
|
||||
MainViewFeedContextBlock.displayName = "MainViewFeedContextBlock"
|
||||
CombinedContextBlock.displayName = "CombinedContextBlock"
|
||||
|
||||
export const ContextBlock: FC<{ block: AIChatContextBlock }> = memo(({ block }) => {
|
||||
const { t } = useTranslation("common")
|
||||
@@ -125,6 +150,9 @@ export const ContextBlock: FC<{ block: AIChatContextBlock }> = memo(({ block })
|
||||
case "selectedText": {
|
||||
return "i-mgc-quill-pen-cute-re"
|
||||
}
|
||||
case "unreadOnly": {
|
||||
return "i-mgc-round-cute-fi"
|
||||
}
|
||||
case "fileAttachment": {
|
||||
const { type, dataUrl, previewUrl } = block.attachment
|
||||
const fileCategory = getFileCategoryFromMimeType(type)
|
||||
@@ -159,6 +187,9 @@ export const ContextBlock: FC<{ block: AIChatContextBlock }> = memo(({ block })
|
||||
case "selectedText": {
|
||||
return `"${block.value}"`
|
||||
}
|
||||
case "unreadOnly": {
|
||||
return "Unread Only"
|
||||
}
|
||||
case "fileAttachment": {
|
||||
const { type, name, dataUrl, previewUrl, uploadStatus, errorMessage, uploadProgress } =
|
||||
block.attachment
|
||||
@@ -255,6 +286,9 @@ export const ContextBlock: FC<{ block: AIChatContextBlock }> = memo(({ block })
|
||||
case "selectedText": {
|
||||
return "Text"
|
||||
}
|
||||
case "unreadOnly": {
|
||||
return "Filter"
|
||||
}
|
||||
case "fileAttachment": {
|
||||
return "File"
|
||||
}
|
||||
|
||||
+22
-2
@@ -2,6 +2,7 @@ import { cn } from "@follow/utils/utils"
|
||||
import { memo, useCallback, useEffect, useMemo, useRef } from "react"
|
||||
|
||||
import { useAISettingValue } from "~/atoms/settings/ai"
|
||||
import { useGeneralSettingKey } from "~/atoms/settings/general"
|
||||
import { DropdownMenu, DropdownMenuTrigger } from "~/components/ui/dropdown-menu/dropdown-menu"
|
||||
import { useRouteParamsSelector } from "~/hooks/biz/useRouteParams"
|
||||
import { useDisplayBlocks } from "~/modules/ai-chat/hooks/useDisplayBlocks"
|
||||
@@ -11,7 +12,7 @@ import { SUPPORTED_MIME_ACCEPT } from "~/modules/ai-chat/utils/file-validation"
|
||||
|
||||
import { useBlockActions } from "../../store/hooks"
|
||||
import { BlockSliceAction } from "../../store/slices/block.slice"
|
||||
import { ContextBlock, MainViewFeedContextBlock } from "../context-bar/blocks"
|
||||
import { CombinedContextBlock, ContextBlock } from "../context-bar/blocks"
|
||||
import { ContextMenuContent, ShortcutsMenuContent } from "../context-bar/menus"
|
||||
|
||||
export const AIChatContextBar: Component<{ onSendShortcut?: (prompt: string) => void }> = memo(
|
||||
@@ -71,6 +72,24 @@ export const AIChatContextBar: Component<{ onSendShortcut?: (prompt: string) =>
|
||||
}
|
||||
}, [addOrUpdateBlock, feedId, removeBlock])
|
||||
|
||||
// Add unreadOnly context block only when unreadOnly is enabled
|
||||
const unreadOnly = useGeneralSettingKey("unreadOnly")
|
||||
useEffect(() => {
|
||||
if (unreadOnly) {
|
||||
addOrUpdateBlock({
|
||||
id: BlockSliceAction.SPECIAL_TYPES.unreadOnly,
|
||||
type: "unreadOnly",
|
||||
value: "true",
|
||||
})
|
||||
} else {
|
||||
removeBlock(BlockSliceAction.SPECIAL_TYPES.unreadOnly)
|
||||
}
|
||||
|
||||
return () => {
|
||||
removeBlock(BlockSliceAction.SPECIAL_TYPES.unreadOnly)
|
||||
}
|
||||
}, [addOrUpdateBlock, unreadOnly, removeBlock])
|
||||
|
||||
const displayBlocks = useDisplayBlocks(blocks)
|
||||
|
||||
return (
|
||||
@@ -128,10 +147,11 @@ export const AIChatContextBar: Component<{ onSendShortcut?: (prompt: string) =>
|
||||
{displayBlocks.map((item) => {
|
||||
if (item.kind === "combined") {
|
||||
return (
|
||||
<MainViewFeedContextBlock
|
||||
<CombinedContextBlock
|
||||
key={item.viewBlock.id}
|
||||
viewBlock={item.viewBlock}
|
||||
feedBlock={item.feedBlock}
|
||||
unreadOnlyBlock={item.unreadOnlyBlock}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
+33
-10
@@ -24,9 +24,10 @@ type ValueBlockOf<Type extends ValueContextBlock["type"]> = Omit<ValueContextBlo
|
||||
type: Type
|
||||
}
|
||||
|
||||
interface MainViewFeedDataBlockItemProps {
|
||||
interface CombinedDataBlockItemProps {
|
||||
viewBlock: ValueBlockOf<"mainView">
|
||||
feedBlock: ValueBlockOf<"mainFeed">
|
||||
feedBlock?: ValueBlockOf<"mainFeed">
|
||||
unreadOnlyBlock?: ValueBlockOf<"unreadOnly">
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -48,6 +49,9 @@ const getDisplayContent = (block: AIChatContextBlock): React.ReactNode => {
|
||||
case "selectedText": {
|
||||
return `"${block.value}"`
|
||||
}
|
||||
case "unreadOnly": {
|
||||
return "Unread Only"
|
||||
}
|
||||
case "fileAttachment": {
|
||||
if (!block.attachment) {
|
||||
return "[File: Unknown]"
|
||||
@@ -153,21 +157,40 @@ export const AIDataBlockItem: React.FC<AIDataBlockItemProps> = React.memo(({ blo
|
||||
AIDataBlockItem.displayName = "AIDataBlockItem"
|
||||
|
||||
/**
|
||||
* Combined block item component for main view and main feed
|
||||
* Displays view icon with feed title content
|
||||
* Combined block item component for main view with optional feed and unread filter
|
||||
* Displays view icon with appropriate content based on available blocks
|
||||
*/
|
||||
export const MainViewFeedDataBlockItem: React.FC<MainViewFeedDataBlockItemProps> = React.memo(
|
||||
({ viewBlock, feedBlock }) => {
|
||||
export const CombinedDataBlockItem: React.FC<CombinedDataBlockItemProps> = React.memo(
|
||||
({ viewBlock, feedBlock, unreadOnlyBlock }) => {
|
||||
const { styles, displayContent, title } = React.useMemo(() => {
|
||||
const view = views.find((v) => v.view === Number(viewBlock.value))
|
||||
const viewName = view?.name ? t(view.name, { ns: "common" }) : viewBlock.value
|
||||
|
||||
const unreadOnlyText = unreadOnlyBlock ? " (Unread Only)" : ""
|
||||
|
||||
// Determine content based on whether feedBlock exists
|
||||
const content = feedBlock ? (
|
||||
<span className="flex items-center gap-1">
|
||||
<FeedTitle feedId={feedBlock.value} fallback={feedBlock.value} />
|
||||
{unreadOnlyBlock && <i className="i-mgc-round-cute-fi size-3" title="Unread Only" />}
|
||||
</span>
|
||||
) : (
|
||||
<span className="flex items-center gap-1">
|
||||
{viewName}
|
||||
{unreadOnlyBlock && <i className="i-mgc-round-cute-fi size-3" title="Unread Only" />}
|
||||
</span>
|
||||
)
|
||||
|
||||
const titleText = feedBlock
|
||||
? `${viewName} - ${feedBlock.value}${unreadOnlyText}`
|
||||
: `${viewName}${unreadOnlyText}`
|
||||
|
||||
return {
|
||||
styles: getBlockStyles("mainView"),
|
||||
displayContent: <FeedTitle feedId={feedBlock.value} fallback={feedBlock.value} />,
|
||||
title: `${viewName} - ${feedBlock.value}`,
|
||||
displayContent: content,
|
||||
title: titleText,
|
||||
}
|
||||
}, [viewBlock.value, feedBlock.value])
|
||||
}, [viewBlock.value, feedBlock, unreadOnlyBlock])
|
||||
|
||||
return (
|
||||
<BlockContainer
|
||||
@@ -180,4 +203,4 @@ export const MainViewFeedDataBlockItem: React.FC<MainViewFeedDataBlockItemProps>
|
||||
},
|
||||
)
|
||||
|
||||
MainViewFeedDataBlockItem.displayName = "MainViewFeedDataBlockItem"
|
||||
CombinedDataBlockItem.displayName = "CombinedDataBlockItem"
|
||||
|
||||
+3
-2
@@ -4,7 +4,7 @@ import * as React from "react"
|
||||
import { useDisplayBlocks } from "~/modules/ai-chat/hooks/useDisplayBlocks"
|
||||
import type { AIChatContextBlock } from "~/modules/ai-chat/store/types"
|
||||
|
||||
import { AIDataBlockItem, MainViewFeedDataBlockItem } from "./AIDataBlockItem"
|
||||
import { AIDataBlockItem, CombinedDataBlockItem } from "./AIDataBlockItem"
|
||||
|
||||
interface AIDataBlockPartProps {
|
||||
blocks: AIChatContextBlock[]
|
||||
@@ -40,10 +40,11 @@ export const AIDataBlockPart: React.FC<AIDataBlockPartProps> = React.memo(({ blo
|
||||
{displayBlocks.map((item, index) => {
|
||||
if (item.kind === "combined") {
|
||||
return (
|
||||
<MainViewFeedDataBlockItem
|
||||
<CombinedDataBlockItem
|
||||
key={item.viewBlock.id}
|
||||
viewBlock={item.viewBlock}
|
||||
feedBlock={item.feedBlock}
|
||||
unreadOnlyBlock={item.unreadOnlyBlock}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
+7
@@ -35,6 +35,11 @@ export const BLOCK_STYLES = {
|
||||
icon: "bg-pink/10 text-pink",
|
||||
label: "text-pink",
|
||||
},
|
||||
unreadOnly: {
|
||||
container: "from-green/5 to-green/10 border-green/20 hover:border-green/30",
|
||||
icon: "bg-green/10 text-green",
|
||||
label: "text-green",
|
||||
},
|
||||
} as const
|
||||
|
||||
/**
|
||||
@@ -55,6 +60,7 @@ export const BLOCK_ICONS = {
|
||||
referEntry: "i-mgc-paper-cute-fi",
|
||||
selectedText: "i-mgc-quill-pen-cute-re",
|
||||
fileAttachment: "i-mgc-file-upload-cute-re",
|
||||
unreadOnly: "i-mgc-round-cute-fi",
|
||||
} as const
|
||||
|
||||
/**
|
||||
@@ -67,6 +73,7 @@ export const BLOCK_LABELS = {
|
||||
selectedText: "Text",
|
||||
fileAttachment: "File",
|
||||
mainView: "View",
|
||||
unreadOnly: "Filter",
|
||||
} as const
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,7 +10,8 @@ export type DisplayBlockItem =
|
||||
| {
|
||||
kind: "combined"
|
||||
viewBlock: ValueBlockOf<"mainView">
|
||||
feedBlock: ValueBlockOf<"mainFeed">
|
||||
feedBlock?: ValueBlockOf<"mainFeed">
|
||||
unreadOnlyBlock?: ValueBlockOf<"unreadOnly">
|
||||
}
|
||||
| { kind: "single"; block: AIChatContextBlock }
|
||||
|
||||
@@ -31,14 +32,27 @@ export const useDisplayBlocks = (blocks: AIChatContextBlock[]): DisplayBlockItem
|
||||
const mainFeedBlock = blocks.find(
|
||||
(block): block is ValueBlockOf<"mainFeed"> => block.type === "mainFeed",
|
||||
)
|
||||
const unreadOnlyBlock = blocks.find(
|
||||
(block): block is ValueBlockOf<"unreadOnly"> => block.type === "unreadOnly",
|
||||
)
|
||||
|
||||
if (mainViewBlock && mainFeedBlock) {
|
||||
// Always filter out unreadOnly from single blocks since it should only appear in combined blocks
|
||||
const filteredBlocks = blocks.filter((block) => block.type !== "unreadOnly")
|
||||
|
||||
if (mainViewBlock) {
|
||||
const items: DisplayBlockItem[] = []
|
||||
|
||||
items.push({ kind: "combined", viewBlock: mainViewBlock, feedBlock: mainFeedBlock })
|
||||
// Create combined block with optional feedBlock
|
||||
items.push({
|
||||
kind: "combined",
|
||||
viewBlock: mainViewBlock,
|
||||
...(mainFeedBlock && { feedBlock: mainFeedBlock }),
|
||||
...(unreadOnlyBlock && { unreadOnlyBlock }),
|
||||
})
|
||||
|
||||
const otherBlocks = blocks.filter(
|
||||
(block) => block.id !== mainViewBlock.id && block.id !== mainFeedBlock.id,
|
||||
// Add other blocks (excluding mainView, mainFeed, and unreadOnly)
|
||||
const otherBlocks = filteredBlocks.filter(
|
||||
(block) => block.id !== mainViewBlock.id && block.id !== mainFeedBlock?.id,
|
||||
)
|
||||
otherBlocks.forEach((block) => {
|
||||
items.push({ kind: "single", block })
|
||||
@@ -47,6 +61,7 @@ export const useDisplayBlocks = (blocks: AIChatContextBlock[]): DisplayBlockItem
|
||||
return items
|
||||
}
|
||||
|
||||
return blocks.map((block) => ({ kind: "single" as const, block }))
|
||||
// If no mainView, show all blocks except unreadOnly
|
||||
return filteredBlocks.map((block) => ({ kind: "single" as const, block }))
|
||||
}, [blocks])
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ export class BlockSliceAction {
|
||||
mainEntry: "mainEntry",
|
||||
mainFeed: "mainFeed",
|
||||
selectedText: "selectedText",
|
||||
unreadOnly: "unreadOnly",
|
||||
}
|
||||
get set() {
|
||||
return this.params[0]
|
||||
|
||||
@@ -19,7 +19,7 @@ interface BaseContextBlock {
|
||||
}
|
||||
|
||||
export interface ValueContextBlock extends BaseContextBlock {
|
||||
type: "mainView" | "mainEntry" | "mainFeed" | "referEntry" | "selectedText"
|
||||
type: "mainView" | "mainEntry" | "mainFeed" | "referEntry" | "selectedText" | "unreadOnly"
|
||||
value: string
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user