refactor: ProgressButton

This commit is contained in:
mrFq1
2023-05-23 23:19:29 +08:00
parent 088fc47329
commit 0a6ff05168
6 changed files with 115 additions and 87 deletions
@@ -76,48 +76,33 @@ struct ProviderProxiesView: View {
}
}
var buttonsView: some View {
VStack {
Button() {
startHealthCheck()
} label: {
HStack {
if isTesting {
ProgressView()
.controlSize(.small)
.frame(width: 12)
} else {
Image(systemName: "bolt.fill")
.frame(width: 12)
}
Text(isTesting ? "Testing" : "Health Check")
.frame(width: 90)
ProgressButton(
title: "Health Check",
title2: "Testing",
iconName: "bolt.fill",
inProgress: $isTesting,
autoWidth: false) {
startHealthCheck()
}
.foregroundColor(isTesting ? .gray : .blue)
}
.disabled(isTesting)
Button() {
startUpdate()
} label: {
HStack {
if isUpdating {
ProgressView()
.controlSize(.small)
.frame(width: 12)
} else {
Image(systemName: "arrow.clockwise")
.frame(width: 12)
}
Text(isUpdating ? "Updating" : "Update")
.frame(width: 90)
ProgressButton(
title: "Update",
title2: "Updating",
iconName: "arrow.clockwise",
inProgress: $isUpdating,
autoWidth: false) {
startUpdate()
}
.foregroundColor(isUpdating ? .gray : .blue)
}
.disabled(isTesting)
}
.frame(width: ProgressButton.width(
[
"Health Check",
"Testing",
"Update",
"Updating"]
))
}
func startHealthCheck() {
@@ -40,24 +40,12 @@ struct ProxyProvidersRowView: View {
listView
}
} header: {
Button {
updateAll()
} label: {
HStack {
if isUpdating {
ProgressView()
.controlSize(.small)
.frame(width: 12)
} else {
Image(systemName: "arrow.clockwise")
.frame(width: 12)
}
Text(isUpdating ? "Updating" : "Update All")
.frame(width: 80)
ProgressButton(
title: "Update All",
title2: "Updating",
iconName: "arrow.clockwise", inProgress: $isUpdating) {
updateAll()
}
.foregroundColor(isUpdating ? .gray : .blue)
}
.disabled(isUpdating)
}
.padding()
}
@@ -42,24 +42,13 @@ struct RuleProvidersRowView: View {
}
}
} header: {
Button {
updateAll()
} label: {
HStack {
if isUpdating {
ProgressView()
.controlSize(.small)
.frame(width: 12)
} else {
Image(systemName: "arrow.clockwise")
.frame(width: 12)
}
Text(isUpdating ? "Updating" : "Update All")
.frame(width: 80)
ProgressButton(
title: "Update All",
title2: "Updating",
iconName: "arrow.clockwise",
inProgress: $isUpdating) {
updateAll()
}
.foregroundColor(isUpdating ? .gray : .blue)
}
.disabled(isUpdating)
}
.padding()
}