From 39bfd73c01b02847c15fc856ea56d28fadee05c4 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Tue, 8 Jul 2025 06:59:04 -0700 Subject: feat: Development commit --- Sora/Views/CollectionAlertsModifier.swift | 59 +++++++++++++++++++++++ Sora/Views/Generic/CollectionAlertsModifier.swift | 59 ----------------------- 2 files changed, 59 insertions(+), 59 deletions(-) create mode 100644 Sora/Views/CollectionAlertsModifier.swift delete mode 100644 Sora/Views/Generic/CollectionAlertsModifier.swift diff --git a/Sora/Views/CollectionAlertsModifier.swift b/Sora/Views/CollectionAlertsModifier.swift new file mode 100644 index 0000000..6c39da8 --- /dev/null +++ b/Sora/Views/CollectionAlertsModifier.swift @@ -0,0 +1,59 @@ +import SwiftUI + +struct CollectionAlertsModifier: ViewModifier { + @Binding var isNewCollectionAlertPresented: Bool + @Binding var newCollectionName: String + @Binding var isCollectionErrorAlertPresented: Bool + let onCreate: (String) -> Void + + func body(content: Content) -> some View { + content + .alert( + "New Collection", + isPresented: $isNewCollectionAlertPresented + ) { + TextField("Collection Name", text: $newCollectionName) + + Button("Cancel") { + newCollectionName = "" + isNewCollectionAlertPresented = false + } + + Button("Create") { + if newCollectionName.isEmpty { + isCollectionErrorAlertPresented = true + } else { + onCreate(newCollectionName) + newCollectionName = "" + isNewCollectionAlertPresented = false + } + } + } + .alert( + "Error", + isPresented: $isCollectionErrorAlertPresented + ) { + Button("OK", role: .cancel) { () } + } message: { + Text("Collection name cannot be empty.") + } + } +} + +extension View { + func collectionAlerts( + isNewCollectionAlertPresented: Binding, + newCollectionName: Binding, + isCollectionErrorAlertPresented: Binding, + onCreate: @escaping (String) -> Void + ) -> some View { + modifier( + CollectionAlertsModifier( + isNewCollectionAlertPresented: isNewCollectionAlertPresented, + newCollectionName: newCollectionName, + isCollectionErrorAlertPresented: isCollectionErrorAlertPresented, + onCreate: onCreate + ) + ) + } +} diff --git a/Sora/Views/Generic/CollectionAlertsModifier.swift b/Sora/Views/Generic/CollectionAlertsModifier.swift deleted file mode 100644 index 6c39da8..0000000 --- a/Sora/Views/Generic/CollectionAlertsModifier.swift +++ /dev/null @@ -1,59 +0,0 @@ -import SwiftUI - -struct CollectionAlertsModifier: ViewModifier { - @Binding var isNewCollectionAlertPresented: Bool - @Binding var newCollectionName: String - @Binding var isCollectionErrorAlertPresented: Bool - let onCreate: (String) -> Void - - func body(content: Content) -> some View { - content - .alert( - "New Collection", - isPresented: $isNewCollectionAlertPresented - ) { - TextField("Collection Name", text: $newCollectionName) - - Button("Cancel") { - newCollectionName = "" - isNewCollectionAlertPresented = false - } - - Button("Create") { - if newCollectionName.isEmpty { - isCollectionErrorAlertPresented = true - } else { - onCreate(newCollectionName) - newCollectionName = "" - isNewCollectionAlertPresented = false - } - } - } - .alert( - "Error", - isPresented: $isCollectionErrorAlertPresented - ) { - Button("OK", role: .cancel) { () } - } message: { - Text("Collection name cannot be empty.") - } - } -} - -extension View { - func collectionAlerts( - isNewCollectionAlertPresented: Binding, - newCollectionName: Binding, - isCollectionErrorAlertPresented: Binding, - onCreate: @escaping (String) -> Void - ) -> some View { - modifier( - CollectionAlertsModifier( - isNewCollectionAlertPresented: isNewCollectionAlertPresented, - newCollectionName: newCollectionName, - isCollectionErrorAlertPresented: isCollectionErrorAlertPresented, - onCreate: onCreate - ) - ) - } -} -- cgit v1.2.3