diff --git a/apple/OmnivoreKit/Sources/App/AppExtensions/Share/ShareExtensionViewModel.swift b/apple/OmnivoreKit/Sources/App/AppExtensions/Share/ShareExtensionViewModel.swift index e74d34a55..61814a5ad 100644 --- a/apple/OmnivoreKit/Sources/App/AppExtensions/Share/ShareExtensionViewModel.swift +++ b/apple/OmnivoreKit/Sources/App/AppExtensions/Share/ShareExtensionViewModel.swift @@ -64,6 +64,22 @@ public class ShareExtensionViewModel: ObservableObject { ) } + func saveNote() { + if let linkedItem = linkedItem { + if let noteHighlight = linkedItem.noteHighlight, let noteHighlightID = noteHighlight.id { + services.dataService.updateHighlightAttributes(highlightID: noteHighlightID, annotation: noteText) + } else { + let createdHighlightId = UUID().uuidString.lowercased() + let createdShortId = NanoID.generate(alphabet: NanoID.Alphabet.urlSafe.rawValue, size: 8) + + _ = services.dataService.createNote(shortId: createdShortId, + highlightID: createdHighlightId, + articleId: linkedItem.unwrappedID, + annotation: noteText) + } + } + } + #if os(iOS) func queueSaveOperation(_ payload: PageScrapePayload) { ProcessInfo().performExpiringActivity(withReason: "app.omnivore.SaveActivity") { [self] expiring in diff --git a/apple/OmnivoreKit/Sources/App/AppExtensions/Share/Views/AddNoteSheet.swift b/apple/OmnivoreKit/Sources/App/AppExtensions/Share/Views/AddNoteSheet.swift index 335f53cc2..6e9ff533d 100644 --- a/apple/OmnivoreKit/Sources/App/AppExtensions/Share/Views/AddNoteSheet.swift +++ b/apple/OmnivoreKit/Sources/App/AppExtensions/Share/Views/AddNoteSheet.swift @@ -15,8 +15,6 @@ public struct AddNoteSheet: View { @Environment(\.dismiss) private var dismiss @StateObject var viewModel: ShareExtensionViewModel - let highlightId = UUID().uuidString.lowercased() - let shortId = NanoID.generate(alphabet: NanoID.Alphabet.urlSafe.rawValue, size: 8) enum FocusField: Hashable { case noteEditor @@ -30,14 +28,7 @@ public struct AddNoteSheet: View { } func saveNote() { - if let linkedItem = viewModel.linkedItem { - _ = viewModel.services.dataService.createNote(shortId: shortId, - highlightID: highlightId, - articleId: linkedItem.unwrappedID, - annotation: viewModel.noteText) - } else { - // Maybe we shouldn't even allow this UI without linkeditem existing - } + viewModel.saveNote() } public var body: some View { diff --git a/apple/OmnivoreKit/Sources/App/AppExtensions/Share/Views/EditLabelsSheet.swift b/apple/OmnivoreKit/Sources/App/AppExtensions/Share/Views/EditLabelsSheet.swift index 90626a574..5c5615ecd 100644 --- a/apple/OmnivoreKit/Sources/App/AppExtensions/Share/Views/EditLabelsSheet.swift +++ b/apple/OmnivoreKit/Sources/App/AppExtensions/Share/Views/EditLabelsSheet.swift @@ -47,6 +47,10 @@ public struct EditLabelsSheet: View { } } + func isSelected(_ label: LinkedItemLabel) -> Bool { + labelsViewModel.selectedLabels.contains(where: { $0.id == label.id }) + } + var content: some View { VStack(spacing: 15) { LabelsEntryView( @@ -54,33 +58,71 @@ public struct EditLabelsSheet: View { viewModel: labelsViewModel ) - // swiftlint:disable line_length - ScrollView { - LabelsMasonaryView( - labels: labelsViewModel.labels.applySearchFilter(labelsViewModel.labelSearchFilter), - selectedLabels: labelsViewModel.selectedLabels.applySearchFilter(labelsViewModel.labelSearchFilter), - onLabelTap: onLabelTap - ) - - Button( - action: { labelsViewModel.showCreateLabelModal = true }, - label: { - HStack { - let trimmedLabelName = labelsViewModel.labelSearchFilter.trimmingCharacters(in: .whitespacesAndNewlines) - Image(systemName: "tag").foregroundColor(.blue) - Text( - labelsViewModel.labelSearchFilter.count > 0 ? - "Create: \"\(trimmedLabelName)\" label" : - LocalText.createLabelMessage - ).foregroundColor(.blue) - .font(Font.system(size: 14)) - Spacer() - } + List { + Section { + ForEach(labelsViewModel.labels.applySearchFilter(labelsViewModel.labelSearchFilter), id: \.self) { label in + Button( + action: { +// if labelsViewModel.selectedLabels.contains(label) { +// if let idx = viewModel.selectedLabels.firstIndex(of: label) { +// viewModel.selectedLabels.remove(at: idx) +// } +// } else { +// viewModel.labelSearchFilter = ZWSP +// viewModel.selectedLabels.append(label) +// } + }, + label: { + HStack { + TextChip(feedItemLabel: label).allowsHitTesting(false) + Spacer() + if isSelected(label) { + Image(systemName: "checkmark") + } + } + .contentShape(Rectangle()) + } + ) + .padding(.vertical, 5) + .frame(maxWidth: .infinity, alignment: .leading) + #if os(macOS) + .buttonStyle(PlainButtonStyle()) + #endif } - ) - .buttonStyle(PlainButtonStyle()) - .padding(10) + // createLabelButton + } } + .listStyle(PlainListStyle()) + + Spacer() + +// // swiftlint:disable line_length +// ScrollView { +// LabelsMasonaryView( +// labels: labelsViewModel.labels.applySearchFilter(labelsViewModel.labelSearchFilter), +// selectedLabels: labelsViewModel.selectedLabels.applySearchFilter(labelsViewModel.labelSearchFilter), +// onLabelTap: onLabelTap +// ) +// +// Button( +// action: { labelsViewModel.showCreateLabelModal = true }, +// label: { +// HStack { +// let trimmedLabelName = labelsViewModel.labelSearchFilter.trimmingCharacters(in: .whitespacesAndNewlines) +// Image(systemName: "tag").foregroundColor(.blue) +// Text( +// labelsViewModel.labelSearchFilter.count > 0 ? +// "Create: \"\(trimmedLabelName)\" label" : +// LocalText.createLabelMessage +// ).foregroundColor(.blue) +// .font(Font.system(size: 14)) +// Spacer() +// } +// } +// ) +// .buttonStyle(PlainButtonStyle()) +// .padding(10) +// } } .background(Color.clear) .padding(20) diff --git a/apple/OmnivoreKit/Sources/App/AppExtensions/Share/Views/ShareExtensionView.swift b/apple/OmnivoreKit/Sources/App/AppExtensions/Share/Views/ShareExtensionView.swift index 8954e26b1..db48203e2 100644 --- a/apple/OmnivoreKit/Sources/App/AppExtensions/Share/Views/ShareExtensionView.swift +++ b/apple/OmnivoreKit/Sources/App/AppExtensions/Share/Views/ShareExtensionView.swift @@ -113,8 +113,9 @@ public struct ShareExtensionView: View { NotificationCenter.default.post(name: Notification.Name("ShowAddNoteSheet"), object: nil) }, label: { Text(hasNoteText ? viewModel.noteText : "Add note...") - .frame(height: 50, alignment: .top) + .frame(minHeight: 50, alignment: .top) .frame(maxWidth: .infinity, alignment: .leading) + .multilineTextAlignment(.leading) }) .foregroundColor(hasNoteText ? Color.appGrayTextContrast : Color.extensionTextSubtle diff --git a/apple/OmnivoreKit/Sources/Models/DataModels/FeedItem.swift b/apple/OmnivoreKit/Sources/Models/DataModels/FeedItem.swift index aebbf0e15..ab370b541 100644 --- a/apple/OmnivoreKit/Sources/Models/DataModels/FeedItem.swift +++ b/apple/OmnivoreKit/Sources/Models/DataModels/FeedItem.swift @@ -79,17 +79,21 @@ public extension LinkedItem { (labels?.count ?? 0) > 0 } - var noteText: String? { + var noteHighlight: Highlight? { if let highlights = highlights?.compactMap({ $0 as? Highlight }) { let result = highlights .filter { $0.type == "NOTE" } .sorted(by: { $0.updatedAt ?? Date() < $1.updatedAt ?? Date() }) .first - return result?.annotation + return result } return nil } + var noteText: String? { + noteHighlight?.annotation + } + var isUnread: Bool { readingProgress <= 0 }