mirror of
https://github.com/yJason/ClashX-Dashboard.git
synced 2026-02-04 10:02:26 +08:00
feat: search support
This commit is contained in:
@@ -16,6 +16,16 @@ struct ProviderProxiesView: View {
|
|||||||
@State private var isTesting = false
|
@State private var isTesting = false
|
||||||
@State private var isUpdating = false
|
@State private var isUpdating = false
|
||||||
|
|
||||||
|
var proxies: [DBProxy] {
|
||||||
|
if searchString.string.isEmpty {
|
||||||
|
return provider.proxies
|
||||||
|
} else {
|
||||||
|
return provider.proxies.filter {
|
||||||
|
$0.name.lowercased().contains(searchString.string.lowercased())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
ScrollView {
|
ScrollView {
|
||||||
Section {
|
Section {
|
||||||
@@ -55,21 +65,13 @@ struct ProviderProxiesView: View {
|
|||||||
var proxyListView: some View {
|
var proxyListView: some View {
|
||||||
LazyVGrid(columns: Array(repeating: GridItem(.flexible()),
|
LazyVGrid(columns: Array(repeating: GridItem(.flexible()),
|
||||||
count: columnCount)) {
|
count: columnCount)) {
|
||||||
ForEach($provider.proxies, id: \.id) { proxy in
|
ForEach(proxies, id: \.id) { proxy in
|
||||||
ProxyItemView(
|
ProxyItemView(
|
||||||
proxy: proxy,
|
proxy: proxy,
|
||||||
selectable: false
|
selectable: false
|
||||||
)
|
)
|
||||||
.background(.white)
|
.background(.white)
|
||||||
.cornerRadius(8)
|
.cornerRadius(8)
|
||||||
|
|
||||||
.show(isVisible: {
|
|
||||||
if searchString.string.isEmpty {
|
|
||||||
return true
|
|
||||||
} else {
|
|
||||||
return proxy.wrappedValue.name.lowercased().contains(searchString.string.lowercased())
|
|
||||||
}
|
|
||||||
}())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,9 +9,20 @@ import SwiftUI
|
|||||||
struct ProxyProvidersRowView: View {
|
struct ProxyProvidersRowView: View {
|
||||||
|
|
||||||
@ObservedObject var providerStorage: DBProviderStorage
|
@ObservedObject var providerStorage: DBProviderStorage
|
||||||
|
@EnvironmentObject var searchString: ProxiesSearchString
|
||||||
|
|
||||||
@State private var isUpdating = false
|
@State private var isUpdating = false
|
||||||
|
|
||||||
|
var providers: [DBProxyProvider] {
|
||||||
|
if searchString.string.isEmpty {
|
||||||
|
return providerStorage.proxyProviders
|
||||||
|
} else {
|
||||||
|
return providerStorage.proxyProviders.filter {
|
||||||
|
$0.name.lowercased().contains(searchString.string.lowercased())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
NavigationLink {
|
NavigationLink {
|
||||||
contentView
|
contentView
|
||||||
@@ -53,7 +64,7 @@ struct ProxyProvidersRowView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var listView: some View {
|
var listView: some View {
|
||||||
ForEach(providerStorage.proxyProviders, id: \.id) {
|
ForEach(providers, id: \.id) {
|
||||||
ProxyProviderInfoView(provider: $0)
|
ProxyProviderInfoView(provider: $0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,9 +9,20 @@ import SwiftUI
|
|||||||
struct RuleProvidersRowView: View {
|
struct RuleProvidersRowView: View {
|
||||||
|
|
||||||
@ObservedObject var providerStorage: DBProviderStorage
|
@ObservedObject var providerStorage: DBProviderStorage
|
||||||
|
@EnvironmentObject var searchString: ProxiesSearchString
|
||||||
|
|
||||||
@State private var isUpdating = false
|
@State private var isUpdating = false
|
||||||
|
|
||||||
|
var providers: [DBRuleProvider] {
|
||||||
|
if searchString.string.isEmpty {
|
||||||
|
return providerStorage.ruleProviders
|
||||||
|
} else {
|
||||||
|
return providerStorage.ruleProviders.filter {
|
||||||
|
$0.name.lowercased().contains(searchString.string.lowercased())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
NavigationLink {
|
NavigationLink {
|
||||||
contentView
|
contentView
|
||||||
@@ -26,7 +37,7 @@ struct RuleProvidersRowView: View {
|
|||||||
ScrollView {
|
ScrollView {
|
||||||
Section {
|
Section {
|
||||||
VStack(spacing: 12) {
|
VStack(spacing: 12) {
|
||||||
ForEach(providerStorage.ruleProviders, id: \.id) {
|
ForEach(providers, id: \.id) {
|
||||||
RuleProviderView(provider: $0)
|
RuleProviderView(provider: $0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,16 @@ struct ProxyGroupView: View {
|
|||||||
@State private var selectable = false
|
@State private var selectable = false
|
||||||
@State private var isTesting = false
|
@State private var isTesting = false
|
||||||
|
|
||||||
|
var proxies: [DBProxy] {
|
||||||
|
if searchString.string.isEmpty {
|
||||||
|
return proxyGroup.proxies
|
||||||
|
} else {
|
||||||
|
return proxyGroup.proxies.filter {
|
||||||
|
$0.name.lowercased().contains(searchString.string.lowercased())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
ScrollView {
|
ScrollView {
|
||||||
Section {
|
Section {
|
||||||
@@ -96,24 +106,17 @@ struct ProxyGroupView: View {
|
|||||||
var proxyListView: some View {
|
var proxyListView: some View {
|
||||||
LazyVGrid(columns: Array(repeating: GridItem(.flexible()),
|
LazyVGrid(columns: Array(repeating: GridItem(.flexible()),
|
||||||
count: columnCount)) {
|
count: columnCount)) {
|
||||||
ForEach($proxyGroup.proxies, id: \.id) { proxy in
|
ForEach(proxies, id: \.id) { proxy in
|
||||||
ProxyItemView(
|
ProxyItemView(
|
||||||
proxy: proxy,
|
proxy: proxy,
|
||||||
selectable: selectable
|
selectable: selectable
|
||||||
)
|
)
|
||||||
.background(proxyGroup.now == proxy.wrappedValue.name ? Color.teal : Color.white)
|
.background(proxyGroup.now == proxy.name ? Color.teal : Color.white)
|
||||||
.cornerRadius(8)
|
.cornerRadius(8)
|
||||||
.onTapGesture {
|
.onTapGesture {
|
||||||
let item = proxy.wrappedValue
|
let item = proxy
|
||||||
updateSelect(item.name)
|
updateSelect(item.name)
|
||||||
}
|
}
|
||||||
.show(isVisible: {
|
|
||||||
if searchString.string.isEmpty {
|
|
||||||
return true
|
|
||||||
} else {
|
|
||||||
return proxy.wrappedValue.name.lowercased().contains(searchString.string.lowercased())
|
|
||||||
}
|
|
||||||
}())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,16 +8,16 @@ import SwiftUI
|
|||||||
|
|
||||||
struct ProxyItemView: View {
|
struct ProxyItemView: View {
|
||||||
|
|
||||||
@Binding var proxy: DBProxy
|
@ObservedObject var proxy: DBProxy
|
||||||
@State var selectable: Bool
|
@State var selectable: Bool
|
||||||
|
|
||||||
@EnvironmentObject var hideProxyNames: HideProxyNames
|
@EnvironmentObject var hideProxyNames: HideProxyNames
|
||||||
|
|
||||||
init(proxy: Binding<DBProxy>, selectable: Bool) {
|
init(proxy: DBProxy, selectable: Bool) {
|
||||||
self._proxy = proxy
|
self.proxy = proxy
|
||||||
self.selectable = selectable
|
self.selectable = selectable
|
||||||
|
|
||||||
self.isBuiltInProxy = [.pass, .direct, .reject].contains(proxy.wrappedValue.type)
|
self.isBuiltInProxy = [.pass, .direct, .reject].contains(proxy.type)
|
||||||
}
|
}
|
||||||
|
|
||||||
@State private var isBuiltInProxy: Bool
|
@State private var isBuiltInProxy: Bool
|
||||||
|
|||||||
Reference in New Issue
Block a user