[App] Repositories in the Menu Bar view #4

Merged
javier merged 12 commits from app/repositories into main 2024-10-06 11:50:37 +00:00
4 changed files with 159 additions and 0 deletions
Showing only changes of commit 3ed1cc92f7 - Show all commits

View File

@ -361,6 +361,7 @@
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)";
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
};
name = Debug;
@ -417,6 +418,7 @@
MTL_FAST_MATH = YES;
SDKROOT = macosx;
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_EMIT_LOC_STRINGS = YES;
};
name = Release;
};

View File

@ -0,0 +1,56 @@
{
"sourceLanguage" : "en",
"strings" : {
"Add Item" : {
},
"Item at %@" : {
},
"menu-bar.item.empty.button.text" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Add a repository to the list"
}
}
}
},
"menu-bar.item.empty.title.text" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "No repositories have been defined yet."
}
}
}
},
"menu-bar.section.repositories.button.text" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Add"
}
}
}
},
"menu-bar.section.repositories.title.text" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Repositories"
}
}
}
},
"Select an item" : {
}
},
"version" : "1.0"
}

View File

@ -0,0 +1,20 @@
//
// MenuBarViewModel.swift
// Piper ~ App
//
// Created by Javier Cicchelli on 06/10/2024.
// Copyright © 2024 Röck+Cöde. All rights reserved.
//
import Observation
@Observable
final class MenuBarViewModel {
// MARK: Initialisers
init () {
}
}

View File

@ -0,0 +1,81 @@
//
// 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)
}