implemented card editing functionality although im not sure that's the final version yet

This commit is contained in:
breadone 2024-06-25 18:16:27 +12:00
parent a4302ef65d
commit c49db28ff6
No known key found for this signature in database
3 changed files with 25 additions and 15 deletions

View File

@ -28,7 +28,7 @@
46AD30EF2C266F1900486C25 /* NewProjectForm.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46AD30EE2C266F1900486C25 /* NewProjectForm.swift */; }; 46AD30EF2C266F1900486C25 /* NewProjectForm.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46AD30EE2C266F1900486C25 /* NewProjectForm.swift */; };
46AD30F22C2672BD00486C25 /* ColorModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46AD30F12C2672BD00486C25 /* ColorModel.swift */; }; 46AD30F22C2672BD00486C25 /* ColorModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46AD30F12C2672BD00486C25 /* ColorModel.swift */; };
46AD30F42C267D6400486C25 /* PreviewData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46AD30F32C267D6400486C25 /* PreviewData.swift */; }; 46AD30F42C267D6400486C25 /* PreviewData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46AD30F32C267D6400486C25 /* PreviewData.swift */; };
46AD30F62C26823B00486C25 /* AddNewCardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46AD30F52C26823B00486C25 /* AddNewCardView.swift */; }; 46AD30F62C26823B00486C25 /* EditCardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46AD30F52C26823B00486C25 /* EditCardView.swift */; };
46AD30F82C2689B900486C25 /* ProjectSlideshowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46AD30F72C2689B900486C25 /* ProjectSlideshowView.swift */; }; 46AD30F82C2689B900486C25 /* ProjectSlideshowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46AD30F72C2689B900486C25 /* ProjectSlideshowView.swift */; };
46D3E13F2C26D6430060722E /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46D3E13E2C26D6430060722E /* Constants.swift */; }; 46D3E13F2C26D6430060722E /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46D3E13E2C26D6430060722E /* Constants.swift */; };
46D3E1402C26D6430060722E /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46D3E13E2C26D6430060722E /* Constants.swift */; }; 46D3E1402C26D6430060722E /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46D3E13E2C26D6430060722E /* Constants.swift */; };
@ -81,7 +81,7 @@
46AD30EE2C266F1900486C25 /* NewProjectForm.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewProjectForm.swift; sourceTree = "<group>"; }; 46AD30EE2C266F1900486C25 /* NewProjectForm.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewProjectForm.swift; sourceTree = "<group>"; };
46AD30F12C2672BD00486C25 /* ColorModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorModel.swift; sourceTree = "<group>"; }; 46AD30F12C2672BD00486C25 /* ColorModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorModel.swift; sourceTree = "<group>"; };
46AD30F32C267D6400486C25 /* PreviewData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreviewData.swift; sourceTree = "<group>"; }; 46AD30F32C267D6400486C25 /* PreviewData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreviewData.swift; sourceTree = "<group>"; };
46AD30F52C26823B00486C25 /* AddNewCardView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddNewCardView.swift; sourceTree = "<group>"; }; 46AD30F52C26823B00486C25 /* EditCardView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditCardView.swift; sourceTree = "<group>"; };
46AD30F72C2689B900486C25 /* ProjectSlideshowView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProjectSlideshowView.swift; sourceTree = "<group>"; }; 46AD30F72C2689B900486C25 /* ProjectSlideshowView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProjectSlideshowView.swift; sourceTree = "<group>"; };
46D3E13E2C26D6430060722E /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; }; 46D3E13E2C26D6430060722E /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
46D3E1412C27DD5C0060722E /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = "<group>"; }; 46D3E1412C27DD5C0060722E /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = "<group>"; };
@ -185,7 +185,7 @@
46AD30BC2C26557500486C25 /* MainView.swift */, 46AD30BC2C26557500486C25 /* MainView.swift */,
46AD30EC2C266C0B00486C25 /* CardsView.swift */, 46AD30EC2C266C0B00486C25 /* CardsView.swift */,
46AD30EE2C266F1900486C25 /* NewProjectForm.swift */, 46AD30EE2C266F1900486C25 /* NewProjectForm.swift */,
46AD30F52C26823B00486C25 /* AddNewCardView.swift */, 46AD30F52C26823B00486C25 /* EditCardView.swift */,
46AD30F72C2689B900486C25 /* ProjectSlideshowView.swift */, 46AD30F72C2689B900486C25 /* ProjectSlideshowView.swift */,
464787CA2C269CAF00A9C462 /* TeleprompterView.swift */, 464787CA2C269CAF00A9C462 /* TeleprompterView.swift */,
46D3E1412C27DD5C0060722E /* SettingsView.swift */, 46D3E1412C27DD5C0060722E /* SettingsView.swift */,
@ -326,7 +326,7 @@
46AD30F82C2689B900486C25 /* ProjectSlideshowView.swift in Sources */, 46AD30F82C2689B900486C25 /* ProjectSlideshowView.swift in Sources */,
46AD30EF2C266F1900486C25 /* NewProjectForm.swift in Sources */, 46AD30EF2C266F1900486C25 /* NewProjectForm.swift in Sources */,
46D3E1462C27EC3B0060722E /* AutoScrollView.swift in Sources */, 46D3E1462C27EC3B0060722E /* AutoScrollView.swift in Sources */,
46AD30F62C26823B00486C25 /* AddNewCardView.swift in Sources */, 46AD30F62C26823B00486C25 /* EditCardView.swift in Sources */,
464787CB2C269CAF00A9C462 /* TeleprompterView.swift in Sources */, 464787CB2C269CAF00A9C462 /* TeleprompterView.swift in Sources */,
46AD30ED2C266C0B00486C25 /* CardsView.swift in Sources */, 46AD30ED2C266C0B00486C25 /* CardsView.swift in Sources */,
46AD30BD2C26557500486C25 /* MainView.swift in Sources */, 46AD30BD2C26557500486C25 /* MainView.swift in Sources */,

View File

@ -10,8 +10,9 @@ import SwiftData
struct CardsView: View { struct CardsView: View {
let project: OCProject let project: OCProject
@State private var addNewCard = false @State private var editCard = false
@State private var newCardText = "" @State private var newCardText = ""
@State private var editCardText = ""
@Environment(\.modelContext) private var ctx @Environment(\.modelContext) private var ctx
@State private var showNoTextInNewCardError = false @State private var showNoTextInNewCardError = false
@ -26,8 +27,12 @@ struct CardsView: View {
Section { Section {
ForEach(project.sortedCards) { card in ForEach(project.sortedCards) { card in
Text(card.content) Text(card.content)
.swipeActions {
Button(role: .destructive) { } label: { Image(systemName: "trash.fill") }
.background(Color.red)
Button { editCardText = card.content; editCard.toggle() } label: { Image(systemName: "pencil") }
}
} }
.onDelete(perform: deleteItems)
} header: { } header: {
Text("\(project.cards.count) \(project.cards.count == 1 ? "Card" : "Cards")") Text("\(project.cards.count) \(project.cards.count == 1 ? "Card" : "Cards")")
} }
@ -55,8 +60,8 @@ struct CardsView: View {
} }
} }
.sheet(isPresented: $addNewCard) { .sheet(isPresented: $editCard) {
AddNewCardView(completionHandler: addNewCard) EditCardView(text: $editCardText) { editCard(txt: $0, offset: []) }
} }
.alert("No Text In Card", isPresented: $showNoTextInNewCardError) { .alert("No Text In Card", isPresented: $showNoTextInNewCardError) {
Button("OK", role: .cancel) {} Button("OK", role: .cancel) {}
@ -66,6 +71,10 @@ struct CardsView: View {
} }
func editCard(txt: String, offset: IndexSet) {
}
func addNewCard(txt: String) { func addNewCard(txt: String) {
guard txt != "" else { guard txt != "" else {
showNoTextInNewCardError.toggle() showNoTextInNewCardError.toggle()

View File

@ -1,5 +1,5 @@
// //
// AddNewCardView.swift // EditCardView.swift
// OnCue // OnCue
// //
// Created by Pradyun Setti on 22/06/2024. // Created by Pradyun Setti on 22/06/2024.
@ -7,8 +7,8 @@
import SwiftUI import SwiftUI
struct AddNewCardView: View { struct EditCardView: View {
@State private var newCardText = "" @Binding var text: String
@Environment(\.dismiss) var dismiss @Environment(\.dismiss) var dismiss
let completionHandler: (String) -> Void let completionHandler: (String) -> Void
@ -16,10 +16,10 @@ struct AddNewCardView: View {
var body: some View { var body: some View {
NavigationView { NavigationView {
Form { Form {
TextEditor(text: $newCardText) TextEditor(text: $text)
.frame(minHeight: 100) .frame(minHeight: 100)
} }
.navigationTitle("Add New Card") .navigationTitle("Edit Card")
.navigationBarTitleDisplayMode(.inline) .navigationBarTitleDisplayMode(.inline)
.toolbar { .toolbar {
ToolbarItem(placement: .topBarLeading) { ToolbarItem(placement: .topBarLeading) {
@ -28,7 +28,7 @@ struct AddNewCardView: View {
} }
ToolbarItem(placement: .topBarTrailing) { ToolbarItem(placement: .topBarTrailing) {
Button("Done") { Button("Done") {
completionHandler(newCardText) completionHandler(text)
dismiss() dismiss()
} }
} }
@ -38,5 +38,6 @@ struct AddNewCardView: View {
} }
#Preview { #Preview {
AddNewCardView(completionHandler: {_ in}) @State var test = ""
return EditCardView(text: $test) { _ in }
} }