Persist log and connection search state across tabs
This commit is contained in:
@@ -60,10 +60,15 @@ public struct ConnectionListView: View {
|
|||||||
#endif
|
#endif
|
||||||
.alert($viewModel.alert)
|
.alert($viewModel.alert)
|
||||||
.onAppear {
|
.onAppear {
|
||||||
|
if !environments.connectionSearchText.isEmpty {
|
||||||
|
viewModel.searchText = environments.connectionSearchText
|
||||||
|
viewModel.isSearching = true
|
||||||
|
}
|
||||||
viewModel.connect()
|
viewModel.connect()
|
||||||
commandClient.connect()
|
commandClient.connect()
|
||||||
}
|
}
|
||||||
.onDisappear {
|
.onDisappear {
|
||||||
|
environments.connectionSearchText = viewModel.searchText
|
||||||
viewModel.disconnect()
|
viewModel.disconnect()
|
||||||
commandClient.disconnect()
|
commandClient.disconnect()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,15 +15,16 @@ public struct LogView: View {
|
|||||||
public init() {}
|
public init() {}
|
||||||
|
|
||||||
public var body: some View {
|
public var body: some View {
|
||||||
LogViewContent(commandClient: environments.commandClient)
|
LogViewContent(commandClient: environments.commandClient, initialSearchText: environments.logSearchText)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private struct LogViewContent: View {
|
private struct LogViewContent: View {
|
||||||
|
@EnvironmentObject private var environments: ExtensionEnvironments
|
||||||
@StateObject private var viewModel: LogViewModel
|
@StateObject private var viewModel: LogViewModel
|
||||||
|
|
||||||
init(commandClient: CommandClient) {
|
init(commandClient: CommandClient, initialSearchText: String = "") {
|
||||||
_viewModel = StateObject(wrappedValue: LogViewModel(commandClient: commandClient))
|
_viewModel = StateObject(wrappedValue: LogViewModel(commandClient: commandClient, searchText: initialSearchText))
|
||||||
}
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
@@ -35,6 +36,9 @@ private struct LogViewContent: View {
|
|||||||
toolbarButtons
|
toolbarButtons
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.onDisappear {
|
||||||
|
environments.logSearchText = viewModel.searchText
|
||||||
|
}
|
||||||
.alert($viewModel.alert)
|
.alert($viewModel.alert)
|
||||||
.background(
|
.background(
|
||||||
LogExportView(
|
LogExportView(
|
||||||
|
|||||||
@@ -176,8 +176,10 @@ public class LogViewModel: BaseViewModel {
|
|||||||
public let commandClient: CommandClient
|
public let commandClient: CommandClient
|
||||||
public private(set) var dataModel: LogDataModel!
|
public private(set) var dataModel: LogDataModel!
|
||||||
|
|
||||||
public init(commandClient: CommandClient) {
|
public init(commandClient: CommandClient, searchText: String = "") {
|
||||||
self.commandClient = commandClient
|
self.commandClient = commandClient
|
||||||
|
self.searchText = searchText
|
||||||
|
self.isSearching = !searchText.isEmpty
|
||||||
super.init()
|
super.init()
|
||||||
dataModel = LogDataModel(commandClient: commandClient, viewModel: self)
|
dataModel = LogDataModel(commandClient: commandClient, viewModel: self)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -180,6 +180,9 @@ public class ExtensionEnvironments: ObservableObject {
|
|||||||
@Published public var emptyProfiles = false
|
@Published public var emptyProfiles = false
|
||||||
@Published public var pendingImportRemoteProfile: ImportRemoteProfileRequest?
|
@Published public var pendingImportRemoteProfile: ImportRemoteProfileRequest?
|
||||||
|
|
||||||
|
public var logSearchText = ""
|
||||||
|
public var connectionSearchText = ""
|
||||||
|
|
||||||
public let profileUpdate = ObjectWillChangePublisher()
|
public let profileUpdate = ObjectWillChangePublisher()
|
||||||
public let selectedProfileUpdate = ObjectWillChangePublisher()
|
public let selectedProfileUpdate = ObjectWillChangePublisher()
|
||||||
public let openSettings = ObjectWillChangePublisher()
|
public let openSettings = ObjectWillChangePublisher()
|
||||||
|
|||||||
Reference in New Issue
Block a user