-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
296 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright (c) 2024 Anass Bouassaba. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file LICENSE in the root of this repository. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the GNU Affero General Public License v3.0 only, included in the file | ||
// AGPL-3.0-only in the root of this repository. | ||
|
||
import Foundation | ||
|
||
extension String { | ||
func isValidURL() -> Bool { | ||
guard !isEmpty else { return false } | ||
if let url = URL(string: self), let scheme = url.scheme, let host = url.host { | ||
return ["http", "https"].contains(scheme) && !host.isEmpty | ||
} | ||
return false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright (c) 2024 Anass Bouassaba. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file LICENSE in the root of this repository. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the GNU Affero General Public License v3.0 only, included in the file | ||
// AGPL-3.0-only in the root of this repository. | ||
|
||
import SwiftUI | ||
|
||
struct ServerEditAPIURL: View, FormValidatable { | ||
@EnvironmentObject private var tokenStore: TokenStore | ||
@Environment(\.dismiss) private var dismiss | ||
@Environment(\.modelContext) private var context | ||
@State private var value = "" | ||
@State private var isProcessing = false | ||
private let server: Server | ||
|
||
init(_ server: Server) { | ||
self.server = server | ||
} | ||
|
||
var body: some View { | ||
Form { | ||
TextField("API URL", text: $value) | ||
} | ||
.navigationBarTitleDisplayMode(.inline) | ||
.navigationTitle("Change API URL") | ||
.toolbar { | ||
ToolbarItem(placement: .topBarTrailing) { | ||
if isProcessing { | ||
ProgressView() | ||
} else { | ||
Button("Save") { | ||
performSave() | ||
} | ||
.disabled(!isValid()) | ||
} | ||
} | ||
} | ||
.onAppear { | ||
value = server.apiURL | ||
} | ||
} | ||
|
||
private func performSave() { | ||
isProcessing = true | ||
Task { | ||
server.apiURL = value | ||
try? context.save() | ||
|
||
UserDefaults.standard.server = server | ||
tokenStore.recreateClient() | ||
|
||
DispatchQueue.main.async { | ||
dismiss() | ||
isProcessing = false | ||
} | ||
} | ||
} | ||
|
||
// MARK: - FormValidatable | ||
|
||
func isValid() -> Bool { | ||
value.isValidURL() | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
Sources/Screens/Server/ServerEditIdentityProviderURL.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright (c) 2024 Anass Bouassaba. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file LICENSE in the root of this repository. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the GNU Affero General Public License v3.0 only, included in the file | ||
// AGPL-3.0-only in the root of this repository. | ||
|
||
import SwiftUI | ||
|
||
struct ServerEditIdentityProviderURL: View, FormValidatable { | ||
@EnvironmentObject private var tokenStore: TokenStore | ||
@Environment(\.dismiss) private var dismiss | ||
@Environment(\.modelContext) private var context | ||
@State private var value = "" | ||
@State private var isProcessing = false | ||
private let server: Server | ||
|
||
init(_ server: Server) { | ||
self.server = server | ||
} | ||
|
||
var body: some View { | ||
Form { | ||
TextField("Identity Provider URL", text: $value) | ||
} | ||
.navigationBarTitleDisplayMode(.inline) | ||
.navigationTitle("Change Identity Provider URL") | ||
.toolbar { | ||
ToolbarItem(placement: .topBarTrailing) { | ||
if isProcessing { | ||
ProgressView() | ||
} else { | ||
Button("Save") { | ||
performSave() | ||
} | ||
.disabled(!isValid()) | ||
} | ||
} | ||
} | ||
.onAppear { | ||
value = server.idpURL | ||
} | ||
} | ||
|
||
private func performSave() { | ||
isProcessing = true | ||
Task { | ||
server.idpURL = value | ||
try? context.save() | ||
|
||
UserDefaults.standard.server = server | ||
tokenStore.recreateClient() | ||
|
||
DispatchQueue.main.async { | ||
dismiss() | ||
isProcessing = false | ||
} | ||
} | ||
} | ||
|
||
// MARK: - FormValidatable | ||
|
||
func isValid() -> Bool { | ||
value.isValidURL() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright (c) 2024 Anass Bouassaba. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file LICENSE in the root of this repository. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the GNU Affero General Public License v3.0 only, included in the file | ||
// AGPL-3.0-only in the root of this repository. | ||
|
||
import SwiftUI | ||
|
||
struct ServerEditName: View, FormValidatable { | ||
@EnvironmentObject private var tokenStore: TokenStore | ||
@Environment(\.dismiss) private var dismiss | ||
@Environment(\.modelContext) private var context | ||
@State private var value = "" | ||
@State private var isProcessing = false | ||
private let server: Server | ||
|
||
init(_ server: Server) { | ||
self.server = server | ||
} | ||
|
||
var body: some View { | ||
Form { | ||
TextField("Name", text: $value) | ||
} | ||
.navigationBarTitleDisplayMode(.inline) | ||
.navigationTitle("Change Name") | ||
.toolbar { | ||
ToolbarItem(placement: .topBarTrailing) { | ||
if isProcessing { | ||
ProgressView() | ||
} else { | ||
Button("Save") { | ||
performSave() | ||
} | ||
.disabled(!isValid()) | ||
} | ||
} | ||
} | ||
.onAppear { | ||
value = server.name | ||
} | ||
} | ||
|
||
private var normalizedValue: String { | ||
value.trimmingCharacters(in: .whitespaces) | ||
} | ||
|
||
private func performSave() { | ||
isProcessing = true | ||
Task { | ||
server.name = normalizedValue | ||
try? context.save() | ||
|
||
UserDefaults.standard.server = server | ||
|
||
DispatchQueue.main.async { | ||
dismiss() | ||
isProcessing = false | ||
} | ||
} | ||
} | ||
|
||
// MARK: - FormValidatable | ||
|
||
func isValid() -> Bool { | ||
!normalizedValue.isEmpty | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters