2024-11-14 10:02:26 +00:00
|
|
|
//
|
|
|
|
// MigrateView+Section.swift
|
|
|
|
// Passepartout
|
|
|
|
//
|
|
|
|
// Created by Davide De Rosa on 11/13/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/>.
|
|
|
|
//
|
|
|
|
|
|
|
|
import CommonLibrary
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
extension MigrateView {
|
|
|
|
struct SectionView: View {
|
2024-11-14 14:11:25 +00:00
|
|
|
let step: Model.Step
|
|
|
|
|
2024-11-14 10:02:26 +00:00
|
|
|
let profiles: [MigratableProfile]
|
|
|
|
|
|
|
|
@Binding
|
2024-11-14 14:11:25 +00:00
|
|
|
var statuses: [UUID: MigrationStatus]
|
2024-11-14 10:02:26 +00:00
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
Section {
|
|
|
|
ForEach(profiles, id: \.id) {
|
2024-11-14 14:11:25 +00:00
|
|
|
switch step {
|
|
|
|
case .initial, .fetching, .fetched:
|
2024-11-14 10:02:26 +00:00
|
|
|
button(forProfile: $0)
|
2024-11-14 14:11:25 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
row(forProfile: $0, status: statuses[$0.id])
|
2024-11-14 10:02:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-11-14 14:11:25 +00:00
|
|
|
}
|
|
|
|
}
|
2024-11-14 10:02:26 +00:00
|
|
|
|
2024-11-14 14:11:25 +00:00
|
|
|
private extension MigrateView.SectionView {
|
|
|
|
func button(forProfile profile: MigratableProfile) -> some View {
|
|
|
|
Button {
|
|
|
|
if statuses[profile.id] == .excluded {
|
|
|
|
statuses.removeValue(forKey: profile.id)
|
|
|
|
} else {
|
|
|
|
statuses[profile.id] = .excluded
|
2024-11-14 10:02:26 +00:00
|
|
|
}
|
2024-11-14 14:11:25 +00:00
|
|
|
} label: {
|
|
|
|
row(forProfile: profile, status: nil)
|
2024-11-14 10:02:26 +00:00
|
|
|
}
|
2024-11-14 14:11:25 +00:00
|
|
|
}
|
2024-11-14 10:02:26 +00:00
|
|
|
|
2024-11-14 14:11:25 +00:00
|
|
|
func row(forProfile profile: MigratableProfile, status: MigrationStatus?) -> some View {
|
|
|
|
HStack {
|
|
|
|
CardView(profile: profile)
|
|
|
|
Spacer()
|
|
|
|
StatusView(isIncluded: statuses[profile.id] != .excluded, status: status)
|
|
|
|
}
|
|
|
|
.foregroundStyle(statuses[profile.id].style)
|
|
|
|
}
|
|
|
|
}
|
2024-11-14 10:02:26 +00:00
|
|
|
|
2024-11-14 14:11:25 +00:00
|
|
|
private extension MigrateView.SectionView {
|
|
|
|
struct CardView: View {
|
|
|
|
let profile: MigratableProfile
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
VStack(alignment: .leading) {
|
|
|
|
Text(profile.name)
|
|
|
|
.font(.headline)
|
|
|
|
|
|
|
|
profile.lastUpdate.map {
|
|
|
|
Text($0.localizedDescription(style: .timestamp))
|
|
|
|
.font(.subheadline)
|
2024-11-14 10:02:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-11-14 14:11:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private extension MigrateView.SectionView {
|
|
|
|
struct StatusView: View {
|
|
|
|
let isIncluded: Bool
|
|
|
|
|
|
|
|
let status: MigrationStatus?
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
if let status {
|
|
|
|
icon(forStatus: status)
|
|
|
|
} else if isIncluded {
|
|
|
|
ThemeImage(.marked)
|
|
|
|
}
|
|
|
|
}
|
2024-11-14 10:02:26 +00:00
|
|
|
|
|
|
|
@ViewBuilder
|
|
|
|
func icon(forStatus status: MigrationStatus) -> some View {
|
|
|
|
switch status {
|
|
|
|
case .excluded:
|
2024-11-14 14:11:25 +00:00
|
|
|
Text("--")
|
2024-11-14 10:02:26 +00:00
|
|
|
|
|
|
|
case .pending:
|
|
|
|
ProgressView()
|
|
|
|
|
2024-11-14 14:11:25 +00:00
|
|
|
case .migrated, .imported:
|
2024-11-14 10:02:26 +00:00
|
|
|
ThemeImage(.marked)
|
|
|
|
|
2024-11-14 14:11:25 +00:00
|
|
|
case .failed:
|
2024-11-14 10:02:26 +00:00
|
|
|
ThemeImage(.failure)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|