| ... | @@ -1,5 +1,6 @@ | ... | @@ -1,5 +1,6 @@ |
| 1 | import { message as errMessage } from "@clo/lib/error.ts"; | 1 | import { message as errMessage } from "@clo/lib/error.ts"; |
| 2 | import type { Timer } from "@clo/lib/ts.ts"; | 2 | import type { Timer } from "@clo/lib/ts.ts"; |
| | 3 | import { isDisabled } from "@testing-library/user-event/dist/cjs/utils/index.js"; |
| 3 | import { | 4 | import { |
| 4 | type FC, | 5 | type FC, |
| 5 | type MouseEvent, | 6 | type MouseEvent, |
| ... | @@ -46,9 +47,15 @@ export interface UseMutateResultBase<Args extends unknown[], Result> { | ... | @@ -46,9 +47,15 @@ export interface UseMutateResultBase<Args extends unknown[], Result> { |
| 46 | runWithOptions: ( | 47 | runWithOptions: ( |
| 47 | ..._: [...args: Args, options: RunOptions<Result>] | 48 | ..._: [...args: Args, options: RunOptions<Result>] |
| 48 | ) => void; | 49 | ) => void; |
| | 50 | |
| | 51 | /** Unset error and success states */ |
| 49 | clear: () => void; | 52 | clear: () => void; |
| | 53 | /** Set `error`, useful for input validators or whatever */ |
| 50 | setError: (error: unknown) => void; | 54 | setError: (error: unknown) => void; |
| | 55 | /** The arguments of the latest mutation call */ |
| 51 | args: Args | undefined; | 56 | args: Args | undefined; |
| | 57 | /** `true` when controls should be disabled */ |
| | 58 | isDisabled: boolean; |
| 52 | } | 59 | } |
| 53 | | 60 | |
| 54 | export interface UseMutateSuccess<Result> { | 61 | export interface UseMutateSuccess<Result> { |
| ... | @@ -89,8 +96,6 @@ export interface UseMutateIdle { | ... | @@ -89,8 +96,6 @@ export interface UseMutateIdle { |
| 89 | result: undefined; | 96 | result: undefined; |
| 90 | error: undefined; | 97 | error: undefined; |
| 91 | errorMessage: undefined; | 98 | errorMessage: undefined; |
| 92 | /** `true` when controls should be disabled */ | | |
| 93 | isDisabled: boolean; | | |
| 94 | /** `true` when a `mutate` function is currently running. */ | 99 | /** `true` when a `mutate` function is currently running. */ |
| 95 | isMutating: boolean; | 100 | isMutating: boolean; |
| 96 | /** `true` when a loading indicator should be shown. */ | 101 | /** `true` when a loading indicator should be shown. */ |
| ... | @@ -116,6 +121,7 @@ type AnyMutationStateWithoutRun<Args extends unknown[], Result> = | ... | @@ -116,6 +121,7 @@ type AnyMutationStateWithoutRun<Args extends unknown[], Result> = |
| 116 | isSuccess: boolean; | 121 | isSuccess: boolean; |
| 117 | isError: boolean; | 122 | isError: boolean; |
| 118 | args: Args | undefined; | 123 | args: Args | undefined; |
| | 124 | isDisabled: boolean; |
| 119 | }; | 125 | }; |
| 120 | | 126 | |
| 121 | export type AnyMutationState<Args extends unknown[], Result> = | 127 | export type AnyMutationState<Args extends unknown[], Result> = |
| ... | @@ -134,6 +140,7 @@ function initialState() { | ... | @@ -134,6 +140,7 @@ function initialState() { |
| 134 | isError: false, | 140 | isError: false, |
| 135 | isOptimisticData: false, | 141 | isOptimisticData: false, |
| 136 | args: undefined, | 142 | args: undefined, |
| | 143 | isDisabled: true, |
| 137 | } as const; | 144 | } as const; |
| 138 | } | 145 | } |
| 139 | | 146 | |
| ... | @@ -368,7 +375,7 @@ class Observer<Args extends unknown[], Result> { | ... | @@ -368,7 +375,7 @@ class Observer<Args extends unknown[], Result> { |
| 368 | // TODO: when auth drops this will be dependant on the auth status and isMutating | 375 | // TODO: when auth drops this will be dependant on the auth status and isMutating |
| 369 | get isDisabled() { | 376 | get isDisabled() { |
| 370 | self.watched.add("isMutating"); | 377 | self.watched.add("isMutating"); |
| 371 | return self.state.isMutating; | 378 | return !self.mutation || self.state.isMutating; |
| 372 | }, | 379 | }, |
| 373 | get isPending() { | 380 | get isPending() { |
| 374 | self.watched.add("isPending"); | 381 | self.watched.add("isPending"); |