Skip to content

Commit

Permalink
feat: improved UX for searching in the catalog
Browse files Browse the repository at this point in the history
  • Loading branch information
Donkey committed Dec 13, 2023
1 parent efa020e commit 2a4f9f2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 27 deletions.
21 changes: 6 additions & 15 deletions TwinpackVsixShared/Dialogs/CatalogWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,10 @@
</TextBlock>
</StackPanel>
<TextBlock Grid.Row="1" Margin="8 0 0 0" MaxHeight="50" Text="{Binding Description}"
d:Text="The path of the righteous man is beset on all sides by the iniquities of the selfish and the tyranny of the evil men. Blessed is he who, in the name of charity and goodwill, shepherds the weak through the valley of darkness, for he is truly his brother's keeper,"
TextWrapping="Wrap"/>
d:Text="The path of the righteous man is beset on all sides by the iniquities of the asdf sdf asdf sdf asf asdf sf sdf asfd sdf sdf selfish and the tyranny of the evil men. Blessed is he who, in the name of charity and goodwill, shepherds the weak through the valley of darkness, for he is truly his brother's keeper, III"
TextWrapping="Wrap"
TextTrimming="WordEllipsis"
/>
</Grid>

<Grid Grid.Column="2" HorizontalAlignment="Right" VerticalAlignment="Stretch">
Expand Down Expand Up @@ -276,17 +278,6 @@
Users are advised to use packages at their own discretion and risk.
</TextBlock>

<Grid Grid.Row="0" d:Visibility="Collapsed" Background="{DynamicResource {x:Static platform:EnvironmentColors.ToolboxBackgroundBrushKey}}" Visibility="{Binding IsCatalogLoading, Converter={StaticResource BooleanToVisibilityConverter}}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Grid HorizontalAlignment="Center" VerticalAlignment="Center">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<fa:ImageAwesome Margin="2 0 0 0" Foreground="{DynamicResource {x:Static platform:EnvironmentColors.ToolboxContentTextBrushKey}}" Icon="Spinner" Spin="True" Height="12"/>
<TextBlock Grid.Row="1" Text="Loading ..." HorizontalAlignment="Center" VerticalAlignment="Center"></TextBlock>
</Grid>
</Grid>

<GridSplitter Grid.Column="1" Grid.RowSpan="5" Width="5" HorizontalAlignment="Stretch"></GridSplitter>
<ScrollViewer Grid.RowSpan="6" x:Name="PackageVersionView" Visibility="{Binding PackageVersion, Converter={StaticResource NullToVisibilityConverter}}" Margin="5,0,0,0"
IsEnabled="{Binding IsPackageVersionPanelEnabled, ElementName=This}"
Expand Down Expand Up @@ -566,7 +557,7 @@
</Expander>
</StackPanel>

<Grid Grid.Row="1" Grid.RowSpan="3" d:Visibility="Hidden" Visibility="{Binding IsPackageVersionLoading, Converter={StaticResource BooleanToVisibilityConverter}}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Grid Grid.Row="1" Grid.RowSpan="3" d:Visibility="Visible" Visibility="{Binding IsPackageVersionLoading, Converter={StaticResource BooleanToVisibilityConverter}}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<StackPanel Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center">
<fa:ImageAwesome Margin="2 0 0 0" Icon="Spinner" Spin="True" Height="12"/>
<TextBlock Text="Loading ..." HorizontalAlignment="Center" VerticalAlignment="Center"></TextBlock>
Expand All @@ -577,7 +568,7 @@
</Grid>
</ScrollViewer>

<Grid Grid.Column="2" Grid.RowSpan="10" d:Visibility="Hidden" Background="{DynamicResource {x:Static platform:EnvironmentColors.ToolWindowBackgroundBrushKey}}"
<Grid Grid.Column="2" Grid.RowSpan="10" d:Visibility="Visible" Background="{DynamicResource {x:Static platform:EnvironmentColors.ToolWindowBackgroundBrushKey}}"
Visibility="{Binding IsPackageLoading, Converter={StaticResource BooleanToVisibilityConverter}}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<StackPanel Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center">
<fa:ImageAwesome Margin="2 0 0 0" Icon="Spinner" Spin="True" Height="12"/>
Expand Down
23 changes: 11 additions & 12 deletions TwinpackVsixShared/Dialogs/CatalogWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1224,16 +1224,17 @@ private async Task LoadNextCatalogPageAsync(string text = "", bool reset = false
var results = await _twinpackServer.GetCatalogAsync(text, _currentCatalogPage, _itemsPerPage, cancellationToken);
cancellationToken.ThrowIfCancellationRequested();
IsAvailablePackageAvailable = results.Item2;

if (reset)
{
_availablePackages.Clear();
}
bool newPackage = false;
foreach (var item in results.Item1)
{
_availablePackages.Add(new CatalogItem(item));
if(!_availablePackages.Any(x => x.PackageId == item.PackageId))
{
_availablePackages.Add(new CatalogItem(item));
newPackage = true;
}
}

IsAvailablePackageAvailable &= newPackage;
_currentCatalogPage++;

}
Expand Down Expand Up @@ -1262,7 +1263,6 @@ private async Task LoadInstalledPackagesAsync(CancellationToken cancellationToke

if (_plcConfig != null)
{
_installedPackages.Clear();
foreach (var item in _plcConfig.Packages)
{
CatalogItem catalogItem = new CatalogItem(item);
Expand All @@ -1271,7 +1271,8 @@ private async Task LoadInstalledPackagesAsync(CancellationToken cancellationToke
if (packageVersion.PackageVersionId != null)
catalogItem = new CatalogItem(packageVersion, item.Version);

_installedPackages.Add(catalogItem);
if(!_installedPackages.Any(x => x.PackageId == catalogItem.PackageId))
_installedPackages.Add(catalogItem);
}
}

Expand Down Expand Up @@ -1588,7 +1589,9 @@ public async void SearchTextBox_TextChanged(object sender, TextChangedEventArgs
try
{
var text = ((TextBox)sender).Text;
UpdateCatalog();

// this will only add additional items
if (IsBrowsingAvailablePackages)
{
_searchText = text;
Expand All @@ -1597,10 +1600,6 @@ public async void SearchTextBox_TextChanged(object sender, TextChangedEventArgs
if (_searchText == text)
await LoadAvailablePackagesAsync(text, Token);
}
else
{
UpdateCatalog();
}
}
catch (Exception ex)
{
Expand Down

0 comments on commit 2a4f9f2

Please sign in to comment.