mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Add save note to view model, improve labels editor
This commit is contained in:
parent
b92cbbc9a5
commit
e1076f9ac4
5 changed files with 92 additions and 38 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue