Allow editing author on iOS

This commit is contained in:
Jackson Harper 2022-11-25 14:42:56 +08:00
parent 42a4f22c4b
commit a3b53485ed
9 changed files with 33 additions and 14 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

@ -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) },