2020-01-21 01:11:55 +00:00
|
|
|
//
|
|
|
|
// PiHoleDetailsView.swift
|
|
|
|
// Pi-Helper
|
|
|
|
//
|
|
|
|
// Created by Billy Brawner on 10/19/19.
|
|
|
|
// Copyright © 2019 William Brawner. All rights reserved.
|
|
|
|
//
|
|
|
|
|
2022-10-19 00:52:30 +00:00
|
|
|
import Pihelper
|
2020-01-21 01:11:55 +00:00
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct PiHoleDetailsView: View {
|
2022-10-19 00:52:30 +00:00
|
|
|
@EnvironmentObject var store: PihelperStore
|
|
|
|
|
2022-03-04 02:35:21 +00:00
|
|
|
@ViewBuilder
|
2022-10-19 00:52:30 +00:00
|
|
|
var stateContent: some View {
|
|
|
|
if self.store.state.loading {
|
2022-03-04 02:35:21 +00:00
|
|
|
ActivityIndicatorView()
|
2022-10-19 00:52:30 +00:00
|
|
|
} else {
|
|
|
|
PiHoleActionsView()
|
2020-01-21 01:11:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
NavigationView {
|
2022-10-19 00:52:30 +00:00
|
|
|
stateContent
|
|
|
|
.animation(.default, value: self.store.state.status)
|
2022-03-04 02:35:21 +00:00
|
|
|
.navigationBarTitle("Pi-helper")
|
2022-10-19 00:52:30 +00:00
|
|
|
.navigationBarItems(trailing: NavigationLink(destination: AboutView(), label: {
|
2020-01-31 15:29:15 +00:00
|
|
|
Image(systemName: "info.circle")
|
|
|
|
.padding()
|
|
|
|
}))
|
2020-01-21 01:11:55 +00:00
|
|
|
}
|
|
|
|
.navigationViewStyle(StackNavigationViewStyle())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct PiHoleActionsView: View {
|
|
|
|
var body: some View {
|
|
|
|
VStack {
|
|
|
|
HStack {
|
|
|
|
Text("status")
|
2022-10-19 00:52:30 +00:00
|
|
|
PiholeStatusView()
|
2020-01-21 01:11:55 +00:00
|
|
|
}
|
2022-10-19 00:52:30 +00:00
|
|
|
PiHoleActions()
|
2020-01-21 01:11:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-04 02:35:21 +00:00
|
|
|
struct PiholeStatusView: View {
|
2022-10-19 00:52:30 +00:00
|
|
|
@EnvironmentObject var store: PihelperStore
|
|
|
|
|
2022-03-04 02:35:21 +00:00
|
|
|
@ViewBuilder
|
2020-01-21 01:11:55 +00:00
|
|
|
var body: some View {
|
2022-03-04 02:35:21 +00:00
|
|
|
HStack {
|
2022-10-19 00:52:30 +00:00
|
|
|
if let status = store.state.status {
|
|
|
|
Text(status.localizedStringKey)
|
2022-03-04 02:35:21 +00:00
|
|
|
.foregroundColor(status.foregroundColor)
|
2023-01-09 02:47:53 +00:00
|
|
|
if status is Status.Disabled, let timeRemaining = (status as! Status.Disabled).timeRemaining {
|
|
|
|
Text("(\(timeRemaining))")
|
|
|
|
.monospacedDigit()
|
|
|
|
.foregroundColor(status.foregroundColor)
|
|
|
|
}
|
2020-10-20 00:46:05 +00:00
|
|
|
}
|
2020-01-21 01:11:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct PiHoleActions: View {
|
2022-10-19 00:52:30 +00:00
|
|
|
@EnvironmentObject var store: PihelperStore
|
|
|
|
@SwiftUI.State var showCustomDisable: Bool = false
|
|
|
|
|
2020-01-21 01:11:55 +00:00
|
|
|
var body: some View {
|
|
|
|
stateContent.padding()
|
|
|
|
}
|
2022-10-19 00:52:30 +00:00
|
|
|
|
|
|
|
@ViewBuilder
|
|
|
|
var stateContent: some View {
|
|
|
|
switch self.store.state.status {
|
2023-01-09 02:47:53 +00:00
|
|
|
case is Pihelper.Status.Disabled:
|
2022-10-19 00:52:30 +00:00
|
|
|
Button(action: {
|
|
|
|
self.store.dispatch(ActionEnable())
|
|
|
|
}, label: { Text("enable") })
|
2020-01-26 20:43:54 +00:00
|
|
|
.buttonStyle(PiHelperButtonStyle(.green))
|
|
|
|
.padding(Edge.Set(arrayLiteral: [.bottom, .top]), 5.0)
|
2023-01-09 02:47:53 +00:00
|
|
|
case is Pihelper.Status.Enabled:
|
2022-10-19 00:52:30 +00:00
|
|
|
VStack {
|
|
|
|
Button(action: {
|
|
|
|
self.store.dispatch(ActionDisable(duration: 10))
|
|
|
|
}, label: { Text("disable_10_sec") })
|
2020-01-21 01:11:55 +00:00
|
|
|
.buttonStyle(PiHelperButtonStyle())
|
|
|
|
.padding(Edge.Set(arrayLiteral: [.bottom, .top]), 5.0)
|
2022-10-19 00:52:30 +00:00
|
|
|
Button(action: {
|
|
|
|
self.store.dispatch(ActionDisable(duration: 30))
|
|
|
|
}, label: { Text("disable_30_sec") })
|
2020-01-21 01:11:55 +00:00
|
|
|
.buttonStyle(PiHelperButtonStyle())
|
|
|
|
.padding(Edge.Set(arrayLiteral: [.bottom, .top]), 5.0)
|
2022-10-19 00:52:30 +00:00
|
|
|
Button(action: {
|
|
|
|
self.store.dispatch(ActionDisable(duration: 300))
|
|
|
|
}, label: { Text("disable_5_min") })
|
2020-01-21 01:11:55 +00:00
|
|
|
.buttonStyle(PiHelperButtonStyle())
|
|
|
|
.padding(Edge.Set(arrayLiteral: [.bottom, .top]), 5.0)
|
2020-07-04 17:51:51 +00:00
|
|
|
Button(action: {
|
2022-10-19 00:52:30 +00:00
|
|
|
self.showCustomDisable = true
|
2020-07-04 17:51:51 +00:00
|
|
|
}, label: { Text("disable_custom") })
|
|
|
|
.buttonStyle(PiHelperButtonStyle())
|
|
|
|
.padding(Edge.Set(arrayLiteral: [.bottom, .top]), 5.0)
|
2022-10-19 00:52:30 +00:00
|
|
|
Button(action: {
|
|
|
|
self.store.dispatch(ActionDisable(duration: nil))
|
|
|
|
}, label: { Text("disable_permanent") })
|
2020-01-21 01:11:55 +00:00
|
|
|
.buttonStyle(PiHelperButtonStyle())
|
|
|
|
.padding(Edge.Set(arrayLiteral: [.bottom, .top]), 5.0)
|
2022-03-04 02:35:21 +00:00
|
|
|
NavigationLink(
|
2022-10-19 00:52:30 +00:00
|
|
|
destination: DisableCustomTimeView(showCustom: self.$showCustomDisable),
|
|
|
|
isActive: self.$showCustomDisable,
|
2022-03-04 02:35:21 +00:00
|
|
|
label: { EmptyView() }
|
|
|
|
)
|
2022-10-19 00:52:30 +00:00
|
|
|
}
|
2020-01-26 20:43:54 +00:00
|
|
|
default:
|
2022-10-19 00:52:30 +00:00
|
|
|
Text("Unable to load Pi-hole status. Please verify your credentials and ensure the Pi-hole is accessible from your current network.")
|
2020-01-21 01:11:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct PiHoleDetailsView_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
2022-10-19 00:52:30 +00:00
|
|
|
PiHoleDetailsView()
|
2020-01-21 01:11:55 +00:00
|
|
|
}
|
|
|
|
}
|