Issue #2: Moved local SwiftUI state to a view model.
This commit is contained in:
parent
3ec25bc247
commit
6b253a6843
4 changed files with 42 additions and 17 deletions
|
|
@ -35,8 +35,11 @@ enum ServiceStatus {
|
|||
}
|
||||
|
||||
struct HomeView: View {
|
||||
|
||||
@EnvironmentObject
|
||||
private var viewModel: ViewModel
|
||||
|
||||
@State private var isEnabled = false
|
||||
@State private var selectedBlocklist: BlocklistOption = .secure
|
||||
@State private var serviceStatus: ServiceStatus = .operational
|
||||
|
||||
private let falsePositiveURL = URL(string: "https://www.sr2.uk/contact")!
|
||||
|
|
@ -74,13 +77,13 @@ struct HomeView: View {
|
|||
ForEach(BlocklistOption.allCases) { option in
|
||||
BlocklistRow(
|
||||
option: option,
|
||||
isSelected: selectedBlocklist == option
|
||||
isSelected: viewModel.blocklist == option
|
||||
)
|
||||
.contentShape(Rectangle())
|
||||
.onTapGesture {
|
||||
guard option.enabled else { return }
|
||||
withAnimation(.spring(duration: 0.3)) {
|
||||
selectedBlocklist = option
|
||||
viewModel.blocklist = option
|
||||
}
|
||||
}
|
||||
.opacity(option.enabled ? 1 : 0.6)
|
||||
|
|
@ -105,7 +108,7 @@ struct HomeView: View {
|
|||
HStack {
|
||||
Label("Server", systemImage: "server.rack")
|
||||
Spacer()
|
||||
Text(selectedBlocklist.server)
|
||||
Text(viewModel.blocklist.server)
|
||||
.foregroundStyle(.secondary)
|
||||
.font(.system(.body, design: .monospaced))
|
||||
}
|
||||
|
|
@ -113,7 +116,7 @@ struct HomeView: View {
|
|||
HStack {
|
||||
Label("IPv4", systemImage: "globe")
|
||||
Spacer()
|
||||
Text(selectedBlocklist.ipv4)
|
||||
Text(viewModel.blocklist.ipv4)
|
||||
.foregroundStyle(.secondary)
|
||||
.font(.system(.body, design: .monospaced))
|
||||
}
|
||||
|
|
@ -121,7 +124,7 @@ struct HomeView: View {
|
|||
HStack {
|
||||
Label("IPv6", systemImage: "globe")
|
||||
Spacer()
|
||||
Text(selectedBlocklist.ipv6)
|
||||
Text(viewModel.blocklist.ipv6)
|
||||
.foregroundStyle(.secondary)
|
||||
.font(.system(.body, design: .monospaced))
|
||||
}
|
||||
|
|
@ -217,4 +220,5 @@ struct HomeView: View {
|
|||
|
||||
#Preview {
|
||||
HomeView()
|
||||
.environmentObject(ViewModel())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue