-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAddItemView.swift
44 lines (41 loc) · 1.35 KB
/
AddItemView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//
// AddItemView.swift
//
// Created by Speedyfriend67 on 27.06.24
//
import SwiftUI
struct AddItemView: View {
@State private var itemName: String = ""
@State private var showAlert = false
@Binding var isPresented: Bool
var isDirectory: Bool
var existingNames: [String]
var onComplete: (String) -> Void
var body: some View {
NavigationView {
Form {
Section(header: Text(isDirectory ? "New Folder Name" : "New File Name")) {
TextField(isDirectory ? "Folder Name" : "File Name", text: $itemName)
}
}
.navigationTitle(isDirectory ? "New Folder" : "New File")
.navigationBarItems(leading: Button("Cancel") {
isPresented = false
}, trailing: Button("Save") {
if itemName.isEmpty || existingNames.contains(itemName) {
showAlert = true
} else {
onComplete(itemName)
isPresented = false
}
})
.alert(isPresented: $showAlert) {
Alert(
title: Text("Invalid Name"),
message: Text("Please provide a unique and non-empty name."),
dismissButton: .default(Text("OK"))
)
}
}
}
}