Merge pull request #4002 from RollerKnobster/hotfix/3992-toast-handle-null-duration

NETSCRIPT: fix #3992 allow null duration in toast ns function
This commit is contained in:
hydroflame 2022-08-23 12:06:56 -03:00 committed by GitHub
commit cc29de7969
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 4 deletions

@ -139,7 +139,7 @@ function initAppNotifier(): void {
toast: (message: string, type: ToastVariant, duration = 2000) => SnackbarEvents.emit(message, type, duration), toast: (message: string, type: ToastVariant, duration = 2000) => SnackbarEvents.emit(message, type, duration),
}; };
// Will be consumud by the electron wrapper. // Will be consumed by the electron wrapper.
window.appNotifier = funcs; window.appNotifier = funcs;
} }
@ -173,7 +173,7 @@ function initSaveFunctions(): void {
pushSaveData: (base64save: string, automatic = false): void => Router.toImportSave(base64save, automatic), pushSaveData: (base64save: string, automatic = false): void => Router.toImportSave(base64save, automatic),
}; };
// Will be consumud by the electron wrapper. // Will be consumed by the electron wrapper.
window.appSaveFns = funcs; window.appSaveFns = funcs;
} }

@ -1849,7 +1849,7 @@ const base: InternalAPI<NS> = {
(_message: unknown, _variant: unknown = ToastVariant.SUCCESS, _duration: unknown = 2000): void => { (_message: unknown, _variant: unknown = ToastVariant.SUCCESS, _duration: unknown = 2000): void => {
const message = helpers.string(ctx, "message", _message); const message = helpers.string(ctx, "message", _message);
const variant = helpers.string(ctx, "variant", _variant); const variant = helpers.string(ctx, "variant", _variant);
const duration = helpers.number(ctx, "duration", _duration); const duration = _duration === null ? null : helpers.number(ctx, "duration", _duration);
if (!checkEnum(ToastVariant, variant)) if (!checkEnum(ToastVariant, variant))
throw new Error(`variant must be one of ${Object.values(ToastVariant).join(", ")}`); throw new Error(`variant must be one of ${Object.values(ToastVariant).join(", ")}`);
SnackbarEvents.emit(message, variant, duration); SnackbarEvents.emit(message, variant, duration);

@ -43,7 +43,7 @@ export function SnackbarProvider(props: IProps): React.ReactElement {
); );
} }
export const SnackbarEvents = new EventEmitter<[string | React.ReactNode, ToastVariant, number]>(); export const SnackbarEvents = new EventEmitter<[string | React.ReactNode, ToastVariant, number | null]>();
export function Snackbar(): React.ReactElement { export function Snackbar(): React.ReactElement {
const { enqueueSnackbar, closeSnackbar } = useSnackbar(); const { enqueueSnackbar, closeSnackbar } = useSnackbar();