diff options
| author | Mohamed Bassem <me@mbassem.com> | 2025-04-27 00:02:20 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-27 00:02:20 +0100 |
| commit | 136f126296af65f50da598d084d1485c0e40437a (patch) | |
| tree | 2725c7932ebbcb9b48b5af98eb9b72329a400260 /packages/shared-react | |
| parent | ca47be7fe7be128f459c37614a04902a873fe289 (diff) | |
| download | karakeep-136f126296af65f50da598d084d1485c0e40437a.tar.zst | |
feat: Implement generic rule engine (#1318)
* Add schema for the new rule engine
* Add rule engine backend logic
* Implement the worker logic and event firing
* Implement the UI changesfor the rule engine
* Ensure that when a referenced list or tag are deleted, the corresponding event/action is
* Dont show smart lists in rule engine events
* Add privacy validations for attached tag and list ids
* Move the rules logic into a models
Diffstat (limited to 'packages/shared-react')
| -rw-r--r-- | packages/shared-react/hooks/rules.ts | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/packages/shared-react/hooks/rules.ts b/packages/shared-react/hooks/rules.ts new file mode 100644 index 00000000..16a72f75 --- /dev/null +++ b/packages/shared-react/hooks/rules.ts @@ -0,0 +1,40 @@ +import { api } from "../trpc"; + +export function useCreateRule( + ...opts: Parameters<typeof api.rules.create.useMutation> +) { + const apiUtils = api.useUtils(); + return api.rules.create.useMutation({ + ...opts[0], + onSuccess: (res, req, meta) => { + apiUtils.rules.list.invalidate(); + return opts[0]?.onSuccess?.(res, req, meta); + }, + }); +} + +export function useUpdateRule( + ...opts: Parameters<typeof api.rules.update.useMutation> +) { + const apiUtils = api.useUtils(); + return api.rules.update.useMutation({ + ...opts[0], + onSuccess: (res, req, meta) => { + apiUtils.rules.list.invalidate(); + return opts[0]?.onSuccess?.(res, req, meta); + }, + }); +} + +export function useDeleteRule( + ...opts: Parameters<typeof api.rules.delete.useMutation> +) { + const apiUtils = api.useUtils(); + return api.rules.delete.useMutation({ + ...opts[0], + onSuccess: (res, req, meta) => { + apiUtils.rules.list.invalidate(); + return opts[0]?.onSuccess?.(res, req, meta); + }, + }); +} |
