blob: 270996d768c00134d34f7db263b95ec0faa434d6 (
plain)
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
|
//
// MainPumpView.swift
// InfiniSolar WatchKit Extension
//
// Created by Evgeny Zinoviev on 09.08.2021.
//
import SwiftUI
struct PumpView: View {
@ObservedObject var state = PumpState()
var body: some View {
VStack(alignment: .leading) {
Text("Water pump")
.font(.title2)
.fontWeight(.thin)
Spacer().frame(height: 10)
if self.state.loading == true {
Text("Loading...")
.fontWeight(.thin)
}
else if self.state.error == true {
Text("Connection error.")
}
else {
if self.state.isEnabled == true {
Text("The pump is ").fontWeight(.thin)
+ Text("turned on")
Spacer().frame(height: 10)
Button(self.state.setting ? "..." : "Turn off") {
self.state.setState(on: false)
}
} else {
Text("The pump is ").fontWeight(.thin)
+ Text("turned off")
Spacer().frame(height: 10)
Button(self.state.setting ? "..." : "Turn on") {
self.state.setState(on: true)
}
}
}
}
.onAppear() {
self.state.fetch()
}
.onDisappear() {
self.state.abort()
}
}
}
struct PumpView_Previews: PreviewProvider {
static var previews: some View {
PumpView()
}
}
|