diff --git a/apple/OmnivoreKit/Sources/App/Views/Highlights/HighlightsListView.swift b/apple/OmnivoreKit/Sources/App/Views/Highlights/HighlightsListView.swift new file mode 100644 index 000000000..75332e587 --- /dev/null +++ b/apple/OmnivoreKit/Sources/App/Views/Highlights/HighlightsListView.swift @@ -0,0 +1,60 @@ +import Models +import Services +import SwiftUI +import Views + +struct HighlightsListView: View { + @EnvironmentObject var dataService: DataService + @Environment(\.presentationMode) private var presentationMode + @StateObject var viewModel = HighlightsListViewModel() + + let item: LinkedItem + + var innerBody: some View { + List { + Section { + ForEach(viewModel.highlights, id: \.self) { highlight in + Text(highlight.quote ?? "no quote") + } + } + } + .navigationTitle("Highlights") + #if os(iOS) + .navigationBarTitleDisplayMode(.inline) + .toolbar { + ToolbarItem(placement: .navigationBarTrailing) { + dismissButton + } + } + #else + .toolbar { + ToolbarItemGroup { + dismissButton + } + } + #endif + } + + var dismissButton: some View { + Button( + action: { presentationMode.wrappedValue.dismiss() }, + label: { Text("Done").foregroundColor(.appGrayTextContrast) } + ) + } + + var body: some View { + Group { + #if os(iOS) + NavigationView { + innerBody + } + #elseif os(macOS) + innerBody + .frame(minWidth: 400, minHeight: 400) + #endif + } + .task { + viewModel.load(item: item) + } + } +} diff --git a/apple/OmnivoreKit/Sources/App/Views/Highlights/HighlightsListViewModel.swift b/apple/OmnivoreKit/Sources/App/Views/Highlights/HighlightsListViewModel.swift new file mode 100644 index 000000000..611b9a2aa --- /dev/null +++ b/apple/OmnivoreKit/Sources/App/Views/Highlights/HighlightsListViewModel.swift @@ -0,0 +1,13 @@ +import CoreData +import Models +import Services +import SwiftUI +import Views + +@MainActor final class HighlightsListViewModel: ObservableObject { + @Published var highlights = [Highlight]() + + func load(item: LinkedItem) { + highlights = item.highlights.asArray(of: Highlight.self) + } +} diff --git a/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift b/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift index 58800211b..f74763fcf 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift @@ -63,7 +63,7 @@ import Views LinkedItemTitleEditView(item: item) } .sheet(item: $viewModel.itemForHighlightsView) { item in - Text("Highlights view for: \(item.unwrappedTitle)") // TODO: implement view + HighlightsListView(item: item) } .toolbar { ToolbarItem(placement: .barTrailing) { diff --git a/apple/OmnivoreKit/Sources/App/Views/WebReader/WebReaderContainer.swift b/apple/OmnivoreKit/Sources/App/Views/WebReader/WebReaderContainer.swift index 3624aec4b..b13acc07a 100644 --- a/apple/OmnivoreKit/Sources/App/Views/WebReader/WebReaderContainer.swift +++ b/apple/OmnivoreKit/Sources/App/Views/WebReader/WebReaderContainer.swift @@ -12,6 +12,7 @@ struct WebReaderContainerView: View { @State private var showPreferencesPopover = false @State private var showLabelsModal = false @State private var showTitleEdit = false + @State private var showHighlightsView = false @State var showHighlightAnnotationModal = false @State var safariWebLink: SafariWebLink? @State private var navBarVisibilityRatio = 1.0 @@ -131,6 +132,10 @@ struct WebReaderContainerView: View { Menu( content: { Group { + Button( + action: { showHighlightsView = true }, + label: { Label("View Highlights", systemImage: "highlighter") } + ) Button( action: { showTitleEdit = true }, label: { Label("Edit Title/Description", systemImage: "textbox") } @@ -198,6 +203,9 @@ struct WebReaderContainerView: View { .sheet(isPresented: $showTitleEdit) { LinkedItemTitleEditView(item: item) } + .sheet(isPresented: $showHighlightsView) { + HighlightsListView(item: item) + } #if os(macOS) .buttonStyle(PlainButtonStyle()) #endif