Skip to content

Commit 92091df

Browse files
authored
fix(Table): ToastDelay use global setting (#5340)
1 parent ddca0bf commit 92091df

File tree

1 file changed

+19
-31
lines changed

1 file changed

+19
-31
lines changed

src/BootstrapBlazor/Components/Table/Table.razor.Toolbar.cs

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -598,22 +598,16 @@ public async Task EditAsync()
598598

599599
private async Task ShowToastAsync(string title, string content, ToastCategory category = ToastCategory.Information)
600600
{
601-
var option = new ToastOption
602-
{
603-
Category = category,
604-
Title = title,
605-
Content = content
606-
};
601+
var option = GetToastOption(title);
602+
option.Category = category;
603+
option.Content = content;
607604
await Toast.Show(option);
608605
}
609606

610607
private async Task ShowDeleteToastAsync(string title, string content, ToastCategory category = ToastCategory.Information)
611608
{
612-
var option = new ToastOption
613-
{
614-
Category = category,
615-
Title = title
616-
};
609+
var option = GetToastOption(title);
610+
option.Category = category;
617611
option.Content = string.Format(content, Math.Ceiling(option.Delay / 1000.0));
618612
await Toast.Show(option);
619613
}
@@ -673,11 +667,8 @@ protected async Task<bool> SaveModelAsync(EditContext context, ItemChangedType c
673667
}
674668
if (ShowToastAfterSaveOrDeleteModel)
675669
{
676-
var option = new ToastOption
677-
{
678-
Category = valid ? ToastCategory.Success : ToastCategory.Error,
679-
Title = SaveButtonToastTitle
680-
};
670+
var option = GetToastOption(SaveButtonToastTitle);
671+
option.Category = valid ? ToastCategory.Success : ToastCategory.Error;
681672
option.Content = string.Format(SaveButtonToastResultContent, valid ? SuccessText : FailText, Math.Ceiling(option.Delay / 1000.0));
682673
await Toast.Show(option);
683674
}
@@ -1023,11 +1014,8 @@ protected async Task DeleteAsync()
10231014

10241015
if (ShowToastAfterSaveOrDeleteModel)
10251016
{
1026-
var option = new ToastOption()
1027-
{
1028-
Title = DeleteButtonToastTitle,
1029-
Category = ret ? ToastCategory.Success : ToastCategory.Error
1030-
};
1017+
var option = GetToastOption(DeleteButtonToastTitle);
1018+
option.Category = ret ? ToastCategory.Success : ToastCategory.Error;
10311019
option.Content = string.Format(DeleteButtonToastResultContent, ret ? SuccessText : FailText, Math.Ceiling(option.Delay / 1000.0));
10321020
await Toast.Show(option);
10331021
}
@@ -1137,11 +1125,8 @@ private async Task ExecuteExportAsync(Func<Task<bool>> callback)
11371125
}
11381126
else if (ShowToastBeforeExport)
11391127
{
1140-
var option = new ToastOption
1141-
{
1142-
Title = ExportToastTitle,
1143-
Category = ToastCategory.Information
1144-
};
1128+
var option = GetToastOption(ExportToastTitle);
1129+
option.Category = ToastCategory.Information;
11451130
option.Content = string.Format(ExportToastInProgressContent, Math.Ceiling(option.Delay / 1000.0));
11461131
await Toast.Show(option);
11471132
}
@@ -1154,16 +1139,19 @@ private async Task ExecuteExportAsync(Func<Task<bool>> callback)
11541139
}
11551140
else if (ShowToastAfterExport)
11561141
{
1157-
var option = new ToastOption
1158-
{
1159-
Title = ExportToastTitle,
1160-
Category = ret ? ToastCategory.Success : ToastCategory.Error
1161-
};
1142+
var option = GetToastOption(ExportToastTitle);
1143+
option.Category = ret ? ToastCategory.Success : ToastCategory.Error;
11621144
option.Content = string.Format(ExportToastContent, ret ? SuccessText : FailText, Math.Ceiling(option.Delay / 1000.0));
11631145
await Toast.Show(option);
11641146
}
11651147
}
11661148

1149+
private ToastOption GetToastOption(string title) => new()
1150+
{
1151+
Title = title,
1152+
Delay = Options.CurrentValue.ToastDelay
1153+
};
1154+
11671155
private Task ExportAsync() => ExecuteExportAsync(() => OnExportAsync != null
11681156
? OnExportAsync(new TableExportDataContext<TItem>(TableExportType.Unknown, Rows, GetVisibleColumns(), BuildQueryPageOptions()))
11691157
: TableExport.ExportAsync(Rows, GetVisibleColumns()));

0 commit comments

Comments
 (0)