Pushing currently broken code.
This commit is contained in:
1 parent
435d01ef90
commit
4b2504b48c
10 files changed
+108
-36
No files matched your search
@@ -0,0 +1,30 @@
|
||||
using ReactiveUI;
|
||||
using System.Reactive;
|
||||
|
||||
namespace PcgsInvUi.ViewModels;
|
||||
|
||||
public class ApiKeyViewModel : ViewModelBase {
|
||||
public string ApiKeyInput {
|
||||
get => _apiKeyInput;
|
||||
set => this.RaiseAndSetIfChanged(ref _apiKeyInput, value);
|
||||
}
|
||||
private string _apiKeyInput = "";
|
||||
|
||||
public bool OkEnabled {
|
||||
get => _okEnabled;
|
||||
set => this.RaiseAndSetIfChanged(ref _okEnabled, value);
|
||||
}
|
||||
private bool _okEnabled;
|
||||
|
||||
public ReactiveCommand<Unit, string> OkCommand { get; }
|
||||
|
||||
public ApiKeyViewModel() {
|
||||
var okEnabled = this.WhenAnyValue(
|
||||
x => x.ApiKeyInput,
|
||||
x => !string.IsNullOrWhiteSpace(x));
|
||||
|
||||
|
||||
// Get the API key from the user.
|
||||
OkCommand = ReactiveCommand.Create(() => ApiKeyInput, okEnabled);
|
||||
}
|
||||
}
|
||||
@@ -39,10 +39,24 @@ public class MainWindowViewModel : ViewModelBase {
|
||||
public MainWindowViewModel(CoinDatabase coins, bool askForApiKey) {
|
||||
ConnectedCoinDatabase = coins;
|
||||
var newViewModel = new NewViewModel();
|
||||
_sideContent = newViewModel;
|
||||
// DisplayedList = CoinCollection = new ObservableCollection<Coin>(coins.GetItems());
|
||||
DisplayedList = ConnectedCoinDatabase.Collection;
|
||||
TotalValue = DisplayedList.Sum(x => x.TotalPrice);
|
||||
|
||||
// Setup interaction to show ApiKeyWindow
|
||||
// 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.
|
||||
ShowErrorWindow = new Interaction<ErrorWindowViewModel, bool>();
|
||||
|
||||
Reference in new issue
Block a user