Refactor providers call

This commit is contained in:
2023-07-09 17:35:12 +02:00
parent 29254b49a6
commit 014c2625f9
9 changed files with 42 additions and 51 deletions

View File

@ -8,9 +8,7 @@ import {
} from "@mui/material";
import React, { PropsWithChildren } from "react";
interface AlertContext {
alert: (message: string, title?: string) => Promise<void>;
}
type AlertContext = (message: string, title?: string) => Promise<void>;
const AlertContextK = React.createContext<AlertContext | null>(null);
@ -29,16 +27,14 @@ export function AlertDialogProvider(p: PropsWithChildren): React.ReactElement {
cb.current = null;
};
const hook: AlertContext = {
alert: (message, title) => {
setTitle(title);
setMessage(message);
setOpen(true);
const hook: AlertContext = (message, title) => {
setTitle(title);
setMessage(message);
setOpen(true);
return new Promise((res) => {
cb.current = res;
});
},
return new Promise((res) => {
cb.current = res;
});
};
return (

View File

@ -8,13 +8,11 @@ import {
} from "@mui/material";
import React, { PropsWithChildren } from "react";
interface ConfirmContext {
confirm: (
message: string,
title?: string,
confirmButton?: string
) => Promise<boolean>;
}
type ConfirmContext = (
message: string,
title?: string,
confirmButton?: string
) => Promise<boolean>;
const ConfirmContextK = React.createContext<ConfirmContext | null>(null);
@ -38,17 +36,15 @@ export function ConfirmDialogProvider(
cb.current = null;
};
const hook: ConfirmContext = {
confirm: (message, title, confirmButton) => {
setTitle(title);
setMessage(message);
setConfirmButton(confirmButton);
setOpen(true);
const hook: ConfirmContext = (message, title, confirmButton) => {
setTitle(title);
setMessage(message);
setConfirmButton(confirmButton);
setOpen(true);
return new Promise((res) => {
cb.current = res;
});
},
return new Promise((res) => {
cb.current = res;
});
};
return (