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

+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.