mirror of
https://github.com/yJason/ClashX-Dashboard.git
synced 2026-03-01 00:35:19 +08:00
feat: provider tab
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
//
|
||||
// ProxyProvidersRowView.swift
|
||||
// ClashX Dashboard
|
||||
//
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct ProxyProvidersRowView: View {
|
||||
|
||||
@ObservedObject var providerStorage: DBProviderStorage
|
||||
|
||||
@State private var isUpdating = false
|
||||
|
||||
var body: some View {
|
||||
NavigationLink {
|
||||
contentView
|
||||
} label: {
|
||||
Text("Proxy")
|
||||
.font(.system(size: 15))
|
||||
.padding(EdgeInsets(top: 2, leading: 4, bottom: 2, trailing: 4))
|
||||
}
|
||||
}
|
||||
|
||||
var contentView: some View {
|
||||
ScrollView {
|
||||
Section {
|
||||
VStack(spacing: 16) {
|
||||
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)
|
||||
}
|
||||
.foregroundColor(isUpdating ? .gray : .blue)
|
||||
}
|
||||
.disabled(isUpdating)
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
}
|
||||
|
||||
var listView: some View {
|
||||
ForEach(providerStorage.proxyProviders, id: \.id) {
|
||||
ProxyProviderInfoView(provider: $0)
|
||||
}
|
||||
}
|
||||
|
||||
func updateAll() {
|
||||
isUpdating = true
|
||||
|
||||
ApiRequest.updateAllProviders(for: .proxy) { _ in
|
||||
ApiRequest.requestProxyProviderList { resp in
|
||||
providerStorage.proxyProviders = resp.allProviders.values.filter {
|
||||
$0.vehicleType == .HTTP
|
||||
}.sorted {
|
||||
$0.name < $1.name
|
||||
}
|
||||
.map(DBProxyProvider.init)
|
||||
isUpdating = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//struct AllProvidersRowView_Previews: PreviewProvider {
|
||||
// static var previews: some View {
|
||||
// ProxyProvidersRowView()
|
||||
// }
|
||||
//}
|
||||
Reference in New Issue
Block a user