Merge profile to dashboard
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import Foundation
|
||||
import Library
|
||||
|
||||
@MainActor
|
||||
public struct ButtonVisibilityState {
|
||||
public var showGroupsButton = false
|
||||
public var showConnectionsButton = false
|
||||
public var groupsCount = 0
|
||||
public var connectionsCount = 0
|
||||
|
||||
public init() {}
|
||||
|
||||
public mutating func update(
|
||||
profile: ExtensionProfile?,
|
||||
commandClient: CommandClient,
|
||||
requireAnyConnection: Bool = false
|
||||
) {
|
||||
guard let profile else {
|
||||
reset()
|
||||
return
|
||||
}
|
||||
|
||||
groupsCount = commandClient.groups?.count ?? 0
|
||||
connectionsCount = commandClient.connections?.count ?? 0
|
||||
|
||||
let isConnected = ApplicationLibrary.inPreview || profile.status.isConnectedStrict
|
||||
|
||||
showConnectionsButton = isConnected && (!requireAnyConnection || commandClient.hasAnyConnection)
|
||||
showGroupsButton = isConnected && (commandClient.groups?.isEmpty == false)
|
||||
}
|
||||
|
||||
private mutating func reset() {
|
||||
showGroupsButton = false
|
||||
showConnectionsButton = false
|
||||
groupsCount = 0
|
||||
connectionsCount = 0
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user