-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccountView.swift
More file actions
83 lines (78 loc) · 3.11 KB
/
Copy pathAccountView.swift
File metadata and controls
83 lines (78 loc) · 3.11 KB
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
//
// AccountView.swift
// DevLogPresentation
//
// Created by opfic on 5/14/25.
//
import SwiftUI
import ComposableArchitecture
import DevLogDomain
struct AccountView: View {
@State var store: StoreOf<AccountFeature>
var body: some View {
List {
Section(String(localized: "account_current_section")) {
HStack {
if let provider = store.currentProvider {
providerContent(provider)
}
}
}
Section(String(localized: "account_social_section")) {
let providers = AuthProvider.allCases.filter { $0 != store.currentProvider }
ForEach(providers, id: \.self) { provider in
let isConnected = store.connectedProviders.contains(provider)
let showProgressView = store.isLoading && store.activeLoadingProvider == provider
HStack {
providerContent(provider)
Spacer()
Button {
if isConnected {
store.send(.unlinkFromProvider(provider))
} else {
store.send(.linkWithProvider(provider))
}
} label: {
Text(isConnected
? String(localized: "account_disconnect")
: String(localized: "account_connect"))
.font(.caption.weight(.semibold))
.foregroundStyle(.white)
.padding(.horizontal, 12)
.padding(.vertical, 6)
.background(isConnected ? Color.red : .blue)
.clipShape(.capsule)
}
.buttonStyle(.plain)
.disabled(store.isLoading)
.opacity(showProgressView ? 0 : 1)
.overlay {
if showProgressView {
ProgressView()
}
}
}
}
}
}
.scrollDisabled(true)
.listStyle(.insetGrouped)
.navigationTitle(String(localized: "nav_account"))
.onAppear { store.send(.onAppear) }
.alert($store.scope(state: \.alert, action: \.alert))
}
private func formattedProviderName(_ provider: AuthProvider) -> String {
let rawValue = provider.rawValue
let providerPrefix = rawValue.prefix(1).uppercased()
let providerSuffix = rawValue.dropFirst().prefix(while: { $0 != "." })
return providerPrefix + providerSuffix
}
@ViewBuilder
private func providerContent(_ provider: AuthProvider) -> some View {
Image(formattedProviderName(provider))
.resizable()
.scaledToFit()
.frame(width: UIFont.labelFontSize)
Text(formattedProviderName(provider))
}
}