From 3ed1cc92f70d1fa7d4c4c8484725fa3148eed76c Mon Sep 17 00:00:00 2001 From: Javier Cicchelli Date: Sun, 6 Oct 2024 13:44:15 +0200 Subject: [PATCH] Implemented the list layout for the repositories for the MenuBarView view in the app target. --- Piper.xcodeproj/project.pbxproj | 2 + .../Resources/Catalogs/Localizable.xcstrings | 56 +++++++++++++ .../Logic/ViewModels/MenuBarViewModel.swift | 20 +++++ Piper/Sources/UI/Views/MenuBarView.swift | 81 +++++++++++++++++++ 4 files changed, 159 insertions(+) create mode 100644 Piper/Resources/Catalogs/Localizable.xcstrings create mode 100644 Piper/Sources/Logic/ViewModels/MenuBarViewModel.swift create mode 100644 Piper/Sources/UI/Views/MenuBarView.swift diff --git a/Piper.xcodeproj/project.pbxproj b/Piper.xcodeproj/project.pbxproj index fc590bd..e9c7c3f 100644 --- a/Piper.xcodeproj/project.pbxproj +++ b/Piper.xcodeproj/project.pbxproj @@ -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; }; diff --git a/Piper/Resources/Catalogs/Localizable.xcstrings b/Piper/Resources/Catalogs/Localizable.xcstrings new file mode 100644 index 0000000..f26d581 --- /dev/null +++ b/Piper/Resources/Catalogs/Localizable.xcstrings @@ -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" +} \ No newline at end of file diff --git a/Piper/Sources/Logic/ViewModels/MenuBarViewModel.swift b/Piper/Sources/Logic/ViewModels/MenuBarViewModel.swift new file mode 100644 index 0000000..cb04301 --- /dev/null +++ b/Piper/Sources/Logic/ViewModels/MenuBarViewModel.swift @@ -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 () { + + } + +} diff --git a/Piper/Sources/UI/Views/MenuBarView.swift b/Piper/Sources/UI/Views/MenuBarView.swift new file mode 100644 index 0000000..9040121 --- /dev/null +++ b/Piper/Sources/UI/Views/MenuBarView.swift @@ -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) +}