Merge pull request #1466 from omnivore-app/feat/edit-title-desc

Allow editing author on iOS
This commit is contained in:
Jackson Harper 2022-11-25 17:25:11 +08:00 committed by GitHub
commit 787f7e2198
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 44 additions and 16 deletions

View file

@ -55,7 +55,8 @@ public class ShareExtensionViewModel: ObservableObject {
dataService.updateLinkedItemTitleAndDescription(
itemID: itemID,
title: title,
description: description
description: description,
author: nil
)
}

View file

@ -16,6 +16,7 @@ public struct ShareExtensionView: View {
@State var messageText: String?
@State var viewState = ViewState.mainView
@State var showHighlightInstructionAlert = false
enum FocusField: Hashable {
case titleEditor
@ -297,7 +298,7 @@ public struct ShareExtensionView: View {
Button(
action: {},
label: {
Button(action: {}, label: { Label("Dismiss", systemImage: "arrow.down.to.line") })
Button("Dismiss", role: .cancel, action: {})
}
)
Button(action: {
@ -452,7 +453,11 @@ public struct ShareExtensionView: View {
highlightSection
.onTapGesture {
withAnimation {
viewState = .viewingHighlight
if viewModel.highlightData != nil {
viewState = .viewingHighlight
} else {
showHighlightInstructionAlert = true
}
}
}
}
@ -481,6 +486,10 @@ public struct ShareExtensionView: View {
.sheet(isPresented: $labelsViewModel.showCreateLabelModal) {
CreateLabelView(viewModel: labelsViewModel)
}
.alert("Before saving an article select text in Safari to create a highlight on save.",
isPresented: $showHighlightInstructionAlert) {
Button("Ok", role: .cancel) { showHighlightInstructionAlert = false }
}
.environmentObject(viewModel.services.dataService)
.task {
await labelsViewModel.loadLabelsFromStore(dataService: viewModel.services.dataService)

View file

@ -62,7 +62,7 @@ import Views
ApplyLabelsView(mode: .item(item), onSave: nil)
}
.sheet(item: $viewModel.itemUnderTitleEdit) { item in
LinkedItemTitleEditView(item: item)
LinkedItemMetadataEditView(item: item)
}
.sheet(item: $viewModel.itemForHighlightsView) { item in
HighlightsListView(itemObjectID: item.objectID, hasHighlightMutations: $hasHighlightMutations)
@ -279,7 +279,7 @@ import Views
}
Button(
action: { viewModel.itemUnderTitleEdit = item },
label: { Label("Edit Title/Description", systemImage: "textbox") }
label: { Label("Edit Metadata", systemImage: "textbox") }
)
Button(
action: { viewModel.itemUnderLabelEdit = item },

View file

@ -46,7 +46,7 @@ import Views
// TODO: add highlights view button
Button(
action: { viewModel.itemUnderTitleEdit = item },
label: { Label("Edit Title/Description", systemImage: "textbox") }
label: { Label("Edit Metadata", systemImage: "textbox") }
)
Button(
action: { viewModel.itemUnderLabelEdit = item },
@ -143,7 +143,7 @@ import Views
ApplyLabelsView(mode: .item(item), onSave: nil)
}
.sheet(item: $viewModel.itemUnderTitleEdit) { item in
LinkedItemTitleEditView(item: item)
LinkedItemMetadataEditView(item: item)
}
// TODO: add highlights view sheet
.task {

View file

@ -150,7 +150,7 @@ struct LinkItemDetailView: View {
Group {
Button(
action: { showTitleEdit = true },
label: { Label("Edit Title/Description", systemImage: "textbox") }
label: { Label("Edit Metadata", systemImage: "textbox") }
)
Button(
action: { viewModel.handleArchiveAction(dataService: dataService) },
@ -188,7 +188,7 @@ struct LinkItemDetailView: View {
}
.sheet(isPresented: $showTitleEdit) {
if let item = viewModel.item {
LinkedItemTitleEditView(item: item)
LinkedItemMetadataEditView(item: item)
}
}
}

View file

@ -6,9 +6,11 @@ import Views
@MainActor final class LinkedItemTitleEditViewModel: ObservableObject {
@Published var title = ""
@Published var description = ""
@Published var author = ""
func load(item: LinkedItem) {
title = item.unwrappedTitle
author = item.author ?? ""
description = item.descriptionText ?? ""
}
@ -16,12 +18,14 @@ import Views
dataService.updateLinkedItemTitleAndDescription(
itemID: item.unwrappedID,
title: title,
description: description
description: description,
// Don't set author to an empty string
author: author.isEmpty ? nil : author
)
}
}
struct LinkedItemTitleEditView: View {
struct LinkedItemMetadataEditView: View {
@EnvironmentObject var dataService: DataService
@Environment(\.presentationMode) private var presentationMode
@StateObject var viewModel = LinkedItemTitleEditViewModel()
@ -39,6 +43,14 @@ struct LinkedItemTitleEditView: View {
.textFieldStyle(StandardTextFieldStyle(textColor: .appGrayTextContrast))
}
VStack(alignment: .leading, spacing: 6) {
Text("Author")
.font(.appFootnote)
.foregroundColor(.appGrayTextContrast)
TextField("", text: $viewModel.author)
.textFieldStyle(StandardTextFieldStyle(textColor: .appGrayTextContrast))
}
VStack(alignment: .leading, spacing: 6) {
Text("Description")
.font(.appFootnote)

View file

@ -165,7 +165,7 @@ struct WebReaderContainerView: View {
}
Button(
action: { showTitleEdit = true },
label: { Label("Edit Title/Description", systemImage: "textbox") }
label: { Label("Edit Metadata", systemImage: "textbox") }
)
Button(
action: editLabels,
@ -272,7 +272,7 @@ struct WebReaderContainerView: View {
ApplyLabelsView(mode: .item(item), onSave: { _ in showLabelsModal = false })
}
.sheet(isPresented: $showTitleEdit) {
LinkedItemTitleEditView(item: item)
LinkedItemMetadataEditView(item: item)
}
.sheet(isPresented: $showHighlightsView, onDismiss: onHighlightListViewDismissal) {
HighlightsListView(

View file

@ -179,6 +179,7 @@ public extension LinkedItem {
newIsArchivedValue: Bool? = nil,
newTitle: String? = nil,
newDescription: String? = nil,
newAuthor: String? = nil,
listenPositionIndex: Int? = nil,
listenPositionOffset: Double? = nil,
listenPositionTime: Double? = nil
@ -204,6 +205,10 @@ public extension LinkedItem {
self.descriptionText = newDescription
}
if let newAuthor = newAuthor {
self.author = newAuthor
}
if let listenPositionIndex = listenPositionIndex {
self.listenPositionIndex = Int64(listenPositionIndex)
}

View file

@ -4,7 +4,7 @@ import Models
import SwiftGraphQL
extension DataService {
public func updateLinkedItemTitleAndDescription(itemID: String, title: String, description: String) {
public func updateLinkedItemTitleAndDescription(itemID: String, title: String, description: String, author: String?) {
backgroundContext.perform { [weak self] in
guard let self = self else { return }
guard let linkedItem = LinkedItem.lookup(byID: itemID, inContext: self.backgroundContext) else { return }
@ -12,7 +12,8 @@ extension DataService {
linkedItem.update(
inContext: self.backgroundContext,
newTitle: title,
newDescription: description
newDescription: description,
newAuthor: author
)
// Send update to server

View file

@ -53,7 +53,7 @@ public struct GridCard: View {
}
Button(
action: { menuActionHandler(.editTitle) },
label: { Label("Edit Title/Description", systemImage: "textbox") }
label: { Label("Edit Metadata", systemImage: "textbox") }
)
Button(
action: { menuActionHandler(.editLabels) },