I made it work

This commit is contained in:
alphafetus committed 2023-11-30 13:35:25 -05:00
1 parent 2b4ed5374a
commit fab011b898
5 files changed
+35 -13

No files matched your search

+1
View File
@@ -1,5 +1,6 @@
using ReactiveUI;
using System.Reactive;
using System;
namespace PcgsInvUi.ViewModels;
+8 -8
View File
@@ -39,23 +39,22 @@ public class MainWindowViewModel : ViewModelBase {
public MainWindowViewModel(CoinDatabase coins, bool askForApiKey) {
ConnectedCoinDatabase = coins;
var newViewModel = new NewViewModel();
var apiKeyViewModel = new ApiKeyViewModel();
// DisplayedList = CoinCollection = new ObservableCollection<Coin>(coins.GetItems());
DisplayedList = ConnectedCoinDatabase.Collection;
TotalValue = DisplayedList.Sum(x => x.TotalPrice);
// Setup interaction to show ApiKeyWindow
apiKeyViewModel.OkCommand.Subscribe(apiKey => {
if (ConnectedCoinDatabase.TryInitApiClient(apiKey))
SidebarContent = newViewModel; // Must assign this to the observable property.
});
// Check if API key must be entered.
if (askForApiKey) {
Console.WriteLine("API key must be entered by user.");
// Show the API key input view.
var apiKeyViewModel = new ApiKeyViewModel();
_sideContent = apiKeyViewModel;
// Subscribe to the OkCommand in the ApiKeyViewModel.
apiKeyViewModel.OkCommand
.Subscribe(apiKey => {
// Attempt to connect to the PCGS API and set view accordingly.
if (ConnectedCoinDatabase.TryInitApiClient()) _sideContent = newViewModel;
});
} else _sideContent = newViewModel;
// Set up the ability to show the error window.
@@ -115,7 +114,8 @@ public class MainWindowViewModel : ViewModelBase {
break;
}
// TODO Clear the text boxes.
// Clear the text boxes.
newViewModel.ClearText();
});
// Update TotalValue anytime a coin's quantity changes.
+11 -4
View File
@@ -40,9 +40,7 @@ public class NewViewModel : ViewModelBase {
okEnabled);
ClearCommand = ReactiveCommand.Create(() => {
PcgsNumber = "";
Grade = "";
Quantity = "";
ClearText();
});
// Initialize grade values for use in the view.
@@ -83,4 +81,13 @@ public class NewViewModel : ViewModelBase {
public ReactiveCommand<Unit, (int, string, int)> OkCommand { get; }
public ReactiveCommand<Unit, Unit> ClearCommand { get; }
}
/// <summary>
/// Clears the text fields.
/// </summary>
public void ClearText() {
PcgsNumber = "";
Grade = "";
Quantity = "";
}
}