Fixed DeleteWindow and allowed it to close.

This commit is contained in:
alphafetus committed 2023-11-23 18:19:47 -05:00
1 parent 83a08edb2e
commit f98ff942bb
13 files changed
+361 -22

No files matched your search

@@ -1,15 +1,14 @@
using System.Reactive;
using PcgsInvUi.Views;
using ReactiveUI;
namespace PcgsInvUi.ViewModels;
public class DeleteWindowViewModel : ViewModelBase {
public ReactiveCommand<Unit, object> OkCommand { get; }
public ReactiveCommand<DeleteWindow, Unit> CancelCommand { get; }
public ReactiveCommand<Unit, object> CancelCommand { get; }
public DeleteWindowViewModel() {
OkCommand = ReactiveCommand.Create(() => (object)true);
CancelCommand = ReactiveCommand.Create<DeleteWindow>(window => window.Close());
CancelCommand = ReactiveCommand.Create(() => (object)false);
}
}
}
+2 -3
View File
@@ -1,5 +1,4 @@
using System;
using System.Reactive;
using System.Reactive;
using PcgsInvUi.Models;
using ReactiveUI;
@@ -25,4 +24,4 @@ public class EditViewModel : ViewModelBase {
// Setup OkCommand - all Coin-related properties must be non-whitespace.
OkCommand = ReactiveCommand.Create(() => { });
}
}
}
+2 -2
View File
@@ -18,9 +18,9 @@ public class ErrorWindowViewModel : ViewModelBase {
public ErrorWindowViewModel(string message)
{
DisplayedMessage = message;
_message = message;
CloseCommand = ReactiveCommand.Create<ErrorWindow>(window => window.Close());
}
}
}
+5 -4
View File
@@ -10,6 +10,7 @@ using ReactiveUI;
namespace PcgsInvUi.ViewModels;
// TODO Create proper sums for total value.
// TODO Error handling for API calls.
// TODO Manual handling of API key.
// TODO Use CoinFacts link.
@@ -67,7 +68,7 @@ public class MainWindowViewModel : ViewModelBase {
var result = await ShowDeleteWindow.Handle(deleteViewModel);
if (result && SelectedCoin is not null) {
ConnectedCoinDatabase.DeleteCoin(SelectedCoin);
ConnectedCoinDatabase.Collection.Remove(SelectedCoin); // possible null deref - ignored due to button being disabled.
ConnectedCoinDatabase.Collection.Remove(SelectedCoin);
}
}, deleteEnabled);
@@ -83,10 +84,10 @@ public class MainWindowViewModel : ViewModelBase {
catch (IOException e) {
// Something is wrong with the file after it's been created.
Console.WriteLine(e.Message);
ShowErrorWindow.Handle(new ErrorWindowViewModel(e.Message));
await ShowErrorWindow.Handle(new ErrorWindowViewModel(e.Message));
} catch (Exception e) {
Console.WriteLine(e.Message);
ShowErrorWindow.Handle(new ErrorWindowViewModel(e.Message));
await ShowErrorWindow.Handle(new ErrorWindowViewModel(e.Message));
}
});
@@ -120,4 +121,4 @@ public class MainWindowViewModel : ViewModelBase {
this.WhenAnyValue(x => x.SelectedCoin.TotalPrice)
.Subscribe(_ => TotalValue = ConnectedCoinDatabase.Collection.Sum(x => x.TotalPrice));
}
}
}