diff --git a/readeck/UI/Bookmarks/BookmarksView.swift b/readeck/UI/Bookmarks/BookmarksView.swift index 3f28b87..fa756ff 100644 --- a/readeck/UI/Bookmarks/BookmarksView.swift +++ b/readeck/UI/Bookmarks/BookmarksView.swift @@ -121,7 +121,6 @@ struct BookmarksView: View { } } } - .navigationTitle(state.displayName) .navigationDestination( item: Binding( get: { selectedBookmarkId }, @@ -148,14 +147,14 @@ struct BookmarksView: View { }*/ .onAppear { Task { - await viewModel.loadBookmarks(state: state) + await viewModel.loadBookmarks(state: state, type: type) } } .onChange(of: showingAddBookmark) { oldValue, newValue in // Refresh bookmarks when sheet is dismissed if oldValue && !newValue { Task { - await viewModel.loadBookmarks(state: state) + await viewModel.loadBookmarks(state: state, type: type) } } } diff --git a/readeck/UI/Bookmarks/BookmarksViewModel.swift b/readeck/UI/Bookmarks/BookmarksViewModel.swift index 6564346..0af2ef6 100644 --- a/readeck/UI/Bookmarks/BookmarksViewModel.swift +++ b/readeck/UI/Bookmarks/BookmarksViewModel.swift @@ -12,7 +12,7 @@ class BookmarksViewModel { var isLoading = false var errorMessage: String? var currentState: BookmarkState = .unread - var type = [BookmarkType.article] + var currentType = [BookmarkType.article] var showingAddBookmarkFromShare = false var shareURL = "" @@ -29,7 +29,7 @@ class BookmarksViewModel { throttleSearch() } } - + init() { setupNotificationObserver() } @@ -60,7 +60,7 @@ class BookmarksViewModel { } private func throttleSearch() { - searchWorkItem?.cancel() + searchWorkItem?.cancel() let workItem = DispatchWorkItem { [weak self] in guard let self = self else { return } @@ -74,13 +74,15 @@ class BookmarksViewModel { } @MainActor - func loadBookmarks(state: BookmarkState = .unread) async { + func loadBookmarks(state: BookmarkState = .unread, type: [BookmarkType] = [.article]) async { isLoading = true errorMessage = nil currentState = state + currentType = type + offset = 0 // Offset zurücksetzen hasMoreData = true // Pagination zurücksetzen - + do { let newBookmarks = try await getBooksmarksUseCase.execute( state: state, @@ -98,17 +100,21 @@ class BookmarksViewModel { isLoading = false } - + @MainActor func loadMoreBookmarks() async { guard !isLoading && hasMoreData else { return } // Verhindern, dass mehrfach geladen wird isLoading = true errorMessage = nil - + do { offset += limit // Offset erhöhen - let newBookmarks = try await getBooksmarksUseCase.execute(state: currentState, limit: limit, offset: offset) + let newBookmarks = try await getBooksmarksUseCase.execute( + state: currentState, + limit: limit, + offset: offset, + type: currentType) bookmarks?.bookmarks.append(contentsOf: newBookmarks.bookmarks) // Neue Bookmarks hinzufügen hasMoreData = newBookmarks.bookmarks.count == limit // Prüfen, } catch { @@ -117,7 +123,7 @@ class BookmarksViewModel { isLoading = false } - + @MainActor func refreshBookmarks() async { await loadBookmarks(state: currentState) diff --git a/readeck/UI/Menu/PadSidebarView.swift b/readeck/UI/Menu/PadSidebarView.swift index 249b64d..6999d5b 100644 --- a/readeck/UI/Menu/PadSidebarView.swift +++ b/readeck/UI/Menu/PadSidebarView.swift @@ -22,18 +22,18 @@ struct PadSidebarView: View { .foregroundColor(selectedTab == tab ? .accentColor : .primary) .frame(maxWidth: .infinity, alignment: .leading) .contentShape(Rectangle()) - - if tab == .archived { - Spacer(minLength: 20) - } - - if tab == .pictures { - Spacer(minLength: 30) - Divider() - Spacer() - } } .listRowBackground(selectedTab == tab ? Color.accentColor.opacity(0.15) : Color.clear) + + if tab == .archived { + Spacer(minLength: 20) + } + + if tab == .pictures { + Spacer(minLength: 30) + Divider() + Spacer() + } } } .listStyle(.sidebar) @@ -55,26 +55,29 @@ struct PadSidebarView: View { .background(Color(.systemGroupedBackground)) } } content: { - switch selectedTab { - case .all: - BookmarksView(state: .all, type: [.article, .video, .photo], selectedBookmark: $selectedBookmark) - case .unread: - BookmarksView(state: .unread, type: [.article], selectedBookmark: $selectedBookmark) - case .favorite: - BookmarksView(state: .favorite, type: [.article], selectedBookmark: $selectedBookmark) - case .archived: - BookmarksView(state: .archived, type: [.article], selectedBookmark: $selectedBookmark) - case .settings: - SettingsView() - case .article: - BookmarksView(state: .all, type: [.article], selectedBookmark: $selectedBookmark) - case .videos: - BookmarksView(state: .all, type: [.video], selectedBookmark: $selectedBookmark) - case .pictures: - BookmarksView(state: .all, type: [.photo], selectedBookmark: $selectedBookmark) - case .tags: - Text("Tags") + Group { + switch selectedTab { + case .all: + BookmarksView(state: .all, type: [.article, .video, .photo], selectedBookmark: $selectedBookmark) + case .unread: + BookmarksView(state: .unread, type: [.article], selectedBookmark: $selectedBookmark) + case .favorite: + BookmarksView(state: .favorite, type: [.article], selectedBookmark: $selectedBookmark) + case .archived: + BookmarksView(state: .archived, type: [.article], selectedBookmark: $selectedBookmark) + case .settings: + SettingsView() + case .article: + BookmarksView(state: .all, type: [.article], selectedBookmark: $selectedBookmark) + case .videos: + BookmarksView(state: .all, type: [.video], selectedBookmark: $selectedBookmark) + case .pictures: + BookmarksView(state: .all, type: [.photo], selectedBookmark: $selectedBookmark) + case .tags: + Text("Tags") + } } + .navigationTitle(selectedTab.label) } detail: { if let bookmark = selectedBookmark, selectedTab != .settings { BookmarkDetailView(bookmarkId: bookmark.id)