Refactor_updateView to add task

This commit is contained in:
2dust
2024-08-22 19:51:10 +08:00
parent b936c194e4
commit b57cdd31bd
27 changed files with 218 additions and 216 deletions
@@ -23,7 +23,7 @@ namespace ServiceLib.ViewModels
public ReactiveCommand<Unit, Unit> SubShareCmd { get; }
public bool IsModified { get; set; }
public SubSettingViewModel(Func<EViewAction, object?, bool>? updateView)
public SubSettingViewModel(Func<EViewAction, object?, Task<bool>>? updateView)
{
_config = LazyConfig.Instance.Config;
_noticeHandler = Locator.Current.GetService<NoticeHandler>();
@@ -39,19 +39,19 @@ namespace ServiceLib.ViewModels
SubAddCmd = ReactiveCommand.Create(() =>
{
EditSub(true);
EditSubAsync(true);
});
SubDeleteCmd = ReactiveCommand.Create(() =>
{
DeleteSub();
DeleteSubAsync();
}, canEditRemove);
SubEditCmd = ReactiveCommand.Create(() =>
SubEditCmd = ReactiveCommand.CreateFromTask(async () =>
{
EditSub(false);
await EditSubAsync(false);
}, canEditRemove);
SubShareCmd = ReactiveCommand.Create(() =>
SubShareCmd = ReactiveCommand.CreateFromTask(async () =>
{
_updateView?.Invoke(EViewAction.ShareSub, SelectedSource?.url);
await _updateView?.Invoke(EViewAction.ShareSub, SelectedSource?.url);
}, canEditRemove);
}
@@ -61,7 +61,7 @@ namespace ServiceLib.ViewModels
_subItems.AddRange(LazyConfig.Instance.SubItems().OrderBy(t => t.sort));
}
public void EditSub(bool blNew)
public async Task EditSubAsync(bool blNew)
{
SubItem item;
if (blNew)
@@ -76,16 +76,16 @@ namespace ServiceLib.ViewModels
return;
}
}
if (_updateView?.Invoke(EViewAction.SubEditWindow, item) == true)
if (await _updateView?.Invoke(EViewAction.SubEditWindow, item) == true)
{
RefreshSubItems();
IsModified = true;
}
}
private void DeleteSub()
private async Task DeleteSubAsync()
{
if (_updateView?.Invoke(EViewAction.ShowYesNo, null) == false)
if (await _updateView?.Invoke(EViewAction.ShowYesNo, null) == false)
{
return;
}