New app icon and recipe sharing options (pdf and plain text)

This commit is contained in:
VincentMeilinger
2024-01-10 17:52:34 +01:00
parent 3bcf104a5d
commit d180b96ed8
22 changed files with 288 additions and 7 deletions

View File

@@ -166,6 +166,7 @@ struct MainView: View {
Text("Refresh all")
Image(systemName: "icloud.and.arrow.down")
}
} label: {
Image(systemName: "ellipsis.circle")
}
@@ -235,7 +236,7 @@ struct RecipeSearchView: View {
.navigationDestination(for: Recipe.self) { recipe in
RecipeDetailView(viewModel: viewModel, recipe: recipe)
}
.searchable(text: $searchText, prompt: "Search recipes")
.searchable(text: $searchText, prompt: "Search recipes/keywords")
}
.navigationTitle("Search recipe")
}
@@ -247,7 +248,9 @@ struct RecipeSearchView: View {
func recipesFiltered() -> [Recipe] {
guard searchText != "" else { return allRecipes }
return allRecipes.filter { recipe in
recipe.name.lowercased().contains(searchText.lowercased())
recipe.name.lowercased().contains(searchText.lowercased()) || // check name for occurence of search term
(recipe.keywords != nil && recipe.keywords!.lowercased().contains(searchText.lowercased())) // check keywords for search term
}
}
}

View File

@@ -19,6 +19,8 @@ struct RecipeDetailView: View {
@State private var presentEditView: Bool = false
@State private var presentNutritionPopover: Bool = false
@State private var presentKeywordPopover: Bool = false
@State private var presentShareSheet: Bool = false
@State private var sharedURL: URL? = nil
var body: some View {
ScrollView(showsIndicators: false) {
@@ -76,6 +78,7 @@ struct RecipeDetailView: View {
RecipeKeywordSection(recipeDetail: recipeDetail)
MoreInformationSection(recipeDetail: recipeDetail)
}
}.padding(.horizontal, 5)
}
@@ -85,12 +88,25 @@ struct RecipeDetailView: View {
.navigationTitle(showTitle ? recipe.name : "")
.toolbar {
if recipeDetail != nil {
Button {
presentEditView = true
} label: {
HStack {
Text("Edit")
Menu {
Button {
presentEditView = true
} label: {
HStack {
Text("Edit")
Image(systemName: "pencil")
}
}
Button {
print("Sharing recipe ...")
self.presentShareSheet = true
} label: {
Text("Share recipe")
Image(systemName: "square.and.arrow.up")
}
} label: {
Image(systemName: "ellipsis.circle")
}
}
}
@@ -107,6 +123,14 @@ struct RecipeDetailView: View {
)
}
}
.sheet(isPresented: $presentShareSheet) {
if let recipeDetail = recipeDetail {
ShareView(recipeDetail: recipeDetail,
recipeImage: recipeImage,
presentShareSheet: $presentShareSheet)
}
}
.task {
recipeDetail = await viewModel.getRecipe(
id: recipe.recipe_id,
@@ -136,6 +160,50 @@ struct RecipeDetailView: View {
}
}
fileprivate struct ShareView: View {
@State var recipeDetail: RecipeDetail
@State var recipeImage: UIImage?
@Binding var presentShareSheet: Bool
@State var exporter = RecipeExporter()
@State var sharedURL: URL? = nil
var body: some View {
VStack(alignment: .leading) {
if let url = sharedURL {
ShareLink(item: url, subject: Text("PDF Document")) {
Image(systemName: "doc")
Text("Share as PDF")
}
.foregroundStyle(.primary)
.bold()
.padding()
}
ShareLink(item: exporter.createText(recipe: recipeDetail), subject: Text("Recipe")) {
Image(systemName: "ellipsis.message")
Text("Share as text")
}
.foregroundStyle(.primary)
.bold()
.padding()
/*ShareLink(item: exporter.createJson(recipe: recipeDetail), subject: Text("Recipe")) {
Image(systemName: "doc.badge.gearshape")
Text("Share as JSON")
}
.foregroundStyle(.primary)
.bold()
.padding()
*/
}
.task {
self.sharedURL = exporter.createPDF(recipe: recipeDetail, image: recipeImage)
}
}
}
fileprivate struct RecipeDurationSection: View {
@State var recipeDetail: RecipeDetail