refactor: remove referEntry and pickers
This commit is contained in:
+1
-8
@@ -140,9 +140,6 @@ export const ContextBlock: FC<{ block: AIChatContextBlock }> = memo(({ block })
|
||||
case "mainEntry": {
|
||||
return "i-mgc-star-cute-fi"
|
||||
}
|
||||
case "referEntry": {
|
||||
return "i-mgc-paper-cute-fi"
|
||||
}
|
||||
case "mainFeed": {
|
||||
return "i-mgc-rss-cute-fi"
|
||||
}
|
||||
@@ -176,8 +173,7 @@ export const ContextBlock: FC<{ block: AIChatContextBlock }> = memo(({ block })
|
||||
const viewName = getView(Number(block.value))?.name
|
||||
return viewName ? t(viewName) : block.value
|
||||
}
|
||||
case "mainEntry":
|
||||
case "referEntry": {
|
||||
case "mainEntry": {
|
||||
return <EntryTitle entryId={block.value} fallback={block.value} />
|
||||
}
|
||||
case "mainFeed": {
|
||||
@@ -279,9 +275,6 @@ export const ContextBlock: FC<{ block: AIChatContextBlock }> = memo(({ block })
|
||||
case "mainFeed": {
|
||||
return "Current"
|
||||
}
|
||||
case "referEntry": {
|
||||
return "Ref"
|
||||
}
|
||||
case "selectedText": {
|
||||
return "Text"
|
||||
}
|
||||
|
||||
@@ -1,3 +1,2 @@
|
||||
export * from "./blocks"
|
||||
export * from "./menus"
|
||||
export * from "./pickers"
|
||||
|
||||
-55
@@ -1,55 +0,0 @@
|
||||
import type { FC } from "react"
|
||||
|
||||
import {
|
||||
DropdownMenuContent,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuSub,
|
||||
DropdownMenuSubContent,
|
||||
DropdownMenuSubTrigger,
|
||||
} from "~/components/ui/dropdown-menu/dropdown-menu"
|
||||
import { useChatBlockActions } from "~/modules/ai-chat/store/hooks"
|
||||
|
||||
import { CurrentFeedEntriesPickerList, RecentEntriesPickerList } from "../pickers"
|
||||
|
||||
export const ContextMenuContent: FC = () => {
|
||||
const blockActions = useChatBlockActions()
|
||||
|
||||
return (
|
||||
<DropdownMenuContent align="start">
|
||||
<DropdownMenuSub>
|
||||
<DropdownMenuSubTrigger>
|
||||
<i className="i-mgc-paper-cute-fi mr-1.5 size-4" />
|
||||
Current Feed Entries
|
||||
</DropdownMenuSubTrigger>
|
||||
<DropdownMenuSubContent>
|
||||
<CurrentFeedEntriesPickerList
|
||||
onSelect={(entryId) =>
|
||||
blockActions.addBlock({
|
||||
type: "referEntry",
|
||||
value: entryId,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</DropdownMenuSubContent>
|
||||
</DropdownMenuSub>
|
||||
<DropdownMenuSeparator />
|
||||
|
||||
<DropdownMenuSub>
|
||||
<DropdownMenuSubTrigger>
|
||||
<i className="i-mgc-paper-cute-fi mr-1.5 size-4" />
|
||||
Reference Entry
|
||||
</DropdownMenuSubTrigger>
|
||||
<DropdownMenuSubContent>
|
||||
<RecentEntriesPickerList
|
||||
onSelect={(entryId) =>
|
||||
blockActions.addBlock({
|
||||
type: "referEntry",
|
||||
value: entryId,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</DropdownMenuSubContent>
|
||||
</DropdownMenuSub>
|
||||
</DropdownMenuContent>
|
||||
)
|
||||
}
|
||||
@@ -1,2 +1 @@
|
||||
export * from "./ContextMenuContent"
|
||||
export * from "./ShortcutsMenuContent"
|
||||
|
||||
-61
@@ -1,61 +0,0 @@
|
||||
import { getEntry } from "@follow/store/entry/getter"
|
||||
import { useEntryIdsByFeedId, useEntryIdsByView } from "@follow/store/entry/hooks"
|
||||
import { useEntryStore } from "@follow/store/entry/store"
|
||||
import type { FC } from "react"
|
||||
import { useMemo } from "react"
|
||||
|
||||
import { useRouteParamsSelector } from "~/hooks/biz/useRouteParams"
|
||||
import { useAIChatStore } from "~/modules/ai-chat/store/AIChatContext"
|
||||
|
||||
import type { PickerItem } from "./PickerList"
|
||||
import { PickerList } from "./PickerList"
|
||||
|
||||
export const CurrentFeedEntriesPickerList: FC<{ onSelect: (entryId: string) => void }> = ({
|
||||
onSelect,
|
||||
}) => {
|
||||
const mainFeedId = useAIChatStore()((s) => {
|
||||
const mainFeedBlock = s.blocks.find((b) => b.type === "mainFeed")
|
||||
const mainEntryBlock = s.blocks.find((b) => b.type === "mainEntry")
|
||||
return mainFeedBlock && mainFeedBlock.type === "mainFeed"
|
||||
? mainFeedBlock.value
|
||||
: mainEntryBlock && mainEntryBlock.type === "mainEntry"
|
||||
? getEntry(mainEntryBlock.value)?.feedId
|
||||
: null
|
||||
})
|
||||
const entryIds = useEntryIdsByFeedId(mainFeedId)
|
||||
|
||||
return <BaseEntryPickerList items={entryIds || []} onSelect={onSelect} />
|
||||
}
|
||||
|
||||
export const RecentEntriesPickerList: FC<{ onSelect: (entryId: string) => void }> = ({
|
||||
onSelect,
|
||||
}) => {
|
||||
const view = useRouteParamsSelector((route) => route.view)
|
||||
const recentEntryIds = useEntryIdsByView(view, false)
|
||||
|
||||
return <BaseEntryPickerList items={(recentEntryIds || []).slice(0, 20)} onSelect={onSelect} />
|
||||
}
|
||||
|
||||
const BaseEntryPickerList: FC<{ items: string[]; onSelect: (entryId: string) => void }> = ({
|
||||
items,
|
||||
onSelect,
|
||||
}) => {
|
||||
const entryStore = useEntryStore((state) => state.data)
|
||||
const entries = useMemo(() => {
|
||||
return items
|
||||
.map((entryId) => {
|
||||
const entry = entryStore[entryId]
|
||||
return entry ? { id: entryId, title: entry.title || "Untitled" } : null
|
||||
})
|
||||
.filter(Boolean) as PickerItem[]
|
||||
}, [items, entryStore])
|
||||
|
||||
return (
|
||||
<PickerList
|
||||
items={entries}
|
||||
placeholder="Search entries..."
|
||||
onSelect={onSelect}
|
||||
noResultsText="No entries found"
|
||||
/>
|
||||
)
|
||||
}
|
||||
-59
@@ -1,59 +0,0 @@
|
||||
import { getFeedById } from "@follow/store/feed/getter"
|
||||
import { useFeedById } from "@follow/store/feed/hooks"
|
||||
import { useAllFeedSubscription } from "@follow/store/subscription/hooks"
|
||||
import type { FC } from "react"
|
||||
import { useMemo } from "react"
|
||||
|
||||
import { DropdownMenuItem } from "~/components/ui/dropdown-menu/dropdown-menu"
|
||||
|
||||
import type { PickerItem } from "./PickerList"
|
||||
import { PickerList } from "./PickerList"
|
||||
|
||||
export const FeedPickerList: FC<{ onSelect: (feedId: string) => void }> = ({ onSelect }) => {
|
||||
const allSubscriptions = useAllFeedSubscription()
|
||||
|
||||
// Get feeds with their details
|
||||
const feeds = useMemo(() => {
|
||||
return allSubscriptions
|
||||
.filter((subscription) => subscription.feedId)
|
||||
.map((subscription) => {
|
||||
const customTitle = subscription.title
|
||||
|
||||
if (!subscription.feedId) return null
|
||||
const feed = getFeedById(subscription.feedId!)
|
||||
return {
|
||||
id: subscription.feedId!,
|
||||
title: customTitle || feed?.title || `Feed ${subscription.feedId}`,
|
||||
} as PickerItem
|
||||
})
|
||||
.filter(Boolean) as PickerItem[]
|
||||
}, [allSubscriptions])
|
||||
|
||||
return (
|
||||
<PickerList
|
||||
items={feeds}
|
||||
placeholder="Search feeds..."
|
||||
onSelect={onSelect}
|
||||
noResultsText="No feeds found"
|
||||
renderItem={(feed, onSelect) => (
|
||||
<FeedPickerItem key={feed.id} feedId={feed.id} title={feed.title} onSelect={onSelect} />
|
||||
)}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
// Individual Feed Picker Item that shows real feed title
|
||||
const FeedPickerItem: FC<{
|
||||
feedId: string
|
||||
title: string
|
||||
onSelect: (feedId: string) => void
|
||||
}> = ({ feedId, title, onSelect }) => {
|
||||
const feed = useFeedById(feedId, (feed) => ({ title: feed?.title }))
|
||||
const displayTitle = feed?.title || title || "Untitled Feed"
|
||||
|
||||
return (
|
||||
<DropdownMenuItem onClick={() => onSelect(feedId)} className="text-xs">
|
||||
<span className="truncate">{displayTitle}</span>
|
||||
</DropdownMenuItem>
|
||||
)
|
||||
}
|
||||
-75
@@ -1,75 +0,0 @@
|
||||
import { stopPropagation } from "@follow/utils"
|
||||
import Fuse from "fuse.js"
|
||||
import { useMemo, useState } from "react"
|
||||
import { useDebounceCallback } from "usehooks-ts"
|
||||
|
||||
import { DropdownMenuItem } from "~/components/ui/dropdown-menu/dropdown-menu"
|
||||
|
||||
import { SearchInput } from "./SearchInput"
|
||||
|
||||
// Generic Picker Component
|
||||
export interface PickerItem {
|
||||
id: string
|
||||
title: string
|
||||
}
|
||||
|
||||
export interface PickerListProps<T extends PickerItem> {
|
||||
items: T[]
|
||||
placeholder: string
|
||||
onSelect: (id: string) => void
|
||||
renderItem?: (item: T, onSelect: (id: string) => void) => React.ReactNode
|
||||
noResultsText?: string
|
||||
}
|
||||
|
||||
export const PickerList = <T extends PickerItem>({
|
||||
items,
|
||||
placeholder,
|
||||
onSelect,
|
||||
renderItem,
|
||||
noResultsText = "No items found",
|
||||
}: PickerListProps<T>) => {
|
||||
const [searchTerm, setSearchTerm] = useState("")
|
||||
|
||||
const fuse = useMemo(() => {
|
||||
return new Fuse(items, {
|
||||
keys: ["title", "id"],
|
||||
threshold: 0.3,
|
||||
})
|
||||
}, [items])
|
||||
|
||||
const filteredItems = useMemo(() => {
|
||||
if (!searchTerm) return items
|
||||
const results = fuse.search(searchTerm)
|
||||
return results.map((result) => result.item)
|
||||
}, [items, fuse, searchTerm])
|
||||
|
||||
const debouncedSetSearchTerm = useDebounceCallback(setSearchTerm, 300)
|
||||
|
||||
const defaultRenderItem = (item: T, onSelect: (id: string) => void) => (
|
||||
<DropdownMenuItem key={item.id} onClick={() => onSelect(item.id)} className="text-xs">
|
||||
<span className="truncate">{item.title}</span>
|
||||
</DropdownMenuItem>
|
||||
)
|
||||
|
||||
return (
|
||||
<div className="max-h-64 w-56">
|
||||
<SearchInput
|
||||
placeholder={placeholder}
|
||||
onKeyDown={stopPropagation}
|
||||
onKeyUp={stopPropagation}
|
||||
onChange={(e) => {
|
||||
debouncedSetSearchTerm(e.target.value)
|
||||
}}
|
||||
/>
|
||||
<div className="max-h-48 overflow-y-auto pt-2">
|
||||
{filteredItems.length === 0 ? (
|
||||
<div className="text-text-tertiary p-2 text-xs">{noResultsText}</div>
|
||||
) : (
|
||||
filteredItems.map((item) =>
|
||||
renderItem ? renderItem(item, onSelect) : defaultRenderItem(item, onSelect),
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
-14
@@ -1,14 +0,0 @@
|
||||
import type { FC } from "react"
|
||||
|
||||
export const SearchInput: FC<React.ComponentProps<"input">> = (props) => {
|
||||
return (
|
||||
<div className="-mx-1 flex items-center border-b py-1">
|
||||
<i className="i-mgc-search-2-cute-re text-text-secondary ml-3 mr-1.5 size-4" />
|
||||
<input
|
||||
type="text"
|
||||
{...props}
|
||||
className="placeholder:text-text-tertiary w-full bg-transparent py-1 pl-0 pr-4 text-xs"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
-4
@@ -1,4 +0,0 @@
|
||||
export * from "./EntryPickers"
|
||||
export * from "./FeedPickers"
|
||||
export * from "./PickerList"
|
||||
export * from "./SearchInput"
|
||||
-15
@@ -3,7 +3,6 @@ import { FeedViewType } from "@follow-app/client-sdk"
|
||||
import { memo, useCallback, useEffect, useRef } from "react"
|
||||
|
||||
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"
|
||||
import { useFileUploadWithDefaults } from "~/modules/ai-chat/hooks/useFileUpload"
|
||||
@@ -13,7 +12,6 @@ import { SUPPORTED_MIME_ACCEPT } from "~/modules/ai-chat/utils/file-validation"
|
||||
import { useBlockActions } from "../../store/hooks"
|
||||
import { BlockSliceAction } from "../../store/slices/block.slice"
|
||||
import { CombinedContextBlock, ContextBlock } from "../context-bar/blocks"
|
||||
import { ContextMenuContent } from "../context-bar/menus"
|
||||
|
||||
export const AIChatContextBar: Component = memo(({ className }) => {
|
||||
const blocks = useAIChatStore()((s) => s.blocks)
|
||||
@@ -87,19 +85,6 @@ export const AIChatContextBar: Component = memo(({ className }) => {
|
||||
|
||||
return (
|
||||
<div className={cn("flex flex-wrap items-center gap-2 px-4 py-3", className)}>
|
||||
{/* Add Context Button */}
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<button
|
||||
type="button"
|
||||
className="bg-material-medium hover:bg-material-thin border-border text-text-secondary hover:text-text-secondary flex size-7 items-center justify-center rounded-md border transition-colors"
|
||||
>
|
||||
<i className="i-mgc-at-cute-re size-3.5" />
|
||||
</button>
|
||||
</DropdownMenuTrigger>
|
||||
<ContextMenuContent />
|
||||
</DropdownMenu>
|
||||
|
||||
{/* File Upload Button */}
|
||||
<button
|
||||
type="button"
|
||||
|
||||
+1
-2
@@ -39,8 +39,7 @@ const getDisplayContent = (block: AIChatContextBlock): React.ReactNode => {
|
||||
const viewName = getView(Number(block.value))?.name
|
||||
return viewName ? t(viewName, { ns: "common" }) : block.value
|
||||
}
|
||||
case "mainEntry":
|
||||
case "referEntry": {
|
||||
case "mainEntry": {
|
||||
return <EntryTitle entryId={block.value} fallback={block.value} />
|
||||
}
|
||||
case "mainFeed": {
|
||||
|
||||
-7
@@ -20,11 +20,6 @@ export const BLOCK_STYLES = {
|
||||
icon: "bg-orange/10 text-orange",
|
||||
label: "text-orange",
|
||||
},
|
||||
referEntry: {
|
||||
container: "from-blue/5 to-blue/10 border-blue/20 hover:border-blue/30",
|
||||
icon: "bg-blue/10 text-blue",
|
||||
label: "text-blue",
|
||||
},
|
||||
selectedText: {
|
||||
container: "from-purple/5 to-purple/10 border-purple/20 hover:border-purple/30",
|
||||
icon: "bg-purple/10 text-purple",
|
||||
@@ -57,7 +52,6 @@ export const DEFAULT_BLOCK_STYLES = {
|
||||
export const BLOCK_ICONS = {
|
||||
mainEntry: "i-mgc-star-cute-fi",
|
||||
mainFeed: "i-mgc-rss-cute-fi",
|
||||
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",
|
||||
@@ -69,7 +63,6 @@ export const BLOCK_ICONS = {
|
||||
export const BLOCK_LABELS = {
|
||||
mainEntry: "Current",
|
||||
mainFeed: "Current",
|
||||
referEntry: "Ref",
|
||||
selectedText: "Text",
|
||||
fileAttachment: "File",
|
||||
mainView: "View",
|
||||
|
||||
@@ -20,7 +20,7 @@ interface BaseContextBlock {
|
||||
}
|
||||
|
||||
export interface ValueContextBlock extends BaseContextBlock {
|
||||
type: "mainView" | "mainEntry" | "mainFeed" | "referEntry" | "selectedText" | "unreadOnly"
|
||||
type: "mainView" | "mainEntry" | "mainFeed" | "selectedText" | "unreadOnly"
|
||||
value: string
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user