mirror of
https://github.com/yattee/yattee.git
synced 2026-02-20 01:39:46 +00:00
Yattee v2 rewrite
This commit is contained in:
55
Yattee/Views/Components/InstanceToolbarButton.swift
Normal file
55
Yattee/Views/Components/InstanceToolbarButton.swift
Normal file
@@ -0,0 +1,55 @@
|
||||
//
|
||||
// InstanceToolbarButton.swift
|
||||
// Yattee
|
||||
//
|
||||
// A toolbar button that shows the current active instance and allows switching.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct InstanceToolbarButton: View {
|
||||
@Environment(\.appEnvironment) private var appEnvironment
|
||||
@State private var showingPicker = false
|
||||
|
||||
var body: some View {
|
||||
if let instancesManager = appEnvironment?.instancesManager,
|
||||
instancesManager.enabledInstances.count > 1 {
|
||||
Button {
|
||||
showingPicker = true
|
||||
} label: {
|
||||
HStack(spacing: 4) {
|
||||
Image(systemName: iconForInstance)
|
||||
Text(instancesManager.activeInstance?.displayName ?? "")
|
||||
.font(.subheadline)
|
||||
.lineLimit(1)
|
||||
Image(systemName: "chevron.down")
|
||||
.font(.caption2)
|
||||
}
|
||||
}
|
||||
.sheet(isPresented: $showingPicker) {
|
||||
InstancePickerSheet()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var iconForInstance: String {
|
||||
guard let instance = appEnvironment?.instancesManager.activeInstance else {
|
||||
return "server.rack"
|
||||
}
|
||||
return instance.type.systemImage
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Preview
|
||||
|
||||
#Preview {
|
||||
NavigationStack {
|
||||
Text("Content")
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .automatic) {
|
||||
InstanceToolbarButton()
|
||||
}
|
||||
}
|
||||
}
|
||||
.appEnvironment(.preview)
|
||||
}
|
||||
Reference in New Issue
Block a user