Reformatted and cleaned up code across whole project.

This commit is contained in:
alphafetus committed 2023-10-24 09:04:04 -04:00
1 parent 42a7871ed4
commit 99cb9268dd
25 files changed
+272 -319

No files matched your search

+6 -7
View File
@@ -5,19 +5,18 @@ using ReactiveUI;
namespace PcgsInvUi.ViewModels;
public class CoinListViewModel : ViewModelBase
{
public class CoinListViewModel : ViewModelBase {
public ObservableCollection<Coin> CoinCollection { get; set; }
private float _totalValue;
public float TotalValue
{
public float TotalValue {
get => _totalValue;
set => this.RaiseAndSetIfChanged(ref _totalValue, value);
}
public Coin? SelectedCoin { get; set; }
public CoinListViewModel(IEnumerable<Coin> items)
{
public CoinListViewModel(IEnumerable<Coin> items) {
CoinCollection = new ObservableCollection<Coin>(items);
TotalValue = 0;
}
@@ -4,14 +4,12 @@ using ReactiveUI;
namespace PcgsInvUi.ViewModels;
public class DeleteWindowViewModel : ViewModelBase
{
public class DeleteWindowViewModel : ViewModelBase {
public ReactiveCommand<Unit, object> OkCommand { get; }
public ReactiveCommand<DeleteWindow, Unit> CancelCommand { get; }
public DeleteWindowViewModel()
{
OkCommand = ReactiveCommand.Create(() => (object)true);
public DeleteWindowViewModel() {
OkCommand = ReactiveCommand.Create(() => (object)true);
CancelCommand = ReactiveCommand.Create<DeleteWindow>(window => window.Close());
}
}
+4 -6
View File
@@ -5,14 +5,12 @@ using ReactiveUI;
namespace PcgsInvUi.ViewModels;
public class EditViewModel : ViewModelBase
{
public class EditViewModel : ViewModelBase {
public Coin CurrentCoin { get; set; }
public ReactiveCommand<Unit, Unit> OkCommand { get; }
public EditViewModel(Coin coin)
{
public EditViewModel(Coin coin) {
CurrentCoin = coin;
var okEnabled = this.WhenAnyValue(
@@ -23,7 +21,7 @@ public class EditViewModel : ViewModelBase
!string.IsNullOrWhiteSpace(grade) &&
(quantity != 0)
);
// Setup OkCommand - all Coin-related properties must be non-whitespace.
OkCommand = ReactiveCommand.Create(() => { });
}
+1 -2
View File
@@ -3,7 +3,6 @@ using ReactiveUI;
namespace PcgsInvUi.ViewModels;
public class FindWindowViewModel : ViewModelBase
{
public class FindWindowViewModel : ViewModelBase {
public ReactiveCommand<Unit, object> OkCommand { get; } = ReactiveCommand.Create(() => (object)1);
}
+22 -24
View File
@@ -19,80 +19,78 @@ namespace PcgsInvUi.ViewModels;
// TODO API request tracker (1000 per day)
// TODO API update schedules (per month? manual override? needs to store a date of last update in the coin object)
public class MainWindowViewModel : ViewModelBase
{
public ViewModelBase SidebarContent
{
public class MainWindowViewModel : ViewModelBase {
public ViewModelBase SidebarContent {
get => _sideContent;
private set => this.RaiseAndSetIfChanged(ref _sideContent, value);
}
public ObservableCollection<Coin> CoinCollection { get; set; }
public ObservableCollection<Coin> DisplayedList { get; set; }
public Coin? SelectedCoin
{
public Coin? SelectedCoin {
get => _selectedCoin;
set => this.RaiseAndSetIfChanged(ref _selectedCoin, value);
}
public double TotalValue
{
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, Coin> FindCommand { get; }
public Interaction<FindWindowViewModel, int> ShowFindWindow { get; }
private ViewModelBase _sideContent;
private Coin? _selectedCoin;
private double _totalValue;
private PcgsClient _pcgsClient;
public MainWindowViewModel(CoinCollection coins)
{
public MainWindowViewModel(CoinCollection coins) {
var newViewModel = new NewViewModel();
_sideContent = newViewModel;
DisplayedList = CoinCollection = new ObservableCollection<Coin>(coins.GetItems());
_pcgsClient = new PcgsClient("eAb8gS0I2XAvT_5gJeiGJaglMia1Tk-oB4kJUK6kuafyrny_S61vIJY-Ikl4nCQM67wrdxzUqLVWTV2kBSxD3d5XNBHxHnYBhcSS6dOPug0hZaF3qAv56df3gYSzOGh9Tif5y0eP3Iw0LrqKDr1Hj-dk6SV6GKog2IIqCPQhhHH8FMTWBTYO-_O8cx7qLdM5GM8KlTsic6g3VRUhM8EA_4OO04dCfmNLGhqINRl3jGZ0Q4ziI8fng2bVWsIyteqiPzUn10rIQ3-OPpqVZG_DxeOmOejj4GzbUNyqUOajy-nr5rYY");
_pcgsClient = new PcgsClient(
"eAb8gS0I2XAvT_5gJeiGJaglMia1Tk-oB4kJUK6kuafyrny_S61vIJY-Ikl4nCQM67wrdxzUqLVWTV2kBSxD3d5XNBHxHnYBhcSS6dOPug0hZaF3qAv56df3gYSzOGh9Tif5y0eP3Iw0LrqKDr1Hj-dk6SV6GKog2IIqCPQhhHH8FMTWBTYO-_O8cx7qLdM5GM8KlTsic6g3VRUhM8EA_4OO04dCfmNLGhqINRl3jGZ0Q4ziI8fng2bVWsIyteqiPzUn10rIQ3-OPpqVZG_DxeOmOejj4GzbUNyqUOajy-nr5rYY");
// Set up the ability to open the delete window.
ShowDeleteWindow = new Interaction<DeleteWindowViewModel, bool>();
var deleteEnabled = this.WhenAnyValue(x => x.SelectedCoin)
.Select(x => x != null);
DeleteCommand = ReactiveCommand.CreateFromTask(async () =>
{
DeleteCommand = ReactiveCommand.CreateFromTask(async () => {
var deleteViewModel = new DeleteWindowViewModel();
var result = await ShowDeleteWindow.Handle(deleteViewModel);
if (result) CoinCollection.Remove(SelectedCoin); // possible null deref - ignored due to button being disabled.
if (result)
CoinCollection.Remove(SelectedCoin); // possible null deref - ignored due to button being disabled.
}, deleteEnabled);
// Set up the ability to open the find window.
ShowFindWindow = new Interaction<FindWindowViewModel, int>();
var findEnabled = this.WhenAnyValue(x => x.CoinCollection.Count,
x => x > 0);
FindCommand = ReactiveCommand.CreateFromTask(async () =>
{
FindCommand = ReactiveCommand.CreateFromTask(async () => {
var findViewModel = new FindWindowViewModel();
var result = await ShowFindWindow.Handle(findViewModel);
// Find the coin with the matching ID. The issue is that there could be multiple - so we need to return a list.
// Perhaps a secondary viewmodel?
return new Coin();
}, findEnabled);
// 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 =>
{
.Subscribe(async requestStructure => {
var newCoin = await _pcgsClient.GetCoinFactsByGrade(requestStructure.Item1, requestStructure.Item2);
newCoin.Quantity = requestStructure.Item3;
CoinCollection.Add(newCoin);
TotalValue += newCoin.Quantity * newCoin.PriceGuideValue;
});
// Change TotalValue anytime SelectedCoin.TotalPrice changes.
// Possible null deref - ignored due to null values summing to 0.
this.WhenAnyValue(x => x.SelectedCoin.TotalPrice)
.Subscribe(_ => TotalValue = CoinCollection.Sum(x => x.TotalPrice) );
.Subscribe(_ => TotalValue = CoinCollection.Sum(x => x.TotalPrice));
}
}
}
+13 -18
View File
@@ -4,31 +4,29 @@ using ReactiveUI;
namespace PcgsInvUi.ViewModels;
public class NewViewModel : ViewModelBase
{
public class NewViewModel : ViewModelBase {
private string _pcgsNumber = "";
private string _grade = "";
private string _quantity = "";
public string PcgsNumber
{
public string PcgsNumber {
get => _pcgsNumber;
set => this.RaiseAndSetIfChanged(ref _pcgsNumber, value);
}
public string Grade
{
public string Grade {
get => _grade;
set => this.RaiseAndSetIfChanged(ref _grade, value);
}
public string Quantity
{
public string Quantity {
get => _quantity;
set => this.RaiseAndSetIfChanged(ref _quantity, value);
}
public List<string> GradesList { get; }
public NewViewModel()
{
public NewViewModel() {
var okEnabled = this.WhenAnyValue(
x => x.PcgsNumber,
x => x.Grade,
@@ -40,9 +38,8 @@ public class NewViewModel : ViewModelBase
OkCommand = ReactiveCommand.Create(
() => (int.Parse(PcgsNumber), Grade, int.Parse(Quantity)),
okEnabled);
ClearCommand = ReactiveCommand.Create(() =>
{
ClearCommand = ReactiveCommand.Create(() => {
PcgsNumber = "";
Grade = "";
Quantity = "";
@@ -50,8 +47,7 @@ public class NewViewModel : ViewModelBase
// 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.
GradesList = new List<string>
{
GradesList = new List<string> {
"P-01",
"FR-02",
"AG-03",
@@ -84,8 +80,7 @@ public class NewViewModel : ViewModelBase
"MS-70"
};
}
public ReactiveCommand<Unit, (int, string, int)> OkCommand { get; }
public ReactiveCommand<Unit, Unit> ClearCommand { get; }
}
+1 -3
View File
@@ -2,6 +2,4 @@
namespace PcgsInvUi.ViewModels;
public class ViewModelBase : ReactiveObject
{
}
public class ViewModelBase : ReactiveObject { }