From ac48cdeb7f03eae669d9d232070ce5da2e19e7e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=A5=B7=E2=9A=94=EF=B8=8F=F0=9F=92=80=F0=9F=91=BB?= Date: Wed, 14 Aug 2024 21:54:41 -0700 Subject: [PATCH] fix: failureToastOptions are not applied to useExec and useStreamJSON hooks docs: add failureToastOptions to all applicable hooks docs closes https://github.com/raycast/utils/issues/39 --- docs/utils-reference/getting-started.md | 6 +++++- docs/utils-reference/react-hooks/useAI.md | 4 +++- docs/utils-reference/react-hooks/useCachedPromise.md | 2 ++ docs/utils-reference/react-hooks/useExec.md | 7 +++++-- docs/utils-reference/react-hooks/useFetch.md | 2 ++ docs/utils-reference/react-hooks/usePromise.md | 2 ++ docs/utils-reference/react-hooks/useSQL.md | 4 +++- docs/utils-reference/react-hooks/useStreamJSON.md | 4 +++- package.json | 2 +- src/useExec.ts | 3 ++- src/useStreamJSON.ts | 2 ++ 11 files changed, 30 insertions(+), 8 deletions(-) diff --git a/docs/utils-reference/getting-started.md b/docs/utils-reference/getting-started.md index 5f6e58b..a404c3a 100644 --- a/docs/utils-reference/getting-started.md +++ b/docs/utils-reference/getting-started.md @@ -16,9 +16,13 @@ npm install --save @raycast/utils ## Changelog +### v1.16.5 + +- Fixed the bug where `failureToastOptions` did not apply for `useExec` and `useStreamJSON` hooks. + ### v1.16.4 -- Avoid throwing an error when `useFetch` can't parse the `Content-Type` header of the response +- Avoid throwing an error when `useFetch` can't parse the `Content-Type` header of the response. ### v1.16.3 diff --git a/docs/utils-reference/react-hooks/useAI.md b/docs/utils-reference/react-hooks/useAI.md index 67717d5..caf8073 100644 --- a/docs/utils-reference/react-hooks/useAI.md +++ b/docs/utils-reference/react-hooks/useAI.md @@ -14,7 +14,8 @@ function useAI( execute?: boolean; onError?: (error: Error) => void; onData?: (data: T) => void; - onWillExecute?: (args: string[]) -> void; + onWillExecute?: (args: Parameters) => void; + failureToastOptions?: Partial>; } ): AsyncState & { revalidate: () => void; @@ -37,6 +38,7 @@ Including the [usePromise](./usePromise.md)'s options: - `options.onError` is a function called when an execution fails. By default, it will log the error and show a generic failure toast with an action to retry. - `options.onData` is a function called when an execution succeeds. - `options.onWillExecute` is a function called when an execution will start. +- `options.failureToastOptions` are the options to customize the title, message, and primary action of the failure toast. ### Return diff --git a/docs/utils-reference/react-hooks/useCachedPromise.md b/docs/utils-reference/react-hooks/useCachedPromise.md index 934d6cd..d163832 100644 --- a/docs/utils-reference/react-hooks/useCachedPromise.md +++ b/docs/utils-reference/react-hooks/useCachedPromise.md @@ -27,6 +27,7 @@ function useCachedPromise( onError?: (error: Error) => void; onData?: (data: Result) => void; onWillExecute?: (args: Parameters) => void; + failureToastOptions?: Partial>; }, ): AsyncState> & { revalidate: () => void; @@ -54,6 +55,7 @@ Including the [usePromise](./usePromise.md)'s options: - `options.onError` is a function called when an execution fails. By default, it will log the error and show a generic failure toast with an action to retry. - `options.onData` is a function called when an execution succeeds. - `options.onWillExecute` is a function called when an execution will start. +- `options.failureToastOptions` are the options to customize the title, message, and primary action of the failure toast. ### Return diff --git a/docs/utils-reference/react-hooks/useExec.md b/docs/utils-reference/react-hooks/useExec.md index 0d712b8..5af79b1 100644 --- a/docs/utils-reference/react-hooks/useExec.md +++ b/docs/utils-reference/react-hooks/useExec.md @@ -30,7 +30,8 @@ function useExec( execute?: boolean; onError?: (error: Error) => void; onData?: (data: T) => void; - onWillExecute?: (args: string[]) -> void; + onWillExecute?: (args: string[]) => void; + failureToastOptions?: Partial>; } ): AsyncState & { revalidate: () => void; @@ -61,7 +62,8 @@ function useExec( execute?: boolean; onError?: (error: Error) => void; onData?: (data: T) => void; - onWillExecute?: (args: string[]) -> void; + onWillExecute?: (args: string[]) => void; + failureToastOptions?: Partial>; } ): AsyncState & { revalidate: () => void; @@ -110,6 +112,7 @@ Including the [usePromise](./usePromise.md)'s options: - `options.onError` is a function called when an execution fails. By default, it will log the error and show a generic failure toast with an action to retry. - `options.onData` is a function called when an execution succeeds. - `options.onWillExecute` is a function called when an execution will start. +- `options.failureToastOptions` are the options to customize the title, message, and primary action of the failure toast. ### Return diff --git a/docs/utils-reference/react-hooks/useFetch.md b/docs/utils-reference/react-hooks/useFetch.md index 5b15407..9ee6b63 100644 --- a/docs/utils-reference/react-hooks/useFetch.md +++ b/docs/utils-reference/react-hooks/useFetch.md @@ -20,6 +20,7 @@ export function useFetch( onError?: (error: Error) => void; onData?: (data: T) => void; onWillExecute?: (args: [string, RequestInit]) => void; + failureToastOptions?: Partial>; }, ): AsyncState & { revalidate: () => void; @@ -51,6 +52,7 @@ Including the [usePromise](./usePromise.md)'s options: - `options.onError` is a function called when an execution fails. By default, it will log the error and show a generic failure toast with an action to retry. - `options.onData` is a function called when an execution succeeds. - `options.onWillExecute` is a function called when an execution will start. +- `options.failureToastOptions` are the options to customize the title, message, and primary action of the failure toast. ### Return diff --git a/docs/utils-reference/react-hooks/usePromise.md b/docs/utils-reference/react-hooks/usePromise.md index e13b9fb..5336528 100644 --- a/docs/utils-reference/react-hooks/usePromise.md +++ b/docs/utils-reference/react-hooks/usePromise.md @@ -20,6 +20,7 @@ function usePromise( onError?: (error: Error) => void; onData?: (data: Result) => void; onWillExecute?: (args: Parameters) => void; + failureToastOptions?: Partial>; }, ): AsyncState> & { revalidate: () => void; @@ -39,6 +40,7 @@ With a few options: - `options.onError` is a function called when an execution fails. By default, it will log the error and show a generic failure toast with an action to retry. - `options.onData` is a function called when an execution succeeds. - `options.onWillExecute` is a function called when an execution will start. +- `options.failureToastOptions` are the options to customize the title, message, and primary action of the failure toast. ### Returns diff --git a/docs/utils-reference/react-hooks/useSQL.md b/docs/utils-reference/react-hooks/useSQL.md index a3f62ef..9c8a4f4 100644 --- a/docs/utils-reference/react-hooks/useSQL.md +++ b/docs/utils-reference/react-hooks/useSQL.md @@ -13,7 +13,8 @@ function useSQL( execute?: boolean; onError?: (error: Error) => void; onData?: (data: T) => void; - onWillExecute?: (args: string[]) -> void; + onWillExecute?: (args: string[]) => void; + failureToastOptions?: Partial>; } ): AsyncState & { revalidate: () => void; @@ -37,6 +38,7 @@ Including the [usePromise](./usePromise.md)'s options: - `options.onError` is a function called when an execution fails. By default, it will log the error and show a generic failure toast with an action to retry. - `options.onData` is a function called when an execution succeeds. - `options.onWillExecute` is a function called when an execution will start. +- `options.failureToastOptions` are the options to customize the title, message, and primary action of the failure toast. ### Return diff --git a/docs/utils-reference/react-hooks/useStreamJSON.md b/docs/utils-reference/react-hooks/useStreamJSON.md index 7d57b7c..70564e3 100644 --- a/docs/utils-reference/react-hooks/useStreamJSON.md +++ b/docs/utils-reference/react-hooks/useStreamJSON.md @@ -17,6 +17,7 @@ export function useStreamJSON( onError?: (error: Error) => void; onData?: (data: T) => void; onWillExecute?: (args: [string, RequestInit]) => void; + failureToastOptions?: Partial>; }, ): AsyncState> & { revalidate: () => void; @@ -48,7 +49,8 @@ Including the [usePromise](./usePromise.md)'s options: - `options.execute` is a boolean to indicate whether to actually execute the function or not. This is useful for cases where one of the function's arguments depends on something that might not be available right away (for example, depends on some user inputs). Because React requires every hook to be defined on the render, this flag enables you to define the hook right away but wait until you have all the arguments ready to execute the function. - `options.onError` is a function called when an execution fails. By default, it will log the error and show a generic failure toast with an action to retry. - `options.onData` is a function called when an execution succeeds. -- `options.onWillExecute` is a function called when an execution will start.. +- `options.onWillExecute` is a function called when an execution will start. +- `options.failureToastOptions` are the options to customize the title, message, and primary action of the failure toast. ### Return diff --git a/package.json b/package.json index 3b66e38..3c20444 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@raycast/utils", - "version": "1.16.4", + "version": "1.16.5", "description": "Set of utilities to streamline building Raycast extensions", "author": "Raycast Technologies Ltd.", "homepage": "https://developers.raycast.com/utils-reference", diff --git a/src/useExec.ts b/src/useExec.ts index 6c26ab0..b10b675 100644 --- a/src/useExec.ts +++ b/src/useExec.ts @@ -170,7 +170,7 @@ export function useExec( } & ExecOptions & ExecCachedPromiseOptions, ): UseCachedPromiseReturnType { - const { parseOutput, input, onData, onWillExecute, initialData, execute, keepPreviousData, onError, ...execOptions } = + const { parseOutput, input, onData, onWillExecute, initialData, execute, keepPreviousData, onError, failureToastOptions, ...execOptions } = Array.isArray(optionsOrArgs) ? options || {} : optionsOrArgs || {}; const useCachedPromiseOptions: ExecCachedPromiseOptions = { @@ -180,6 +180,7 @@ export function useExec( onError, onData, onWillExecute, + failureToastOptions, }; const abortable = useRef(); diff --git a/src/useStreamJSON.ts b/src/useStreamJSON.ts index 99c7bc5..8992fa1 100644 --- a/src/useStreamJSON.ts +++ b/src/useStreamJSON.ts @@ -391,6 +391,7 @@ export function useStreamJSON( onError, onData, onWillExecute, + failureToastOptions, dataPath, filter, transform, @@ -407,6 +408,7 @@ export function useStreamJSON( onError, onData, onWillExecute, + failureToastOptions, }; const generatorRef = useRef | null>(null);