mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
add title/description edit form
This commit is contained in:
parent
f7172f02b1
commit
64e146380f
2 changed files with 93 additions and 6 deletions
|
|
@ -1,15 +1,97 @@
|
|||
import Models
|
||||
import Services
|
||||
import SwiftUI
|
||||
import Views
|
||||
|
||||
@MainActor final class LinkedItemTitleEditViewModel: ObservableObject {
|
||||
@Published var isLoading = false
|
||||
@Published var title = ""
|
||||
@Published var description = ""
|
||||
@Published var errorMessage: String?
|
||||
|
||||
func load(item: LinkedItem) {
|
||||
title = item.unwrappedTitle
|
||||
description = item.descriptionText ?? ""
|
||||
}
|
||||
|
||||
func submit(dataService: DataService, item: LinkedItem) {
|
||||
isLoading = true
|
||||
print(item.title)
|
||||
print(dataService.currentViewer?.unwrappedName)
|
||||
isLoading = false
|
||||
}
|
||||
}
|
||||
|
||||
struct LinkedItemTitleEditView: View {
|
||||
@EnvironmentObject var dataService: DataService
|
||||
@Environment(\.presentationMode) private var presentationMode
|
||||
// @StateObject var viewModel = LabelsViewModel()
|
||||
@Environment(\.horizontalSizeClass) var horizontalSizeClass
|
||||
@StateObject var viewModel = LinkedItemTitleEditViewModel()
|
||||
|
||||
let item: LinkedItem
|
||||
|
||||
var editForm: some View {
|
||||
ScrollView(showsIndicators: false) {
|
||||
VStack(alignment: .center, spacing: 16) {
|
||||
VStack(alignment: .leading, spacing: 6) {
|
||||
Text("Title")
|
||||
.font(.appFootnote)
|
||||
.foregroundColor(.appGrayTextContrast)
|
||||
TextField("", text: $viewModel.title)
|
||||
.textFieldStyle(StandardTextFieldStyle(textColor: .appGrayTextContrast))
|
||||
}
|
||||
|
||||
VStack(alignment: .leading, spacing: 6) {
|
||||
Text("Description")
|
||||
.font(.appFootnote)
|
||||
.foregroundColor(.appGrayTextContrast)
|
||||
TextEditor(text: $viewModel.description)
|
||||
.lineSpacing(6)
|
||||
.accentColor(.appGraySolid)
|
||||
.foregroundColor(.appGrayTextContrast)
|
||||
.font(.appBody)
|
||||
.padding(12)
|
||||
.background(
|
||||
RoundedRectangle(cornerRadius: 8)
|
||||
.strokeBorder(Color.appGrayBorder, lineWidth: 1)
|
||||
.background(RoundedRectangle(cornerRadius: 8).fill(Color.systemBackground))
|
||||
)
|
||||
.frame(height: 160)
|
||||
}
|
||||
|
||||
if let errorMessage = viewModel.errorMessage {
|
||||
Text(errorMessage)
|
||||
.font(.appCaption)
|
||||
.foregroundColor(.red)
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
Text(item.title ?? "unknown item")
|
||||
NavigationView {
|
||||
editForm
|
||||
.navigationTitle("Edit Title and Description")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .barTrailing) {
|
||||
Button(
|
||||
action: {
|
||||
viewModel.submit(dataService: dataService, item: item)
|
||||
},
|
||||
label: { Text("Save").foregroundColor(.appGrayTextContrast) }
|
||||
)
|
||||
}
|
||||
ToolbarItem(placement: .barLeading) {
|
||||
Button(
|
||||
action: { presentationMode.wrappedValue.dismiss() },
|
||||
label: { Text("Cancel").foregroundColor(.appGrayTextContrast) }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
.task { viewModel.load(item: item) }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,18 @@
|
|||
import SwiftUI
|
||||
|
||||
public struct StandardTextFieldStyle: TextFieldStyle {
|
||||
public init() {}
|
||||
let textColor: Color?
|
||||
|
||||
public init(textColor: Color = .appGrayText) {
|
||||
self.textColor = textColor
|
||||
}
|
||||
|
||||
// swiftlint:disable:next identifier_name
|
||||
public func _body(configuration: TextField<_Label>) -> some View {
|
||||
configuration
|
||||
.textFieldStyle(PlainTextFieldStyle())
|
||||
.multilineTextAlignment(.leading)
|
||||
.foregroundColor(.appGrayText)
|
||||
.foregroundColor(textColor)
|
||||
.font(.appBody)
|
||||
.padding(.vertical, 12)
|
||||
.padding(.horizontal, 16)
|
||||
|
|
@ -15,9 +20,9 @@ public struct StandardTextFieldStyle: TextFieldStyle {
|
|||
}
|
||||
|
||||
public var border: some View {
|
||||
RoundedRectangle(cornerRadius: 16)
|
||||
RoundedRectangle(cornerRadius: 8)
|
||||
.strokeBorder(Color.appGrayBorder, lineWidth: 1)
|
||||
.background(RoundedRectangle(cornerRadius: 16).fill(Color.systemBackground))
|
||||
.background(RoundedRectangle(cornerRadius: 8).fill(Color.systemBackground))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue