refactor: extract alert method to a standalone function

This commit is contained in:
Baptiste Grob
2020-07-20 11:31:32 +02:00
parent c6a25d6ae4
commit 966783c8b9

View File

@@ -8,13 +8,13 @@ export function confirmDialog({
title,
confirmButtonText = 'Confirm',
cancelButtonText = 'Cancel',
confirmButtonStyle = 'info'
confirmButtonStyle = 'info',
}: {
text: string,
title?: string,
confirmButtonText?: string,
cancelButtonText?: string,
confirmButtonStyle?: 'danger' | 'info'
text: string;
title?: string;
confirmButtonText?: string;
cancelButtonText?: string;
confirmButtonStyle?: 'danger' | 'info';
}) {
return new Promise<boolean>((resolve) => {
const alert = new SKAlert({
@@ -41,24 +41,37 @@ export function confirmDialog({
});
}
export class AlertService implements SNAlertService {
alert(
text: string,
title: string,
closeButtonText = 'OK',
) {
return new Promise<void>((resolve) => {
const alert = new SKAlert({
title,
text,
buttons: [{
export function alertDialog({
title,
text,
closeButtonText = 'OK',
}: {
title?: string;
text: string;
closeButtonText?: string;
}) {
return new Promise<void>((resolve) => {
const alert = new SKAlert({
title,
text,
buttons: [
{
text: closeButtonText,
style: 'neutral',
action: resolve,
}],
});
alert.present();
},
],
});
alert.present();
});
}
export class AlertService implements SNAlertService {
/**
* @deprecated use the standalone `alertDialog` function instead
*/
alert(text: string, title?: string, closeButtonText?: string) {
return alertDialog({ text, title, closeButtonText });
}
confirm(
@@ -73,7 +86,8 @@ export class AlertService implements SNAlertService {
title,
confirmButtonText,
cancelButtonText,
confirmButtonStyle: confirmButtonType === ButtonType.Danger ? 'danger' : 'info'
confirmButtonStyle:
confirmButtonType === ButtonType.Danger ? 'danger' : 'info',
});
}