82 lines
1.9 KiB
Swift
82 lines
1.9 KiB
Swift
|
//
|
||
|
// MenuBarView.swift
|
||
|
// Piper ~ App
|
||
|
//
|
||
|
// Created by Javier Cicchelli on 06/10/2024.
|
||
|
// Copyright © 2024 Röck+Cöde. All rights reserved.
|
||
|
//
|
||
|
|
||
|
import SwiftUI
|
||
|
import SwiftData
|
||
|
|
||
|
struct MenuBarView: View {
|
||
|
|
||
|
// MARK: Properties
|
||
|
|
||
|
@Query(sort: \Repository.sortOrder)
|
||
|
private var repositories: [Repository]
|
||
|
|
||
|
@State private var viewMode = MenuBarViewModel()
|
||
|
|
||
|
// MARK: Body
|
||
|
|
||
|
var body: some View {
|
||
|
List {
|
||
|
Section {
|
||
|
if repositories.isEmpty {
|
||
|
ListItemEmpty(
|
||
|
title: "menu-bar.item.empty.title.text",
|
||
|
button: "menu-bar.item.empty.button.text"
|
||
|
) {
|
||
|
// ...
|
||
|
}
|
||
|
.frame(height: Layout.heightEmpty)
|
||
|
} else {
|
||
|
ForEach(repositories) {
|
||
|
ListItem(repository: $0)
|
||
|
}
|
||
|
}
|
||
|
} header: {
|
||
|
ListHeader(
|
||
|
title: "menu-bar.section.repositories.title.text",
|
||
|
button: "menu-bar.section.repositories.button.text",
|
||
|
showButton: !repositories.isEmpty
|
||
|
) {
|
||
|
// ...
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
.frame(
|
||
|
width: Layout.widthView,
|
||
|
height: Layout.heightView
|
||
|
)
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
// MARK: - Layout
|
||
|
|
||
|
private extension MenuBarView {
|
||
|
enum Layout {
|
||
|
static let heightEmpty = CGFloat(200)
|
||
|
static let heightView = CGFloat(260)
|
||
|
static let widthView = CGFloat(400)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// MARK: - Previews
|
||
|
|
||
|
#Preview("Menu Bar view when no repositories found") {
|
||
|
MenuBarView()
|
||
|
.modelContainer(.preview)
|
||
|
}
|
||
|
|
||
|
#Preview("Menu Bar view when some repositories found") {
|
||
|
let container = ModelContainer.preview
|
||
|
|
||
|
Repository.samples(in: container)
|
||
|
|
||
|
return MenuBarView()
|
||
|
.modelContainer(container)
|
||
|
}
|