feat: Redesign server settings form with prompt parameters and quick input chips

- Remove redundant field labels, use prompt parameter instead
- Add QuickInputChip component for quick URL entry
- Add chips: http://, https://, 192.168., :8000
- Improve spacing and layout consistency
- Cleaner, more modern UI appearance
This commit is contained in:
Ilyas Hallak 2025-10-19 19:26:40 +02:00
parent 819eb4fc56
commit 554e223bbc

View File

@ -30,20 +30,51 @@ struct SettingsServerView: View {
// Form // Form
VStack(spacing: 16) { VStack(spacing: 16) {
VStack(alignment: .leading, spacing: 6) { // Server Endpoint
Text("Server Endpoint") VStack(alignment: .leading, spacing: 8) {
.font(.headline)
if viewModel.isSetupMode { if viewModel.isSetupMode {
TextField("http://192.168.0.77:8000", text: $viewModel.endpoint) TextField("",
text: $viewModel.endpoint,
prompt: Text("Server Endpoint").foregroundColor(.secondary))
.textFieldStyle(.roundedBorder) .textFieldStyle(.roundedBorder)
.keyboardType(.URL) .keyboardType(.URL)
.autocapitalization(.none) .autocapitalization(.none)
.disableAutocorrection(true) .disableAutocorrection(true)
.tint(.gray)
.onChange(of: viewModel.endpoint) { .onChange(of: viewModel.endpoint) {
viewModel.clearMessages() viewModel.clearMessages()
} }
// Quick Input Chips
ScrollView(.horizontal, showsIndicators: false) {
HStack(spacing: 8) {
QuickInputChip(text: "http://", action: {
if !viewModel.endpoint.starts(with: "http") {
viewModel.endpoint = "http://" + viewModel.endpoint
}
})
QuickInputChip(text: "https://", action: {
if !viewModel.endpoint.starts(with: "http") {
viewModel.endpoint = "https://" + viewModel.endpoint
}
})
QuickInputChip(text: "192.168.", action: {
if viewModel.endpoint.isEmpty || viewModel.endpoint == "http://" || viewModel.endpoint == "https://" {
if viewModel.endpoint.starts(with: "http") {
viewModel.endpoint += "192.168."
} else {
viewModel.endpoint = "http://192.168."
}
}
})
QuickInputChip(text: ":8000", action: {
if !viewModel.endpoint.contains(":") || viewModel.endpoint.hasSuffix("://") {
viewModel.endpoint += ":8000"
}
})
}
.padding(.horizontal, 1)
}
Text("HTTP/HTTPS supported. HTTP only for local networks. Port optional. No trailing slash needed.") Text("HTTP/HTTPS supported. HTTP only for local networks. Port optional. No trailing slash needed.")
.font(.caption) .font(.caption)
.foregroundColor(.secondary) .foregroundColor(.secondary)
@ -60,11 +91,13 @@ struct SettingsServerView: View {
.padding(.vertical, 8) .padding(.vertical, 8)
} }
} }
VStack(alignment: .leading, spacing: 6) {
Text("Username") // Username
.font(.headline) VStack(alignment: .leading, spacing: 8) {
if viewModel.isSetupMode { if viewModel.isSetupMode {
TextField("Your Username", text: $viewModel.username) TextField("",
text: $viewModel.username,
prompt: Text("Username").foregroundColor(.secondary))
.textFieldStyle(.roundedBorder) .textFieldStyle(.roundedBorder)
.autocapitalization(.none) .autocapitalization(.none)
.disableAutocorrection(true) .disableAutocorrection(true)
@ -83,12 +116,13 @@ struct SettingsServerView: View {
.padding(.vertical, 8) .padding(.vertical, 8)
} }
} }
if viewModel.isSetupMode {
VStack(alignment: .leading, spacing: 6) {
Text("Password")
.font(.headline)
SecureField("Your Password", text: $viewModel.password) // Password
if viewModel.isSetupMode {
VStack(alignment: .leading, spacing: 8) {
SecureField("",
text: $viewModel.password,
prompt: Text("Password").foregroundColor(.secondary))
.textFieldStyle(.roundedBorder) .textFieldStyle(.roundedBorder)
.onChange(of: viewModel.password) { .onChange(of: viewModel.password) {
viewModel.clearMessages() viewModel.clearMessages()
@ -176,3 +210,23 @@ struct SettingsServerView: View {
} }
} }
} }
// MARK: - Quick Input Chip Component
struct QuickInputChip: View {
let text: String
let action: () -> Void
var body: some View {
Button(action: action) {
Text(text)
.font(.caption)
.fontWeight(.medium)
.padding(.horizontal, 12)
.padding(.vertical, 6)
.background(Color(.systemGray5))
.foregroundColor(.secondary)
.cornerRadius(12)
}
}
}