diff options
author | Manti <67705577+mantikafasi@users.noreply.github.com> | 2023-05-28 23:03:06 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-28 22:03:06 +0200 |
commit | 3e3d05fc26a634b17549c9473bd8aeebb7dec4ec (patch) | |
tree | a3591b0b0dea888f24d1ce8e58584b4447f62dde /src/utils | |
parent | 6300198a5463ab38da81906bda634addf4c8a369 (diff) | |
download | Vencord-3e3d05fc26a634b17549c9473bd8aeebb7dec4ec.tar.gz Vencord-3e3d05fc26a634b17549c9473bd8aeebb7dec4ec.tar.bz2 Vencord-3e3d05fc26a634b17549c9473bd8aeebb7dec4ec.zip |
ReviewDB: Add Review Modal & Pagination (#1174)
Co-authored-by: V <vendicated@riseup.net>
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/react.tsx | 13 | ||||
-rw-r--r-- | src/utils/types.ts | 2 |
2 files changed, 13 insertions, 2 deletions
diff --git a/src/utils/react.tsx b/src/utils/react.tsx index 69c1df2..a4c7152 100644 --- a/src/utils/react.tsx +++ b/src/utils/react.tsx @@ -67,6 +67,7 @@ interface AwaiterOpts<T> { fallbackValue: T; deps?: unknown[]; onError?(e: any): void; + onSuccess?(value: T): void; } /** * Await a promise @@ -94,8 +95,16 @@ export function useAwaiter<T>(factory: () => Promise<T>, providedOpts?: AwaiterO if (!state.pending) setState({ ...state, pending: true }); factory() - .then(value => isAlive && setState({ value, error: null, pending: false })) - .catch(error => isAlive && (setState({ value: null, error, pending: false }), opts.onError?.(error))); + .then(value => { + if (!isAlive) return; + setState({ value, error: null, pending: false }); + opts.onSuccess?.(value); + }) + .catch(error => { + if (!isAlive) return; + setState({ value: null, error, pending: false }); + opts.onError?.(error); + }); return () => void (isAlive = false); }, opts.deps); diff --git a/src/utils/types.ts b/src/utils/types.ts index 5c7a85c..c81b13a 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -277,6 +277,8 @@ export interface DefinedSettings<D extends SettingsDefinition = SettingsDefiniti * will be an empty string until plugin is initialized */ pluginName: string; + + withPrivateSettings<T>(): this & { store: T; }; } export type PartialExcept<T, R extends keyof T> = Partial<T> & Required<Pick<T, R>>; |