diff --git a/src/renderer/src/components/settings/action-card.tsx b/src/renderer/src/components/settings/action-card.tsx index fe8945ddd..a461bcf42 100644 --- a/src/renderer/src/components/settings/action-card.tsx +++ b/src/renderer/src/components/settings/action-card.tsx @@ -29,6 +29,8 @@ import { TableHeader, TableRow, } from "@renderer/components/ui/table" +import { ViewSelectContent } from "@renderer/components/view-select-content" +import { cn } from "@renderer/lib/utils" type Operation = | "contains" @@ -41,35 +43,12 @@ type Operation = type EntryField = "all" | "title" | "content" | "author" | "link" | "order" type FeedField = "view" | "title" | "category" | "site_url" | "feed_url" -// eslint-disable-next-line unused-imports/no-unused-vars -type Actions = { - name: string - condition: { - field: FeedField - operator: Operation - value: string | number - }[] - result: { - translation?: string - summary?: boolean - rewriteRules?: { - from: string - to: string - }[] - blockRules?: { - field: EntryField - operator: Operation - value: string | number - }[] - } -}[] - type ActionsInput = { name: string condition: { field?: FeedField operator?: Operation - value?: string | number + value?: string }[] result: { translation?: string @@ -90,30 +69,37 @@ const OperationOptions = [ { name: "contains", value: "contains", + types: ["text"], }, { name: "does not contain", value: "not_contains", + types: ["text"], }, { name: "is equal to", value: "eq", + types: ["number", "text", "view"], }, { name: "is not equal to", value: "not_eq", + types: ["number", "text", "view"], }, { name: "is greater than", value: "gt", + types: ["number"], }, { name: "is less than", value: "lt", + types: ["number"], }, { name: "matches regex", value: "regex", + types: ["text"], }, ] @@ -141,6 +127,7 @@ const EntryOptions = [ { name: "Order", value: "order", + type: "number", }, ] @@ -148,6 +135,7 @@ const FeedOptions = [ { name: "View", value: "view", + type: "view", }, { name: "Title", @@ -231,27 +219,32 @@ const AddTableRow = ({ onClick }: { onClick?: () => void }) => ( ) const OperationTableCell = ({ + type, value, onValueChange, }: { + type: string value?: Operation onValueChange?: (value: Operation) => void -}) => ( - - - - - - - {OperationOptions.map((option) => ( - - {option.name} - - ))} - - - -) +}) => { + const options = OperationOptions.filter((option) => option.types.includes(type)) + return ( + + + + + + + {options.map((option) => ( + + {option.name} + + ))} + + + + ) +} const SettingCollapsible = ({ title, @@ -275,6 +268,16 @@ const SettingCollapsible = ({ ) +const CommonSelectTrigger = ({ + className, +}: { + className?: string +}) => ( + + + +) + export function ActionCard({ data, onChange, @@ -350,6 +353,9 @@ export function ActionCard({ data.condition[conditionIdx][key] = value onChange(data) } + const type = FeedOptions.find( + (option) => option.value === condition.field, + )?.type || "text" return ( change("field", value)} > - - - + {FeedOptions.map((option) => ( change("operator", value)} /> - - change("value", e.target.value)} - /> + {type === "view" ? ( + change("value", value)} + value={condition.value} + > + + + + ) : ( + + change("value", e.target.value)} + /> + )} ) @@ -430,9 +446,7 @@ export function ActionCard({ onChange(data) }} > - - - + {TransitionOptions.map((option) => ( @@ -569,6 +583,9 @@ export function ActionCard({ data.result.blockRules![index][key] = value onChange(data) } + const type = EntryOptions.find( + (option) => option.value === rule.field, + )?.type || "text" return ( change("field", value)} > - - - + {EntryOptions.map((option) => ( change("operator", value)} /> change("value", e.target.value)} diff --git a/src/renderer/src/components/view-select-content.tsx b/src/renderer/src/components/view-select-content.tsx new file mode 100644 index 000000000..cc9ea9ffe --- /dev/null +++ b/src/renderer/src/components/view-select-content.tsx @@ -0,0 +1,21 @@ +import { + SelectContent, + SelectItem, +} from "@renderer/components/ui/select" +import { views } from "@renderer/lib/constants" +import { cn } from "@renderer/lib/utils" + +export const ViewSelectContent = () => ( + + {views.map((view, index) => ( + + + + {view.icon} + + {view.name} + + + ))} + +) diff --git a/src/renderer/src/hono.ts b/src/renderer/src/hono.ts index 237d6aea8..0fa09d5d0 100644 --- a/src/renderer/src/hono.ts +++ b/src/renderer/src/hono.ts @@ -13,7 +13,7 @@ declare const routes: hono_hono_base.HonoBase - - {views.map((view, index) => ( - - - - {view.icon} - - {view.name} - - - ))} - +