ReadKeep/readeck/UI/Menu/PadSidebarView.swift
Ilyas Hallak cf06a3147d feat: Add annotations support with color-coded highlighting
Add comprehensive annotations feature to bookmark detail views:
- Implement annotations list view with date formatting and state machine
- Add CSS-based highlighting for rd-annotation tags in WebView components
- Support Readeck color scheme (yellow, green, blue, red) for annotations
- Enable tap-to-scroll functionality to navigate to selected annotations
- Integrate annotations button in bookmark detail toolbar
- Add API endpoint and repository layer for fetching annotations
2025-10-22 15:25:55 +02:00

129 lines
5.9 KiB
Swift

//
// PadSidebarView.swift
// readeck
//
// Created by Ilyas Hallak on 01.07.25.
//
import SwiftUI
struct PadSidebarView: View {
@State private var selectedTab: SidebarTab = .unread
@State private var selectedBookmark: Bookmark?
@State private var selectedTag: BookmarkLabel?
@EnvironmentObject var playerUIState: PlayerUIState
@EnvironmentObject var appSettings: AppSettings
@State private var offlineBookmarksViewModel = OfflineBookmarksViewModel()
private let sidebarTabs: [SidebarTab] = [.search, .all, .unread, .favorite, .archived, .article, .videos, .pictures, .tags]
var body: some View {
NavigationSplitView {
List {
ForEach(sidebarTabs, id: \.self) { tab in
Button(action: {
selectedTab = tab
selectedBookmark = nil
selectedTag = nil
}) {
Label(tab.label, systemImage: tab.systemImage)
.foregroundColor(selectedTab == tab ? .accentColor : .primary)
.frame(maxWidth: .infinity, alignment: .leading)
.contentShape(Rectangle())
}
.listRowBackground(selectedTab == tab ? Color.accentColor.opacity(0.15) : Color(R.color.menu_sidebar_bg))
if tab == .archived {
Spacer()
.listRowBackground(Color(R.color.menu_sidebar_bg))
}
}
if case .idle = offlineBookmarksViewModel.state {
// Don't show anything for idle state
} else {
Section {
VStack {
LocalBookmarksSyncView(state: offlineBookmarksViewModel.state) {
await offlineBookmarksViewModel.syncOfflineBookmarks()
}
}
.listRowBackground(Color.clear)
.listRowInsets(EdgeInsets())
}
}
}
.listRowBackground(Color(R.color.menu_sidebar_bg))
.background(Color(R.color.menu_sidebar_bg))
.listStyle(.sidebar)
.scrollContentBackground(.hidden)
.safeAreaInset(edge: .bottom, alignment: .center) {
VStack(spacing: 0) {
Button(action: {
selectedTab = .settings
}) {
Label(SidebarTab.settings.label, systemImage: SidebarTab.settings.systemImage)
.foregroundColor(selectedTab == .settings ? .accentColor : .primary)
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.vertical, 12)
.contentShape(Rectangle())
}
.listRowBackground(selectedTab == .settings ? Color.accentColor.opacity(0.15) : Color(R.color.menu_sidebar_bg))
if appSettings.enableTTS {
PlayerQueueResumeButton()
.padding(.top, 8)
}
}
.padding(.horizontal, 12)
.background(Color(R.color.menu_sidebar_bg))
}
} content: {
GlobalPlayerContainerView {
Group {
switch selectedTab {
case .search:
SearchBookmarksView(selectedBookmark: $selectedBookmark)
case .all:
BookmarksView(state: .all, type: [.article, .video, .photo], selectedBookmark: $selectedBookmark)
case .unread:
BookmarksView(state: .unread, type: [.article, .video, .photo], selectedBookmark: $selectedBookmark)
case .favorite:
BookmarksView(state: .favorite, type: [.article, .video, .photo], selectedBookmark: $selectedBookmark)
case .archived:
BookmarksView(state: .archived, type: [.article, .video, .photo], 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:
NavigationStack {
LabelsView(selectedTag: $selectedTag)
}
.navigationDestination(item: $selectedTag) { label in
BookmarksView(state: .all, type: [], selectedBookmark: $selectedBookmark, tag: label.name)
.navigationTitle("\(label.name) (\(label.count))")
.onDisappear {
selectedTag = nil
}
}
}
}
.navigationTitle(selectedTab.label)
}
} detail: {
if let bookmark = selectedBookmark, selectedTab != .settings {
BookmarkDetailView(bookmarkId: bookmark.id)
} else if selectedTab == .settings {
Text(selectedTab == .settings ? "" : "Select a bookmark or tag")
.foregroundColor(.gray)
}
}
.background(Color(R.color.menu_sidebar_bg))
}
}