small fixes

This commit is contained in:
Ilyas Hallak 2025-07-02 22:15:05 +02:00
parent a5ccc75036
commit ec22c379d1
3 changed files with 49 additions and 41 deletions

View File

@ -121,7 +121,6 @@ struct BookmarksView: View {
} }
} }
} }
.navigationTitle(state.displayName)
.navigationDestination( .navigationDestination(
item: Binding<String?>( item: Binding<String?>(
get: { selectedBookmarkId }, get: { selectedBookmarkId },
@ -148,14 +147,14 @@ struct BookmarksView: View {
}*/ }*/
.onAppear { .onAppear {
Task { Task {
await viewModel.loadBookmarks(state: state) await viewModel.loadBookmarks(state: state, type: type)
} }
} }
.onChange(of: showingAddBookmark) { oldValue, newValue in .onChange(of: showingAddBookmark) { oldValue, newValue in
// Refresh bookmarks when sheet is dismissed // Refresh bookmarks when sheet is dismissed
if oldValue && !newValue { if oldValue && !newValue {
Task { Task {
await viewModel.loadBookmarks(state: state) await viewModel.loadBookmarks(state: state, type: type)
} }
} }
} }

View File

@ -12,7 +12,7 @@ class BookmarksViewModel {
var isLoading = false var isLoading = false
var errorMessage: String? var errorMessage: String?
var currentState: BookmarkState = .unread var currentState: BookmarkState = .unread
var type = [BookmarkType.article] var currentType = [BookmarkType.article]
var showingAddBookmarkFromShare = false var showingAddBookmarkFromShare = false
var shareURL = "" var shareURL = ""
@ -29,7 +29,7 @@ class BookmarksViewModel {
throttleSearch() throttleSearch()
} }
} }
init() { init() {
setupNotificationObserver() setupNotificationObserver()
} }
@ -60,7 +60,7 @@ class BookmarksViewModel {
} }
private func throttleSearch() { private func throttleSearch() {
searchWorkItem?.cancel() searchWorkItem?.cancel()
let workItem = DispatchWorkItem { [weak self] in let workItem = DispatchWorkItem { [weak self] in
guard let self = self else { return } guard let self = self else { return }
@ -74,13 +74,15 @@ class BookmarksViewModel {
} }
@MainActor @MainActor
func loadBookmarks(state: BookmarkState = .unread) async { func loadBookmarks(state: BookmarkState = .unread, type: [BookmarkType] = [.article]) async {
isLoading = true isLoading = true
errorMessage = nil errorMessage = nil
currentState = state currentState = state
currentType = type
offset = 0 // Offset zurücksetzen offset = 0 // Offset zurücksetzen
hasMoreData = true // Pagination zurücksetzen hasMoreData = true // Pagination zurücksetzen
do { do {
let newBookmarks = try await getBooksmarksUseCase.execute( let newBookmarks = try await getBooksmarksUseCase.execute(
state: state, state: state,
@ -98,17 +100,21 @@ class BookmarksViewModel {
isLoading = false isLoading = false
} }
@MainActor @MainActor
func loadMoreBookmarks() async { func loadMoreBookmarks() async {
guard !isLoading && hasMoreData else { return } // Verhindern, dass mehrfach geladen wird guard !isLoading && hasMoreData else { return } // Verhindern, dass mehrfach geladen wird
isLoading = true isLoading = true
errorMessage = nil errorMessage = nil
do { do {
offset += limit // Offset erhöhen 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 bookmarks?.bookmarks.append(contentsOf: newBookmarks.bookmarks) // Neue Bookmarks hinzufügen
hasMoreData = newBookmarks.bookmarks.count == limit // Prüfen, hasMoreData = newBookmarks.bookmarks.count == limit // Prüfen,
} catch { } catch {
@ -117,7 +123,7 @@ class BookmarksViewModel {
isLoading = false isLoading = false
} }
@MainActor @MainActor
func refreshBookmarks() async { func refreshBookmarks() async {
await loadBookmarks(state: currentState) await loadBookmarks(state: currentState)

View File

@ -22,18 +22,18 @@ struct PadSidebarView: View {
.foregroundColor(selectedTab == tab ? .accentColor : .primary) .foregroundColor(selectedTab == tab ? .accentColor : .primary)
.frame(maxWidth: .infinity, alignment: .leading) .frame(maxWidth: .infinity, alignment: .leading)
.contentShape(Rectangle()) .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) .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) .listStyle(.sidebar)
@ -55,26 +55,29 @@ struct PadSidebarView: View {
.background(Color(.systemGroupedBackground)) .background(Color(.systemGroupedBackground))
} }
} content: { } content: {
switch selectedTab { Group {
case .all: switch selectedTab {
BookmarksView(state: .all, type: [.article, .video, .photo], selectedBookmark: $selectedBookmark) case .all:
case .unread: BookmarksView(state: .all, type: [.article, .video, .photo], selectedBookmark: $selectedBookmark)
BookmarksView(state: .unread, type: [.article], selectedBookmark: $selectedBookmark) case .unread:
case .favorite: BookmarksView(state: .unread, type: [.article], selectedBookmark: $selectedBookmark)
BookmarksView(state: .favorite, type: [.article], selectedBookmark: $selectedBookmark) case .favorite:
case .archived: BookmarksView(state: .favorite, type: [.article], selectedBookmark: $selectedBookmark)
BookmarksView(state: .archived, type: [.article], selectedBookmark: $selectedBookmark) case .archived:
case .settings: BookmarksView(state: .archived, type: [.article], selectedBookmark: $selectedBookmark)
SettingsView() case .settings:
case .article: SettingsView()
BookmarksView(state: .all, type: [.article], selectedBookmark: $selectedBookmark) case .article:
case .videos: BookmarksView(state: .all, type: [.article], selectedBookmark: $selectedBookmark)
BookmarksView(state: .all, type: [.video], selectedBookmark: $selectedBookmark) case .videos:
case .pictures: BookmarksView(state: .all, type: [.video], selectedBookmark: $selectedBookmark)
BookmarksView(state: .all, type: [.photo], selectedBookmark: $selectedBookmark) case .pictures:
case .tags: BookmarksView(state: .all, type: [.photo], selectedBookmark: $selectedBookmark)
Text("Tags") case .tags:
Text("Tags")
}
} }
.navigationTitle(selectedTab.label)
} detail: { } detail: {
if let bookmark = selectedBookmark, selectedTab != .settings { if let bookmark = selectedBookmark, selectedTab != .settings {
BookmarkDetailView(bookmarkId: bookmark.id) BookmarkDetailView(bookmarkId: bookmark.id)