-
Notifications
You must be signed in to change notification settings - Fork 9
/
PersonaFeature.swift
66 lines (58 loc) · 1.5 KB
/
PersonaFeature.swift
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
import ComposableArchitecture
import SwiftUI
// MARK: - Persona
struct PersonaFeature: Sendable, FeatureReducer {
struct State: Sendable, Hashable, Identifiable {
let id: Persona.ID
let thumbnail: URL?
let displayName: String
var securityProblemsConfig: EntitySecurityProblemsView.Config
init(persona: AuthorizedPersonaDetailed, problems: [SecurityProblem]) {
self.init(
id: persona.id,
thumbnail: nil,
displayName: persona.displayName.rawValue,
identityAddress: persona.identityAddress,
problems: problems
)
}
init(persona: Persona, problems: [SecurityProblem]) {
self.init(
id: persona.id,
thumbnail: nil,
displayName: persona.displayName.rawValue,
identityAddress: persona.address,
problems: problems
)
}
init(
id: Persona.ID,
thumbnail: URL?,
displayName: String,
identityAddress: IdentityAddress,
problems: [SecurityProblem]
) {
self.id = id
self.thumbnail = thumbnail
self.displayName = displayName
self.securityProblemsConfig = .init(kind: .persona(identityAddress), problems: problems)
}
}
enum ViewAction: Sendable, Equatable {
case tapped
case securityProblemsTapped
}
enum DelegateAction: Sendable, Equatable {
case openDetails
case openSecurityCenter
}
init() {}
func reduce(into state: inout State, viewAction: ViewAction) -> Effect<Action> {
switch viewAction {
case .tapped:
.send(.delegate(.openDetails))
case .securityProblemsTapped:
.send(.delegate(.openSecurityCenter))
}
}
}