From e547aa21465198b526de5ed41090b8dc54242206 Mon Sep 17 00:00:00 2001 From: Vicnet <35202538+VincentMeilinger@users.noreply.github.com> Date: Fri, 6 Oct 2023 08:32:21 +0200 Subject: [PATCH] Added default category in settings --- .../Views/CategoryDetailView.swift | 2 +- .../Views/MainView.swift | 11 +++++++++++ .../Views/SettingsView.swift | 17 +++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/Nextcloud Cookbook iOS Client/Views/CategoryDetailView.swift b/Nextcloud Cookbook iOS Client/Views/CategoryDetailView.swift index da82228..71d77cc 100644 --- a/Nextcloud Cookbook iOS Client/Views/CategoryDetailView.swift +++ b/Nextcloud Cookbook iOS Client/Views/CategoryDetailView.swift @@ -31,7 +31,7 @@ struct CategoryDetailView: View { } .navigationTitle(categoryName == "*" ? "Other" : categoryName) .toolbar { - ToolbarItem(placement: .topBarLeading) { + ToolbarItem(placement: .topBarTrailing) { Menu { Button { print("Downloading all recipes in category \(categoryName) ...") diff --git a/Nextcloud Cookbook iOS Client/Views/MainView.swift b/Nextcloud Cookbook iOS Client/Views/MainView.swift index 626719f..e2e2a30 100644 --- a/Nextcloud Cookbook iOS Client/Views/MainView.swift +++ b/Nextcloud Cookbook iOS Client/Views/MainView.swift @@ -85,6 +85,17 @@ struct MainView: View { } .task { await viewModel.loadCategoryList() + if userSettings.defaultCategory != "" { + if let cat = viewModel.categories.first(where: { c in + if c.name == userSettings.defaultCategory { + return true + } + return false + }) { + self.selectedCategory = cat + } + } + } .refreshable { await viewModel.loadCategoryList(needsUpdate: true) diff --git a/Nextcloud Cookbook iOS Client/Views/SettingsView.swift b/Nextcloud Cookbook iOS Client/Views/SettingsView.swift index 1c28536..50b5fdd 100644 --- a/Nextcloud Cookbook iOS Client/Views/SettingsView.swift +++ b/Nextcloud Cookbook iOS Client/Views/SettingsView.swift @@ -39,6 +39,23 @@ struct SettingsView: View { var body: some View { Form { + Section { + Picker("Select a cookbook", selection: $userSettings.defaultCategory) { + Text("") + ForEach(viewModel.categories, id: \.name) { category in + Text(category.name == "*" ? "Other" : category.name) + } + } + Button { + userSettings.defaultCategory = "" + } label: { + Text("Clear default category") + } + } header: { + Text("Default cookbook") + } footer: { + Text("The selected cookbook will be opened on app launch by default.") + } Section() { Link("Visit the GitHub page", destination: URL(string: "https://github.com/VincentMeilinger/Nextcloud-Cookbook-iOS")!) } header: {