Fix threading issue related to Theme switch
MODIFY
WalletWasabi.Fluent/ViewModels/SearchBar/SearchBarViewModel.cs
WalletWasabi.Fluent/ViewModels/SearchBar/SearchBarViewModel.cs
using System.Collections.ObjectModel;
using System.Linq;
using System.Reactive.Linq;
+using System.Text.RegularExpressions;
using DynamicData;
+using DynamicData.Aggregation;
using ReactiveUI;
using WalletWasabi.Fluent.ViewModels.SearchBar.Patterns;
using WalletWasabi.Fluent.ViewModels.SearchBar.SearchItems;
@@ -22,9 +24,11 @@ public partial class SearchBarViewModel : ReactiveObject
.DistinctUntilChanged()
.Select(SearchItemFilterFunc);
- itemsObservable
+ var filteredItems = itemsObservable
.RefCount()
- .Filter(filterPredicate)
+ .Filter(filterPredicate);
+
+ filteredItems
.Transform(item => item is ActionableItem i ? new AutocloseActionableItem(i, () => IsSearchListVisible = false) : item)
.Group(s => s.Category)
.Transform(group => new SearchItemGroup(group.Key, group.Cache))
@@ -32,8 +36,15 @@ public partial class SearchBarViewModel : ReactiveObject
.DisposeMany()
.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe();
+
+ Any = filteredItems
+ .Count()
+ .Select(i => i > 0)
+ .ObserveOn(RxApp.MainThreadScheduler);
}
+ public IObservable<bool> Any { get; }
+
public ReadOnlyObservableCollection<SearchItemGroup> Groups => _groups;
private static Func<ISearchItem, bool> SearchItemFilterFunc(string? text)

MODIFY
WalletWasabi.Fluent/ViewModels/SearchBar/SearchItemGroup.cs
WalletWasabi.Fluent/ViewModels/SearchBar/SearchItemGroup.cs
using System.Collections.ObjectModel;
+using System.Reactive.Disposables;
using System.Reactive.Linq;
using DynamicData;
using ReactiveUI;
@@ -7,8 +8,9 @@ using WalletWasabi.Fluent.ViewModels.SearchBar.SearchItems;
namespace WalletWasabi.Fluent.ViewModels.SearchBar;
-public class SearchItemGroup
+public class SearchItemGroup : IDisposable
{
+ private readonly CompositeDisposable _disposables = new();
private readonly ReadOnlyObservableCollection<ISearchItem> _items;
public SearchItemGroup(string title, IObservableCache<ISearchItem, ComposedKey> groupCache)
@@ -18,10 +20,16 @@ public class SearchItemGroup
.Bind(out _items)
.DisposeMany()
.ObserveOn(RxApp.MainThreadScheduler)
- .Subscribe();
+ .Subscribe()
+ .DisposeWith(_disposables);
}
public string Title { get; }
public ReadOnlyObservableCollection<ISearchItem> Items => _items;
+
+ public void Dispose()
+ {
+ _disposables.Dispose();
+ }
}
\ No newline at end of file

MODIFY
WalletWasabi.Fluent/Views/SearchBar/SearchBarDropdown.axaml
WalletWasabi.Fluent/Views/SearchBar/SearchBarDropdown.axaml
<Setter Property="Background" Value="Transparent" />
</Style>
- <Style Selector="ItemsControl:empty">
- <Setter Property="Template">
- <Setter.Value>
- <ControlTemplate>
- <TextBlock Margin="10">No results</TextBlock>
- </ControlTemplate>
- </Setter.Value>
- </Setter>
- </Style>
-
<Style Selector="Button.searchItem /template/ ContentPresenter">
<Setter Property="Background" Value="Transparent" />
</Style>
</UserControl.DataTemplates>
- <ItemsControl Items="{Binding Groups}">
+ <Panel VerticalAlignment="Center">
+ <TextBlock IsVisible="{Binding !Any^}" Margin="10">No results</TextBlock>
+ <ItemsControl IsVisible="{Binding Any^}" Items="{Binding Groups}">
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type sb:SearchItemGroup}">
<DockPanel Margin="0 0 0 10">
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
+ </Panel>
</UserControl>

Fix threading issue related to Theme switch