diff --git a/BookReader/ViewModels/BookshelfViewModel.cs b/BookReader/ViewModels/BookshelfViewModel.cs index 10f06f5..3a2f3b7 100644 --- a/BookReader/ViewModels/BookshelfViewModel.cs +++ b/BookReader/ViewModels/BookshelfViewModel.cs @@ -19,9 +19,6 @@ public partial class BookshelfViewModel : BaseViewModel [ObservableProperty] private bool _isEmpty; - [ObservableProperty] - private bool _isRefreshing; - [ObservableProperty] private string _searchText = string.Empty; @@ -53,23 +50,22 @@ public partial class BookshelfViewModel : BaseViewModel [RelayCommand] public async Task LoadBooksAsync() { - if (IsBusy) return; IsBusy = true; try { var books = await _databaseService.GetAllBooksAsync(); - + // Применяем фильтр поиска если есть if (!string.IsNullOrWhiteSpace(SearchText)) { var searchLower = SearchText.ToLowerInvariant(); - books = books.Where(b => - b.Title.ToLowerInvariant().Contains(searchLower) || + books = books.Where(b => + b.Title.ToLowerInvariant().Contains(searchLower) || b.Author.ToLowerInvariant().Contains(searchLower) ).ToList(); } - + Books.Clear(); foreach (var book in books) { @@ -87,22 +83,6 @@ public partial class BookshelfViewModel : BaseViewModel } } - [RelayCommand] - public async Task RefreshBooksAsync() - { - if (IsRefreshing) return; - IsRefreshing = true; - - try - { - await LoadBooksAsync(); - } - finally - { - IsRefreshing = false; - } - } - [RelayCommand] public async Task SearchAsync(object? parameter) { diff --git a/BookReader/Views/BookshelfPage.xaml b/BookReader/Views/BookshelfPage.xaml index 15c132d..a326bb7 100644 --- a/BookReader/Views/BookshelfPage.xaml +++ b/BookReader/Views/BookshelfPage.xaml @@ -65,108 +65,95 @@ HorizontalTextAlignment="Center" /> - - - + + - - - + + + - - - - - - - - + + + + + + + + - - - - + + + + - - - - - + + + + + - - - + + + + + + + - - - - - - - - - - - - + + + + + @@ -208,4 +195,4 @@ Command="{Binding OpenCalibreLibraryCommand}" /> - \ No newline at end of file + diff --git a/BookReader/Views/BookshelfPage.xaml.cs b/BookReader/Views/BookshelfPage.xaml.cs index 1b701e2..1727fe9 100644 --- a/BookReader/Views/BookshelfPage.xaml.cs +++ b/BookReader/Views/BookshelfPage.xaml.cs @@ -16,10 +16,14 @@ public partial class BookshelfPage : ContentPage BindingContext = viewModel; } - protected override async void OnAppearing() + protected override void OnAppearing() { base.OnAppearing(); - await _viewModel.LoadBooksCommand.ExecuteAsync(null); + // Загружаем книги только если коллекция пуста + if (_viewModel.Books.Count == 0) + { + _ = _viewModel.LoadBooksCommand.ExecuteAsync(null); + } } private async void OnMenuClicked(object? sender, EventArgs e)