fix: welcome page should use a shared singleton instance to manage and filter repositories (#117)

This commit is contained in:
leo 2024-05-07 14:12:33 +08:00
parent 06ca29b2b2
commit 4af8cc18d2
5 changed files with 5 additions and 11 deletions

View file

@ -114,7 +114,7 @@ namespace SourceGit.ViewModels
repo.Close();
last.Node = new RepositoryNode() { Id = Guid.NewGuid().ToString() };
last.Data = new Welcome();
last.Data = Welcome.Instance;
GC.Collect();
}

View file

@ -27,7 +27,7 @@ namespace SourceGit.ViewModels
public LauncherPage()
{
_node = new RepositoryNode() { Id = Guid.NewGuid().ToString() };
_data = new Welcome();
_data = Welcome.Instance;
}
public LauncherPage(RepositoryNode node, Repository repo)

View file

@ -8,7 +8,6 @@ using Avalonia.Collections;
using Avalonia.Controls;
using Avalonia.Media;
using Avalonia.Media.Imaging;
using Avalonia.Platform;
using Avalonia.Threading;
using CommunityToolkit.Mvvm.ComponentModel;

View file

@ -9,10 +9,7 @@ namespace SourceGit.ViewModels
{
public class Welcome : ObservableObject
{
public bool IsClearSearchVisible
{
get => !string.IsNullOrEmpty(_searchFilter);
}
public static Welcome Instance => _instance;
public AvaloniaList<RepositoryNode> RepositoryNodes
{
@ -25,10 +22,7 @@ namespace SourceGit.ViewModels
set
{
if (SetProperty(ref _searchFilter, value))
{
Referesh();
OnPropertyChanged(nameof(IsClearSearchVisible));
}
}
}
@ -205,6 +199,7 @@ namespace SourceGit.ViewModels
}
}
private static Welcome _instance = new Welcome();
private string _searchFilter = string.Empty;
}
}