Skip to content

Commit

Permalink
feat: format actions value
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed Jun 12, 2024
1 parent 23c9c40 commit 5ba6bbe
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/renderer/src/models/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ export type DiscoverResponse = Array<
>[number]
>

export type ActionsResponse = Exclude<ExtractBizResponse<
typeof apiClient.actions.$get
>["data"], undefined>["rules"]

export type ListResponse<T> = {
code: number
data?: T
Expand Down
10 changes: 8 additions & 2 deletions src/renderer/src/pages/settings/actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { SettingsTitle } from "@renderer/components/settings/title"
import { Button } from "@renderer/components/ui/button"
import { useBizQuery } from "@renderer/hooks/useBizQuery"
import { apiClient } from "@renderer/lib/api-fetch"
import type { ActionsResponse } from "@renderer/models"
import { Queries } from "@renderer/queries"
import { useMutation } from "@tanstack/react-query"
import { useEffect, useState } from "react"
Expand All @@ -17,7 +18,7 @@ type ActionsInput = {
condition: {
field?: FeedField
operator?: Operation
value?: string | number
value?: string
}[]
result: {
translation?: string
Expand Down Expand Up @@ -46,9 +47,14 @@ export function Component() {

const mutation = useMutation({
mutationFn: async () => {
actionsData.forEach((action) => {
action.condition = action.condition.filter((c) => c.field && c.operator && c.value)
action.result.rewriteRules = action.result.rewriteRules?.filter((r) => r.from && r.to)
action.result.blockRules = action.result.blockRules?.filter((r) => r.field && r.operator && r.value)
})
await apiClient.actions.$put({
json: {
rules: actionsData,
rules: actionsData as ActionsResponse,
},
})
},
Expand Down

0 comments on commit 5ba6bbe

Please sign in to comment.