Created frame for FindWindow, shortened CoinCollection

This commit is contained in:
alphafetus committed 2023-10-18 17:12:49 -04:00
1 parent f298296471
commit 3234b12184
11 files changed
+70 -19

No files matched your search

+1
View File
@@ -6,6 +6,7 @@
<entry key="PcgsInvUi/App.axaml" value="PcgsInvUi/PcgsInvUi.csproj" /> <entry key="PcgsInvUi/App.axaml" value="PcgsInvUi/PcgsInvUi.csproj" />
<entry key="PcgsInvUi/Views/CoinListView.axaml" value="PcgsInvUi/PcgsInvUi.csproj" /> <entry key="PcgsInvUi/Views/CoinListView.axaml" value="PcgsInvUi/PcgsInvUi.csproj" />
<entry key="PcgsInvUi/Views/DeleteWindow.axaml" value="PcgsInvUi/PcgsInvUi.csproj" /> <entry key="PcgsInvUi/Views/DeleteWindow.axaml" value="PcgsInvUi/PcgsInvUi.csproj" />
<entry key="PcgsInvUi/Views/FindWindow.axaml" value="PcgsInvUi/PcgsInvUi.csproj" />
<entry key="PcgsInvUi/Views/MainWindow.axaml" value="PcgsInvUi/PcgsInvUi.csproj" /> <entry key="PcgsInvUi/Views/MainWindow.axaml" value="PcgsInvUi/PcgsInvUi.csproj" />
<entry key="PcgsInvUi/Views/MainWindowOld.axaml" value="PcgsInvUi/PcgsInvUi.csproj" /> <entry key="PcgsInvUi/Views/MainWindowOld.axaml" value="PcgsInvUi/PcgsInvUi.csproj" />
<entry key="PcgsInvUi/Views/NewControl.axaml" value="PcgsInvUi/PcgsInvUi.csproj" /> <entry key="PcgsInvUi/Views/NewControl.axaml" value="PcgsInvUi/PcgsInvUi.csproj" />
-14
View File
@@ -10,19 +10,5 @@ public class CoinCollection
new Coin(), new Coin(),
new Coin(), new Coin(),
new Coin(), new Coin(),
new Coin(),
new Coin(),
new Coin(),
new Coin(),
new Coin(),
new Coin(),
new Coin(),
new Coin(),
new Coin(),
new Coin(),
new Coin(),
new Coin(),
new Coin(),
new Coin(),
}; };
} }
@@ -6,11 +6,12 @@ namespace PcgsInvUi.ViewModels;
public class DeleteWindowViewModel : ViewModelBase public class DeleteWindowViewModel : ViewModelBase
{ {
public ReactiveCommand<Unit, object> OkCommand { get; } = ReactiveCommand.Create(() => (object)true); public ReactiveCommand<Unit, object> OkCommand { get; }
public ReactiveCommand<DeleteWindow, Unit> CancelCommand { get; } public ReactiveCommand<DeleteWindow, Unit> CancelCommand { get; }
public DeleteWindowViewModel() public DeleteWindowViewModel()
{ {
OkCommand = ReactiveCommand.Create(() => (object)true);
CancelCommand = ReactiveCommand.Create<DeleteWindow>(window => window.Close()); CancelCommand = ReactiveCommand.Create<DeleteWindow>(window => window.Close());
} }
} }
@@ -0,0 +1,9 @@
using System.Reactive;
using ReactiveUI;
namespace PcgsInvUi.ViewModels;
public class FindWindowViewModel : ViewModelBase
{
public ReactiveCommand<Unit, object> OkCommand { get; } = ReactiveCommand.Create(() => (object)1);
}
+18 -1
View File
@@ -27,6 +27,7 @@ public class MainWindowViewModel : ViewModelBase
private set => this.RaiseAndSetIfChanged(ref _sideContent, value); private set => this.RaiseAndSetIfChanged(ref _sideContent, value);
} }
public ObservableCollection<Coin> CoinCollection { get; set; } public ObservableCollection<Coin> CoinCollection { get; set; }
public ObservableCollection<Coin> DisplayedList { get; set; }
public Coin? SelectedCoin public Coin? SelectedCoin
{ {
get => _selectedCoin; get => _selectedCoin;
@@ -39,6 +40,8 @@ public class MainWindowViewModel : ViewModelBase
} }
public ReactiveCommand<Unit, Unit> DeleteCommand { get; } public ReactiveCommand<Unit, Unit> DeleteCommand { get; }
public Interaction<DeleteWindowViewModel, Boolean> ShowDeleteWindow { get; } public Interaction<DeleteWindowViewModel, Boolean> ShowDeleteWindow { get; }
public ReactiveCommand<Unit, Coin> FindCommand { get; }
public Interaction<FindWindowViewModel, int> ShowFindWindow { get; }
private ViewModelBase _sideContent; private ViewModelBase _sideContent;
private Coin? _selectedCoin; private Coin? _selectedCoin;
@@ -49,9 +52,10 @@ public class MainWindowViewModel : ViewModelBase
{ {
var newViewModel = new NewViewModel(); var newViewModel = new NewViewModel();
_sideContent = newViewModel; _sideContent = newViewModel;
CoinCollection = new ObservableCollection<Coin>(coins.GetItems()); 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>(); ShowDeleteWindow = new Interaction<DeleteWindowViewModel, bool>();
var deleteEnabled = this.WhenAnyValue(x => x.SelectedCoin) var deleteEnabled = this.WhenAnyValue(x => x.SelectedCoin)
.Select(x => x != null); .Select(x => x != null);
@@ -61,6 +65,19 @@ public class MainWindowViewModel : ViewModelBase
var result = await ShowDeleteWindow.Handle(deleteViewModel); 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); }, 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 () =>
{
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)> // Subscribe to SidebarContent.OkCommand, which is an IObservable<(int, string, int)>
// This is the same as the above, but with a different syntax. // This is the same as the above, but with a different syntax.
+1 -1
View File
@@ -50,7 +50,7 @@ public class NewViewModel : ViewModelBase
// Initialize grade values for use in the view. // 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. // 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", "P-01",
"FR-02", "FR-02",
-1
View File
@@ -3,7 +3,6 @@ using Avalonia.ReactiveUI;
using ReactiveUI; using ReactiveUI;
using System; using System;
namespace PcgsInvUi.Views; namespace PcgsInvUi.Views;
public partial class DeleteWindow : ReactiveWindow<DeleteWindowViewModel> public partial class DeleteWindow : ReactiveWindow<DeleteWindowViewModel>
+14
View File
@@ -0,0 +1,14 @@
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="PcgsInvUi.Views.FindWindow"
Title="FindWindow">
<Grid ColumnDefinitions="Auto, *" RowDefinitions="*, *">
<Label Content="PCGS #:" VerticalAlignment="Center" HorizontalAlignment="Right" Margin="5"/>
<TextBox Grid.Row="0" Grid.Column="1" Margin="5"/>
<Button Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Content="Find"
HorizontalAlignment="Center" Margin="5" Width="75"/>
</Grid>
</Window>
+15
View File
@@ -0,0 +1,15 @@
using Avalonia.ReactiveUI;
using PcgsInvUi.ViewModels;
using ReactiveUI;
using System;
namespace PcgsInvUi.Views;
public partial class FindWindow : ReactiveWindow<FindWindowViewModel>
{
public FindWindow()
{
InitializeComponent();
this.WhenActivated(d => d(ViewModel!.OkCommand.Subscribe(Close)));
}
}
+1 -1
View File
@@ -19,7 +19,7 @@
<Grid RowDefinitions="*, Auto" ShowGridLines="False"> <Grid RowDefinitions="*, Auto" ShowGridLines="False">
<DataGrid Grid.Row="0" HorizontalAlignment="Stretch" <DataGrid Grid.Row="0" HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" VerticalAlignment="Stretch"
ItemsSource="{Binding CoinCollection}" ItemsSource="{Binding DisplayedList}"
SelectedItem="{Binding SelectedCoin, Mode=TwoWay}" SelectedItem="{Binding SelectedCoin, Mode=TwoWay}"
AutoGenerateColumns="False" AutoGenerateColumns="False"
CanUserResizeColumns="True"> CanUserResizeColumns="True">
+9
View File
@@ -22,4 +22,13 @@ public partial class MainWindow : ReactiveWindow<MainWindowViewModel>
var result = await window.ShowDialog<bool>(this); var result = await window.ShowDialog<bool>(this);
interaction.SetOutput(result); interaction.SetOutput(result);
} }
public async Task ShowFindWindowAsync(InteractionContext<FindWindowViewModel, int> interaction)
{
var window = new FindWindow();
window.DataContext = interaction.Input;
var result = await window.ShowDialog<int>(this);
interaction.SetOutput(result);
}
} }