summaryrefslogtreecommitdiff
path: root/Sora/Views/Generic/CollectionAlertsModifier.swift
diff options
context:
space:
mode:
authorFuwn <[email protected]>2025-07-08 06:05:10 -0700
committerFuwn <[email protected]>2025-07-08 06:21:44 -0700
commitf7ed210669cd0384438b45b8fa0894d3746b8399 (patch)
tree1b0140d3ec2bfe8ae8d33aba079ce47f2561b203 /Sora/Views/Generic/CollectionAlertsModifier.swift
parentfeat: Development commit (diff)
downloadsora-testing-f7ed210669cd0384438b45b8fa0894d3746b8399.tar.xz
sora-testing-f7ed210669cd0384438b45b8fa0894d3746b8399.zip
feat: Development commit
Diffstat (limited to 'Sora/Views/Generic/CollectionAlertsModifier.swift')
-rw-r--r--Sora/Views/Generic/CollectionAlertsModifier.swift59
1 files changed, 59 insertions, 0 deletions
diff --git a/Sora/Views/Generic/CollectionAlertsModifier.swift b/Sora/Views/Generic/CollectionAlertsModifier.swift
new file mode 100644
index 0000000..6c39da8
--- /dev/null
+++ b/Sora/Views/Generic/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<Bool>,
+ newCollectionName: Binding<String>,
+ isCollectionErrorAlertPresented: Binding<Bool>,
+ onCreate: @escaping (String) -> Void
+ ) -> some View {
+ modifier(
+ CollectionAlertsModifier(
+ isNewCollectionAlertPresented: isNewCollectionAlertPresented,
+ newCollectionName: newCollectionName,
+ isCollectionErrorAlertPresented: isCollectionErrorAlertPresented,
+ onCreate: onCreate
+ )
+ )
+ }
+}