temp: broken push to laptop

This commit is contained in:
alphafetus committed 2026-06-19 12:31:12 -04:00
1 parent 0a0ea86d25
commit 3a819ce180
32 files changed
+503 -573

No files matched your search

+14 -26
View File
@@ -1,30 +1,18 @@
using ReactiveUI;
using System.Reactive;
using System.Diagnostics;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
namespace PcgsInvUi.ViewModels;
public class ApiKeyViewModel : ViewModelBase {
public string ApiKeyInput {
get => _apiKeyInput;
set => this.RaiseAndSetIfChanged(ref _apiKeyInput, value);
public partial class ApiKeyViewModel : ViewModelBase {
[ObservableProperty]
public partial string ApiKeyInput { get; set; }
[ObservableProperty]
public partial bool OkEnabled { get; set; }
[RelayCommand]
public void OkCommand() {
Debug.WriteLine("Running OkCommand from ApiKeyViewModel");
}
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);
}
}
}
+12 -15
View File
@@ -1,23 +1,20 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using PcgsInvUi.Models;
using ReactiveUI;
using CommunityToolkit.Mvvm.ComponentModel;
namespace PcgsInvUi.ViewModels;
public class CoinListViewModel : ViewModelBase {
public ObservableCollection<Coin> CoinCollection { get; set; }
private float _totalValue;
public float TotalValue {
get => _totalValue;
set => this.RaiseAndSetIfChanged(ref _totalValue, value);
}
public Coin? SelectedCoin { get; set; }
public CoinListViewModel(IEnumerable<Coin> items) {
CoinCollection = new ObservableCollection<Coin>(items);
public partial class CoinListViewModel : ViewModelBase {
public CoinListViewModel(IEnumerable<PcgsCoin> items) {
CoinCollection = new ObservableCollection<PcgsCoin>(items);
TotalValue = 0;
}
public ObservableCollection<PcgsCoin> CoinCollection { get; set; }
[ObservableProperty]
public partial float TotalValue { get; set; }
[ObservableProperty]
public partial PcgsCoin? SelectedCoin { get; set; }
}
@@ -4,11 +4,11 @@ using ReactiveUI;
namespace PcgsInvUi.ViewModels;
public class DeleteWindowViewModel : ViewModelBase {
public ReactiveCommand<Unit, object> OkCommand { get; }
public ReactiveCommand<Unit, object> CancelCommand { get; }
public DeleteWindowViewModel() {
OkCommand = ReactiveCommand.Create(() => (object)true);
CancelCommand = ReactiveCommand.Create(() => (object)false);
}
}
public ReactiveCommand<Unit, object> OkCommand { get; }
public ReactiveCommand<Unit, object> CancelCommand { get; }
}
+11 -12
View File
@@ -1,27 +1,26 @@
using System.Reactive;
using PcgsInvUi.Models;
using ReactiveUI;
namespace PcgsInvUi.ViewModels;
public class EditViewModel : ViewModelBase {
public Coin CurrentCoin { get; set; }
public ReactiveCommand<Unit, Unit> OkCommand { get; }
public EditViewModel(Coin coin) {
CurrentCoin = coin;
public EditViewModel(PcgsCoin pcgsCoin) {
CurrentPcgsCoin = pcgsCoin;
var okEnabled = this.WhenAnyValue(
x => x.CurrentCoin.PCGSNo,
x => x.CurrentCoin.Grade,
x => x.CurrentCoin.Quantity,
x => x.CurrentPcgsCoin.PcgsNumber,
x => x.CurrentPcgsCoin.Grade,
x => x.CurrentPcgsCoin.Quantity,
(id, grade, quantity) => !string.IsNullOrWhiteSpace(id) &&
!string.IsNullOrWhiteSpace(grade) &&
(quantity != 0)
quantity != 0
);
// Setup OkCommand - all Coin-related properties must be non-whitespace.
OkCommand = ReactiveCommand.Create(() => { });
}
}
public PcgsCoin CurrentPcgsCoin { get; set; }
public ReactiveCommand<Unit, Unit> OkCommand { get; }
}
+17 -18
View File
@@ -1,23 +1,22 @@
using System.Reactive;
using ReactiveUI;
using Avalonia.Controls;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
namespace PcgsInvUi.ViewModels;
namespace PcgsInvUi.ViewModels;
public class ErrorWindowViewModel : ViewModelBase {
public partial class ErrorWindowViewModel : ViewModelBase {
private readonly Window _dialog;
public string DisplayedMessage {
get => _message;
set => this.RaiseAndSetIfChanged(ref _message, value);
}
private string _message;
public ReactiveCommand<Unit, object> CloseCommand { get; }
public ErrorWindowViewModel(string message)
{
_message = message;
CloseCommand = ReactiveCommand.Create(() => (object)false);
public ErrorWindowViewModel(Window dialog, string message) {
_dialog = dialog;
Message = message;
}
}
[ObservableProperty]
public partial string Message { get; set; }
[RelayCommand]
public void Close() {
_dialog.Close();
}
}
+44 -45
View File
@@ -1,45 +1,19 @@
using System;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Reactive;
using System.Reactive.Linq;
using PcgsInvUi.Models;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.ComponentModel;
using PcgsInvUi.Services;
using ReactiveUI;
using System.Threading.Tasks;
namespace PcgsInvUi.ViewModels;
public class MainWindowViewModel : ViewModelBase {
public ViewModelBase SidebarContent {
get => _sideContent;
private set => this.RaiseAndSetIfChanged(ref _sideContent, value);
}
public ObservableCollection<Coin> DisplayedList { get; set; }
public CoinDatabase ConnectedCoinDatabase { get; set; }
public Coin? SelectedCoin {
get => _selectedCoin;
set => this.RaiseAndSetIfChanged(ref _selectedCoin, value);
}
public double TotalValue {
get => _totalValue;
set => this.RaiseAndSetIfChanged(ref _totalValue, value);
}
public ReactiveCommand<Unit, Unit> DeleteCommand { get; }
public Interaction<DeleteWindowViewModel, Boolean> ShowDeleteWindow { get; }
public ReactiveCommand<Unit, Unit> ExportCommand { get; }
public Interaction<Unit, Uri> ShowExportWindow { get; }
public Interaction<ErrorWindowViewModel, bool> ShowErrorWindow { get; }
private ViewModelBase _sideContent;
private Coin? _selectedCoin;
private double _totalValue;
public partial class MainWindowViewModel : ViewModelBase {
public MainWindowViewModel(CoinDatabase coins) {
ConnectedCoinDatabase = coins;
var keyFound = Task.Run(() => coins.TryInitApiClient()).Result;
var keyFound = Task.Run(coins.TryInitApiClient).Result;
Console.WriteLine("Function completed.");
var newViewModel = new NewViewModel();
var apiKeyViewModel = new ApiKeyViewModel();
@@ -48,21 +22,25 @@ public class MainWindowViewModel : ViewModelBase {
TotalValue = DisplayedList.Sum(x => x.TotalPrice);
// Setup interaction to show ApiKeyWindow
apiKeyViewModel.OkCommand.Subscribe(async apiKey => {
apiKeyViewModel.OkCommandCommand.Subscribe(async apiKey => {
if (await ConnectedCoinDatabase.TryInitApiClient(apiKey))
SidebarContent = newViewModel; // Must assign this to the observable property rather than private variable.
});
SidebarContent =
newViewModel; // Must assign this to the observable property rather than private variable.
});
// Check if API key must be entered.
if (!keyFound) {
Console.WriteLine("API key must be entered by user.");
// Show the API key input view.
_sideContent = apiKeyViewModel;
} else _sideContent = newViewModel;
SidebarContent = apiKeyViewModel;
}
else {
SidebarContent = newViewModel;
}
// Set up the ability to show the error window.
ShowErrorWindow = new Interaction<ErrorWindowViewModel, bool>();
// Set up the ability to open the delete window.
ShowDeleteWindow = new Interaction<DeleteWindowViewModel, bool>();
var deleteEnabled = this.WhenAnyValue(x => x.SelectedCoin)
@@ -89,23 +67,25 @@ public class MainWindowViewModel : ViewModelBase {
// Something is wrong with the file after it's been created.
Console.WriteLine(e.Message);
await ShowErrorWindow.Handle(new ErrorWindowViewModel(e.Message));
} catch (Exception e) {
}
catch (Exception e) {
Console.WriteLine(e.Message);
await ShowErrorWindow.Handle(new ErrorWindowViewModel(e.Message));
}
});
// Subscribe to SidebarContent.OkCommand, which is an IObservable<(int, string, int)>
// This is the same as the above, but with a different syntax.
newViewModel.OkCommand
.Subscribe(async requestStructure => {
var result = await ConnectedCoinDatabase.CreateCoin(requestStructure.Item1, requestStructure.Item2,
requestStructure.Item3);
switch (result) {
case PcgsClient.ErrorType.ApiKeyInvalid:
Console.WriteLine("API key is invalid - showing window.");
await ShowErrorWindow.Handle(new ErrorWindowViewModel("API key is invalid - authorization failed."));
await ShowErrorWindow.Handle(
new ErrorWindowViewModel("API key is invalid - authorization failed."));
break;
case PcgsClient.ErrorType.InvalidRequestFormat:
Console.WriteLine("Request format is invalid - showing window.");
@@ -113,14 +93,15 @@ public class MainWindowViewModel : ViewModelBase {
break;
case PcgsClient.ErrorType.NoCoinFound:
Console.WriteLine("No coin was found with the given parameters.");
await ShowErrorWindow.Handle(new ErrorWindowViewModel("No coin was found with the given parameters."));
await ShowErrorWindow.Handle(
new ErrorWindowViewModel("No coin was found with the given parameters."));
break;
}
// Clear the text boxes.
newViewModel.ClearText();
});
// Update TotalValue anytime a coin's quantity changes.
// Possible null reference is currently ignored - SelectedCoin will never be null.
this.WhenAnyValue(x => x.SelectedCoin.TotalPrice)
@@ -132,10 +113,28 @@ public class MainWindowViewModel : ViewModelBase {
};
}
[ObservableProperty]
public partial ViewModelBase SidebarContent { get; private set; }
public ObservableCollection<PcgsCoin> DisplayedList { get; set; }
public CoinDatabase ConnectedCoinDatabase { get; set; }
[ObservableProperty]
public partial PcgsCoin? SelectedCoin { get; set; }
[ObservableProperty]
public partial double TotalValue { get; set; }
public ReactiveCommand<Unit, Unit> DeleteCommand { get; }
public Interaction<DeleteWindowViewModel, bool> ShowDeleteWindow { get; }
public ReactiveCommand<Unit, Unit> ExportCommand { get; }
public Interaction<Unit, Uri> ShowExportWindow { get; }
public Interaction<ErrorWindowViewModel, bool> ShowErrorWindow { get; }
// Create destructor to save the database when the application exits.
// This is necessary because the database is initialized in this class.
~MainWindowViewModel() {
Console.WriteLine("Running MainWindowViewModel destructor.");
ConnectedCoinDatabase.UpdateCollection("CollectionTable");
}
}
}
+23 -25
View File
@@ -1,31 +1,14 @@
using System.Reactive;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Reactive;
using ReactiveUI;
namespace PcgsInvUi.ViewModels;
public class NewViewModel : ViewModelBase {
private string _pcgsNumber = "";
private string _grade = "";
private string _pcgsNumber = "";
private string _quantity = "";
public string PcgsNumber {
get => _pcgsNumber;
set => this.RaiseAndSetIfChanged(ref _pcgsNumber, value);
}
public string Grade {
get => _grade;
set => this.RaiseAndSetIfChanged(ref _grade, value);
}
public string Quantity {
get => _quantity;
set => this.RaiseAndSetIfChanged(ref _quantity, value);
}
public List<string> GradesList { get; }
public NewViewModel() {
var okEnabled = this.WhenAnyValue(
x => x.PcgsNumber,
@@ -39,9 +22,7 @@ public class NewViewModel : ViewModelBase {
() => (int.Parse(PcgsNumber), Grade, int.Parse(Quantity)),
okEnabled);
ClearCommand = ReactiveCommand.Create(() => {
ClearText();
});
ClearCommand = ReactiveCommand.Create(() => { ClearText(); });
// Initialize grade values for use in the view.
// This must be typed out manually, as there is no way to get a list of grades from the API.
@@ -79,15 +60,32 @@ public class NewViewModel : ViewModelBase {
};
}
public string PcgsNumber {
get => _pcgsNumber;
set => this.RaiseAndSetIfChanged(ref _pcgsNumber, value);
}
public string Grade {
get => _grade;
set => this.RaiseAndSetIfChanged(ref _grade, value);
}
public string Quantity {
get => _quantity;
set => this.RaiseAndSetIfChanged(ref _quantity, value);
}
public List<string> GradesList { get; }
public ReactiveCommand<Unit, (int, string, int)> OkCommand { get; }
public ReactiveCommand<Unit, Unit> ClearCommand { get; }
/// <summary>
/// Clears the text fields.
/// Clears the text fields.
/// </summary>
public void ClearText() {
PcgsNumber = "";
Grade = "";
Quantity = "";
}
}
}
+2 -2
View File
@@ -1,5 +1,5 @@
using ReactiveUI;
using CommunityToolkit.Mvvm.ComponentModel;
namespace PcgsInvUi.ViewModels;
public class ViewModelBase : ReactiveObject { }
public class ViewModelBase : ObservableObject { }