2024-09-23 13:02:26 +00:00
|
|
|
//
|
|
|
|
// ProfileSplitView+macOS.swift
|
|
|
|
// Passepartout
|
|
|
|
//
|
|
|
|
// Created by Davide De Rosa on 6/19/24.
|
|
|
|
// Copyright (c) 2024 Davide De Rosa. All rights reserved.
|
|
|
|
//
|
|
|
|
// https://github.com/passepartoutvpn
|
|
|
|
//
|
|
|
|
// This file is part of Passepartout.
|
|
|
|
//
|
|
|
|
// Passepartout is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Passepartout is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Passepartout. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
//
|
|
|
|
|
|
|
|
#if os(macOS)
|
|
|
|
|
2024-11-18 16:43:01 +00:00
|
|
|
import CommonLibrary
|
2024-11-02 09:11:59 +00:00
|
|
|
import CommonUtils
|
2024-09-23 13:02:26 +00:00
|
|
|
import PassepartoutKit
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct ProfileSplitView: View, Routable {
|
|
|
|
let profileEditor: ProfileEditor
|
|
|
|
|
2024-11-26 18:14:56 +00:00
|
|
|
let initialModuleId: UUID?
|
|
|
|
|
2024-09-23 13:02:26 +00:00
|
|
|
let moduleViewFactory: any ModuleViewFactory
|
|
|
|
|
2024-11-18 16:43:01 +00:00
|
|
|
@Binding
|
|
|
|
var paywallReason: PaywallReason?
|
|
|
|
|
2024-09-23 13:02:26 +00:00
|
|
|
var flow: ProfileCoordinator.Flow?
|
|
|
|
|
2024-10-23 13:42:54 +00:00
|
|
|
@State
|
|
|
|
private var detailPath = NavigationPath()
|
|
|
|
|
2024-09-23 13:02:26 +00:00
|
|
|
@State
|
|
|
|
private var selectedModuleId: UUID? = ModuleListView.generalModuleId
|
|
|
|
|
|
|
|
@State
|
2024-11-18 16:43:01 +00:00
|
|
|
private var errorModuleIds: Set<UUID> = []
|
2024-09-23 13:02:26 +00:00
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
debugChanges()
|
|
|
|
return NavigationSplitView {
|
|
|
|
ModuleListView(
|
|
|
|
profileEditor: profileEditor,
|
|
|
|
selectedModuleId: $selectedModuleId,
|
2024-11-18 16:43:01 +00:00
|
|
|
errorModuleIds: $errorModuleIds,
|
|
|
|
paywallReason: $paywallReason,
|
2024-09-23 13:02:26 +00:00
|
|
|
flow: flow
|
|
|
|
)
|
2024-11-18 16:43:01 +00:00
|
|
|
.navigationSplitViewColumnWidth(200)
|
2024-09-23 13:02:26 +00:00
|
|
|
} detail: {
|
2024-11-13 18:17:00 +00:00
|
|
|
Group {
|
2024-09-23 13:02:26 +00:00
|
|
|
switch selectedModuleId {
|
|
|
|
case ModuleListView.generalModuleId:
|
|
|
|
detailView(for: .general)
|
|
|
|
|
|
|
|
default:
|
|
|
|
detailView(for: .module(id: selectedModuleId))
|
|
|
|
}
|
|
|
|
}
|
2024-11-13 18:17:00 +00:00
|
|
|
.themeNavigationStack(path: $detailPath)
|
2024-09-23 13:02:26 +00:00
|
|
|
.toolbar(content: toolbarContent)
|
2024-10-23 13:42:54 +00:00
|
|
|
.environment(\.navigationPath, $detailPath)
|
2024-09-23 13:02:26 +00:00
|
|
|
}
|
2024-11-26 18:14:56 +00:00
|
|
|
.onLoad {
|
|
|
|
if let initialModuleId {
|
|
|
|
selectedModuleId = initialModuleId
|
|
|
|
}
|
|
|
|
}
|
2024-09-23 13:02:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: -
|
|
|
|
|
|
|
|
extension ProfileSplitView {
|
|
|
|
|
|
|
|
@ToolbarContentBuilder
|
|
|
|
func toolbarContent() -> some ToolbarContent {
|
|
|
|
ToolbarItem(placement: .cancellationAction) {
|
2024-11-23 19:31:22 +00:00
|
|
|
Button(Strings.Global.Actions.cancel, role: .cancel) {
|
2024-09-23 13:02:26 +00:00
|
|
|
flow?.onCancelEditing()
|
|
|
|
}
|
2024-11-28 14:51:03 +00:00
|
|
|
.uiAccessibility(.Profile.cancel)
|
2024-09-23 13:02:26 +00:00
|
|
|
}
|
|
|
|
ToolbarItem(placement: .confirmationAction) {
|
|
|
|
ProfileSaveButton(
|
2024-11-23 19:31:22 +00:00
|
|
|
title: Strings.Global.Actions.save,
|
2024-11-18 16:43:01 +00:00
|
|
|
errorModuleIds: $errorModuleIds
|
2024-09-23 13:02:26 +00:00
|
|
|
) {
|
|
|
|
try await flow?.onCommitEditing()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: - Destinations
|
|
|
|
|
|
|
|
extension ProfileSplitView {
|
|
|
|
enum Detail: Hashable {
|
|
|
|
case general
|
|
|
|
|
|
|
|
case module(id: UUID?)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private extension ProfileSplitView {
|
|
|
|
|
|
|
|
@ViewBuilder
|
|
|
|
func detailView(for detail: Detail) -> some View {
|
|
|
|
switch detail {
|
|
|
|
case .general:
|
2024-11-18 16:43:01 +00:00
|
|
|
ProfileGeneralView(
|
|
|
|
profileEditor: profileEditor,
|
|
|
|
paywallReason: $paywallReason
|
|
|
|
)
|
2024-09-23 13:02:26 +00:00
|
|
|
|
|
|
|
case .module(let id):
|
|
|
|
ModuleDetailView(
|
|
|
|
profileEditor: profileEditor,
|
|
|
|
moduleId: id,
|
|
|
|
moduleViewFactory: moduleViewFactory
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#Preview {
|
|
|
|
ProfileSplitView(
|
2024-10-29 13:30:41 +00:00
|
|
|
profileEditor: ProfileEditor(profile: .newMockProfile()),
|
2024-11-26 18:14:56 +00:00
|
|
|
initialModuleId: nil,
|
2024-11-18 16:43:01 +00:00
|
|
|
moduleViewFactory: DefaultModuleViewFactory(registry: Registry()),
|
|
|
|
paywallReason: .constant(nil)
|
2024-09-23 13:02:26 +00:00
|
|
|
)
|
2024-10-02 14:05:40 +00:00
|
|
|
.withMockEnvironment()
|
2024-09-23 13:02:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|