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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
import SwiftUI
struct DeviceListView: View {
@Binding var devices: [Device]?
@Binding var loading: Bool
var onRemoveDevice: ((Device) -> Void)?
let header: (() -> AnyView)?
struct Device: Identifiable, Hashable {
let id: String
let name: String
let created: Date
let isCurrentDevice: Bool
var isBeingRemoved: Bool
func setIsBeingRemoved(_ isBeingRemoved: Bool) -> Self {
var updatedSelf = self
updatedSelf.isBeingRemoved = isBeingRemoved
return updatedSelf
}
}
var body: some View {
let headerContent: () -> some View = {
VStack {
if let header {
header()
}
if loading {
Spacer()
VStack(spacing: 16) {
ProgressView()
.progressViewStyle(MullvadProgressViewStyle())
Text("Fetching devices...")
.foregroundColor(.mullvadTextPrimary.opacity(0.6))
}
Spacer()
}
}
}
MullvadList(
devices ?? [],
header: headerContent,
footer: { EmptyView() },
content: { device in
MullvadListActionItemView(
item: .init(
id: device.id,
title: LocalizedStringKey(device.name),
state: device.isCurrentDevice ? "Current device" : nil,
detail: "Created: \(device.created.formatted(date: .long, time: .omitted))",
accessibilityIdentifier: .deviceCellRemoveButton,
pressed: {
onRemoveDevice?(device)
}
),
icon: {
if !device.isCurrentDevice {
if device.isBeingRemoved {
ProgressView()
.progressViewStyle(MullvadProgressViewStyle())
.frame(width: 24, height: 24)
.accessibilityIdentifier(.deviceRemovalProgressView)
} else {
Image.mullvadIconClose
}
}
}
)
}
)
.accessibilityIdentifier(.deviceManagementView)
}
}
#Preview {
DeviceListView(
devices: .constant([
DeviceListView.Device(
id: "1",
name: "Test device",
created: Date(),
isCurrentDevice: false,
isBeingRemoved: true
),
DeviceListView.Device(
id: "2",
name: "Test device",
created: Date(),
isCurrentDevice: false,
isBeingRemoved: false
),
]),
loading: .constant(false),
onRemoveDevice: nil,
header: nil
)
}
#Preview("Loading") {
DeviceListView(
devices: .constant([]),
loading: .constant(true),
onRemoveDevice: nil,
header: nil
)
.background(Color.mullvadBackground)
}
|