feat: mention view support

This commit is contained in:
Stephen Zhou
2025-10-17 22:34:05 +08:00
parent 9a8bfffb38
commit cf77555a3c
5 changed files with 49 additions and 6 deletions
@@ -35,7 +35,7 @@ const MentionTooltipContent = ({
mentionData.type === "date" && "bg-purple",
)}
>
<MentionTypeIcon type={mentionData.type} className="size-3" />
<MentionTypeIcon type={mentionData.type} value={mentionData.value} className="size-3" />
</div>
<span className="text-text text-sm">{displayName}</span>
</div>
@@ -76,6 +76,9 @@ const getMentionStyles = (type: MentionData["type"]) => {
"hover:bg-purple/20 hover:border-purple/30",
)
}
case "view": {
return cn(baseStyles)
}
}
}
export const MentionComponent: React.FC<MentionComponentProps> = ({ mentionData, className }) => {
@@ -100,7 +103,11 @@ export const MentionComponent: React.FC<MentionComponentProps> = ({ mentionData,
<TooltipRoot>
<TooltipTrigger asChild>
<span className={cn(getMentionStyles(mentionData.type), className)} onClick={handleClick}>
<MentionTypeIcon type={mentionData.type} className="mr-1 translate-y-[2px]" />
<MentionTypeIcon
type={mentionData.type}
value={mentionData.value}
className="mr-1 translate-y-[2px]"
/>
<span>@{displayName}</span>
</span>
</TooltipTrigger>
@@ -109,7 +109,7 @@ const MentionSuggestionItem = React.memo(
mention.type === "date" && "text-purple-500",
)}
>
<MentionTypeIcon type={mention.type} />
<MentionTypeIcon type={mention.type} value={mention.value} />
</span>
{/* Content */}
@@ -1,13 +1,19 @@
import { getView } from "@follow/constants"
import * as React from "react"
import type { MentionType } from "../../types"
interface MentionTypeIconProps {
type: MentionType
value?: unknown
className?: string
}
export const MentionTypeIcon: React.FC<MentionTypeIconProps> = ({ type, className = "size-3" }) => {
export const MentionTypeIcon: React.FC<MentionTypeIconProps> = ({
type,
value,
className = "size-3",
}) => {
switch (type) {
case "entry": {
return <i className={`i-mgc-paper-cute-fi ${className}`} />
@@ -21,6 +27,17 @@ export const MentionTypeIcon: React.FC<MentionTypeIconProps> = ({ type, classNam
case "date": {
return <i className={`i-mgc-calendar-time-add-cute-re ${className}`} />
}
case "view": {
if (typeof value === "number") {
const viewDef = getView(value)
if (viewDef?.icon?.props?.className) {
return (
<i className={`${viewDef.icon.props.className} ${viewDef.className} ${className}`} />
)
}
}
return <i className={`i-mgc-grid-cute-re ${className}`} />
}
default: {
return <i className={`i-mgc-ai-cute-re ${className}`} />
}
@@ -1,3 +1,4 @@
import { getViewList } from "@follow/constants"
import { useMemo } from "react"
import { useTranslation } from "react-i18next"
@@ -49,6 +50,24 @@ export const useMentionSearchService = () => {
return results
}
const views = getViewList()
const lowerQuery = trimmedQuery.toLowerCase()
const firstView = views.find((view) => {
// @ts-expect-error
const viewName = t(view.name, { ns: "common" }).toLowerCase()
return viewName.includes(lowerQuery) || lowerQuery === ""
})
if (firstView) {
pushResult({
id: `view-${firstView.view}`,
name: t(firstView.name, { ns: "common" }),
type: "view",
value: firstView.view,
})
}
const dateSuggestions = buildDateMentions(trimmedQuery)
const searchResults = search(trimmedQuery, undefined, 10)
@@ -69,7 +88,7 @@ export const useMentionSearchService = () => {
return results
}
}, [buildDateMentions, search])
}, [buildDateMentions, search, t])
return { searchMentions }
}
@@ -1,4 +1,4 @@
export type MentionType = "entry" | "feed" | "date" | "category"
export type MentionType = "entry" | "feed" | "date" | "category" | "view"
export type MentionLabelValue = string | number | boolean | MentionLabelDescriptor