Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Searching #7

Merged
merged 8 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 63 additions & 26 deletions AllRecipesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,45 +10,82 @@ import Swinject

struct AllRecipesView: View {
@StateObject var viewModel: RecipesViewModel
@State private var searchText = ""

var body: some View {
recipesView()
recipesView()
.navigationTitle("allrecipes.title".localized)
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .topBarTrailing) {
Button("", systemImage: "slider.horizontal.2.square") {
viewModel.modalFiltersIsOpenFromAll = true
}
.sheet(isPresented: $viewModel.modalFiltersIsOpenFromAll) {
Assembler.sharedAssembly
.resolver
.resolve(FiltersView.self)
}
.tint(.orange)
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .topBarTrailing) {
Button("", systemImage: "slider.horizontal.2.square") {
viewModel.modalFiltersIsOpenFromAll = true
}
.sheet(isPresented: $viewModel.modalFiltersIsOpenFromAll) {
Assembler.sharedAssembly
.resolver
.resolve(FiltersView.self)
}
.tint(.orange)
}
.searchable(text: $searchText)
}
.searchable(text: $viewModel.searchQueryAll, isPresented: $viewModel.searchIsActiveAll)
.searchPresentationToolbarBehavior(.avoidHidingContent)
.onChange(of: viewModel.searchQueryAll, { _, _ in
viewModel.isLoadingAll = true
})
.onSubmit(of: .search) {
viewModel.findRecipesAll()
}
}

@ViewBuilder
func recipesView() -> some View {
if (!viewModel.allRecipes.isEmpty) {
GeometryReader {proxy in
ScrollView() {
LazyVStack(spacing: 12) {
ForEach(viewModel.allRecipes) { recipe in
RecipeBigCardView(recipe: recipe, proxy: proxy)
if (viewModel.isLoadingAll) {
ProgressView()
} else {
if (viewModel.searchQueryAll == "") {
if (!viewModel.allRecipes.isEmpty) {
GeometryReader {proxy in
ScrollView() {
LazyVStack(spacing: 12) {
ForEach(viewModel.allRecipes) { recipe in
RecipeBigCardView(recipe: recipe, proxy: proxy)
}
}
.scrollTargetLayout()
}
.scrollPosition(id: $viewModel.scrollID)
.onChange(of: viewModel.scrollID) { oldValue, newValue in
viewModel.loadMoreAllRecipes()
}
.scrollIndicators(.hidden)
.contentMargins(.horizontal, 12, for: .scrollContent)
.contentMargins(.bottom, 12, for: .scrollContent)
}
}
else {
Text("allrecipes.error.message".localized)
}
}
else {
if (!viewModel.foundRecipes.isEmpty) {
GeometryReader {proxy in
ScrollView() {
LazyVStack(spacing: 12) {
ForEach(viewModel.foundRecipes, id: \.self) { recipe in
RecipeBigCardView(recipe: recipe, proxy: proxy)
}
}
}
.onAppear(){print("all view")}
.scrollIndicators(.hidden)
.contentMargins(.horizontal, 12)
}
}
.scrollIndicators(.hidden)
.contentMargins(.horizontal, 12)
else {
Text("allrecipes.errorFound.message".localized)
}
}
}
else {
Text("allrecipes.error.message".localized)
}
}
}
4 changes: 4 additions & 0 deletions LiveRecipes.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
66266C6F2BD40C3900DE08E6 /* DietCellView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66266C6E2BD40C3900DE08E6 /* DietCellView.swift */; };
66422F282BCE89C300DD5E56 /* RecipeBigCardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66422F272BCE89C300DD5E56 /* RecipeBigCardView.swift */; };
669EE86D2BBAB76A009B1AB5 /* KeyWordsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 669EE86C2BBAB76A009B1AB5 /* KeyWordsView.swift */; };
66A5FBAE2BEF5A5F00730AA4 /* CardToTimeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66A5FBAD2BEF5A5F00730AA4 /* CardToTimeView.swift */; };
66B585ED2BB86C6000FEF708 /* RecentRecipesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66B585EC2BB86C6000FEF708 /* RecentRecipesView.swift */; };
66B585EF2BB87C9500FEF708 /* AllRecipesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66B585EE2BB87C9500FEF708 /* AllRecipesView.swift */; };
66B585F12BB87E4200FEF708 /* MyRecipesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66B585F02BB87E4200FEF708 /* MyRecipesView.swift */; };
Expand Down Expand Up @@ -164,6 +165,7 @@
66266C6E2BD40C3900DE08E6 /* DietCellView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DietCellView.swift; sourceTree = "<group>"; };
66422F272BCE89C300DD5E56 /* RecipeBigCardView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecipeBigCardView.swift; sourceTree = "<group>"; };
669EE86C2BBAB76A009B1AB5 /* KeyWordsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyWordsView.swift; sourceTree = "<group>"; };
66A5FBAD2BEF5A5F00730AA4 /* CardToTimeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardToTimeView.swift; sourceTree = "<group>"; };
66B585EC2BB86C6000FEF708 /* RecentRecipesView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecentRecipesView.swift; sourceTree = SOURCE_ROOT; };
66B585EE2BB87C9500FEF708 /* AllRecipesView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AllRecipesView.swift; sourceTree = SOURCE_ROOT; };
66B585F02BB87E4200FEF708 /* MyRecipesView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyRecipesView.swift; sourceTree = SOURCE_ROOT; };
Expand Down Expand Up @@ -569,6 +571,7 @@
C0EA6C892BB85AEC00995C49 /* RecipeCardView.swift */,
66422F272BCE89C300DD5E56 /* RecipeBigCardView.swift */,
66266C6E2BD40C3900DE08E6 /* DietCellView.swift */,
66A5FBAD2BEF5A5F00730AA4 /* CardToTimeView.swift */,
);
path = Components;
sourceTree = "<group>";
Expand Down Expand Up @@ -887,6 +890,7 @@
745DA4D12BB862B300BE4C5D /* OneDishView.swift in Sources */,
C0EA6C9E2BB85AED00995C49 /* ViewStateProtocol.swift in Sources */,
D02D7EEC2BCD79760056DC33 /* CreationPhotoFileProtocol.swift in Sources */,
66A5FBAE2BEF5A5F00730AA4 /* CardToTimeView.swift in Sources */,
C0EA6CBA2BB85AED00995C49 /* RecipesProtocols.swift in Sources */,
C0EA6CB12BB85AED00995C49 /* CreationProtocols.swift in Sources */,
D0FA9E132BCFF2DE0010F42B /* ListRecipeItemEntity+CoreDataClass.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
<key>orderHint</key>
<integer>1</integer>
</dict>
<key>TimerActivityWidgetExtension.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
</dict>
</dict>
</dict>
</plist>
43 changes: 17 additions & 26 deletions LiveRecipes/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,6 @@
}
}
}
},
"12г" : {

},
"15г" : {

},
"132кКал" : {

},
"allrecipes.error.message" : {
"extractionState" : "manual",
Expand All @@ -68,23 +59,6 @@
}
}
},
"creation.button.minutes" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "min"
}
},
"ru" : {
"stringUnit" : {
"state" : "translated",
"value" : "мин."
}
}
}
},
"cookingPrepare.days" : {
"extractionState" : "manual",
"localizations" : {
Expand Down Expand Up @@ -204,6 +178,23 @@
}
}
},
"creation.button.minutes" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "min"
}
},
"ru" : {
"stringUnit" : {
"state" : "translated",
"value" : "мин."
}
}
}
},
"creation.button.saveTime" : {
"extractionState" : "manual",
"localizations" : {
Expand Down
26 changes: 13 additions & 13 deletions LiveRecipes/Modules/Favorites/FavoritesModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@
import Foundation

final class FavoritesModel: ObservableObject, FavoritesModelProtocol {
func loadMyRecipes() -> [Recipe] {
func loadMyRecipes() -> [RecipePreviewDTO] {
return [
Recipe(name: "Цезарь с креветками", time: "20-30", cathegory: "Салаты", image: "caesar"),
Recipe(name: "Цезарь с креветками", time: "20-30", cathegory: "Салаты", isInFavorites: true, image: "caesar"),
// RecipeDTO(name: "Цезарь с креветками", time: "20-30", cathegory: "Салаты", image: "caesar"),
// RecipeDTO(name: "Цезарь с креветками", time: "20-30", cathegory: "Салаты", isInFavorites: true, image: "caesar"),
]
}


func loadAllRecipes() -> [Recipe] {
func loadAllRecipes() -> [RecipePreviewDTO] {
return [
Recipe(name: "Цезарь с креветками", time: "20-30", cathegory: "Салаты", image: "caesar"),
Recipe(name: "Цезарь с креветками", time: "20-30", cathegory: "Салаты", isInFavorites: true, image: "caesar"),
Recipe(name: "Цезарь с креветками", time: "20-30", cathegory: "Салаты", image: "caesar"),
Recipe(name: "Цезарь с креветками", time: "20-30", cathegory: "Салаты", image: "caesar"),
Recipe(name: "Цезарь с креветками", time: "20-30", cathegory: "Салаты", isInFavorites: true, image: "caesar"),
Recipe(name: "Цезарь с креветками", time: "20-30", cathegory: "Салаты", image: "caesar"),
Recipe(name: "Цезарь с креветками", time: "20-30", cathegory: "Салаты", image: "caesar"),
Recipe(name: "Цезарь с креветками", time: "20-30", cathegory: "Салаты", isInFavorites: true, image: "caesar"),
Recipe(name: "Цезарь с креветками", time: "20-30", cathegory: "Салаты", image: "caesar")
// RecipeDTO(name: "Цезарь с креветками", time: "20-30", cathegory: "Салаты", image: "caesar"),
// RecipeDTO(name: "Цезарь с креветками", time: "20-30", cathegory: "Салаты", isInFavorites: true, image: "caesar"),
// RecipeDTO(name: "Цезарь с креветками", time: "20-30", cathegory: "Салаты", image: "caesar"),
// RecipeDTO(name: "Цезарь с креветками", time: "20-30", cathegory: "Салаты", image: "caesar"),
// RecipeDTO(name: "Цезарь с креветками", time: "20-30", cathegory: "Салаты", isInFavorites: true, image: "caesar"),
// RecipeDTO(name: "Цезарь с креветками", time: "20-30", cathegory: "Салаты", image: "caesar"),
// RecipeDTO(name: "Цезарь с креветками", time: "20-30", cathegory: "Салаты", image: "caesar"),
// RecipeDTO(name: "Цезарь с креветками", time: "20-30", cathegory: "Салаты", isInFavorites: true, image: "caesar"),
// RecipeDTO(name: "Цезарь с креветками", time: "20-30", cathegory: "Салаты", image: "caesar")
]
}
}
4 changes: 2 additions & 2 deletions LiveRecipes/Modules/Favorites/FavoritesProtocols.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ protocol FavoritesViewModelProtocol {
}

protocol FavoritesModelProtocol {
func loadAllRecipes() -> [Recipe]
func loadMyRecipes() -> [Recipe]
func loadAllRecipes() -> [RecipePreviewDTO]
func loadMyRecipes() -> [RecipePreviewDTO]
}

protocol FavoritesViewProtocol {}
4 changes: 2 additions & 2 deletions LiveRecipes/Modules/Favorites/FavoritesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ struct FavoritesView: View {
GeometryReader {proxy in
ScrollView() {
LazyVStack(spacing: 12) {
ForEach(viewState.allRecipes) { recipe in
ForEach(viewState.allRecipes, id: \.self) { recipe in
RecipeBigCardView(recipe: recipe, proxy: proxy)
}
}
Expand Down Expand Up @@ -124,7 +124,7 @@ struct FavoritesView: View {
GeometryReader {proxy in
ScrollView() {
LazyVStack(spacing: 12) {
ForEach(viewState.myRecipes) { recipe in
ForEach(viewState.myRecipes, id: \.self) { recipe in
withAnimation(.easeInOut) {
RecipeBigCardView(recipe: recipe, proxy: proxy)
}
Expand Down
6 changes: 3 additions & 3 deletions LiveRecipes/Modules/Favorites/FavoritesViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ final class FavoritesViewModel: ObservableObject, FavoritesViewModelProtocol {
var model: FavoritesModelProtocol

@Published var modalFiltersIsOpen: Bool = false
@Published var allRecipes: [Recipe] = []
@Published var myRecipes: [Recipe] = []
@Published var allRecipes: [RecipePreviewDTO] = []
@Published var myRecipes: [RecipePreviewDTO] = []
init(favoritesModel: FavoritesModel) {
self.model = favoritesModel
loadAllData()
Expand All @@ -25,6 +25,6 @@ final class FavoritesViewModel: ObservableObject, FavoritesViewModelProtocol {
myRecipes = model.loadMyRecipes()
}
func findMore() {
myRecipes.append(Recipe(name: "Цезарь с креветками", time: "20-30", cathegory: "Салаты", image: "caesar"))
// myRecipes.append(RecipeDTO(name: "Цезарь с креветками", time: "20-30", cathegory: "Салаты", image: "caesar"))
}
}
41 changes: 41 additions & 0 deletions LiveRecipes/Modules/Recipes/Components/CardToTimeView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// CardToTimeView.swift
// LiveRecipes
//
// Created by Александр Денисов on 11.05.2024.
//

import SwiftUI
import Swinject

struct CardToTimeView: View {
@StateObject var viewModel: RecipesViewModel

let type: NameToTime
let proxy: GeometryProxy

var body: some View {

NavigationLink {
Assembler.sharedAssembly
.resolver
.resolve(CookToTimeView.self)
} label: {
VStack {
Image(type.image)
.resizable()
.scaledToFill()
.frame(width: 80, height: 80)
.clipShape(.rect(cornerRadius: 8))
.clipped()
Text(type.title)
.fontWeight(.bold)
.font(.caption)
}
}
.simultaneousGesture(TapGesture().onEnded{
viewModel.type = type
})
}
}

12 changes: 6 additions & 6 deletions LiveRecipes/Modules/Recipes/Components/RecipeBigCardView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import SwiftUI

struct RecipeBigCardView: View {
@State var recipe: Recipe
@State var recipe: RecipePreviewDTO
var proxy: GeometryProxy

var body: some View {
Expand All @@ -17,7 +17,7 @@ struct RecipeBigCardView: View {
}, label: {
ZStack(alignment: .topTrailing) {
VStack (spacing: 0) {
Image(recipe.image)
Image(uiImage: UIImage(data: Data(base64Encoded: recipe.photo)!)!)
.resizable()
.scaledToFill()
.frame(width: proxy.size.width - 24, height: 170)
Expand All @@ -31,7 +31,7 @@ struct RecipeBigCardView: View {
}
.padding(.horizontal, 8)
HStack {
Text(recipe.cathegory)
Text(recipe.tag)
.fontWeight(.light)
.foregroundStyle(Color(uiColor: .darkGray))
.font(.system(size: 14))
Expand All @@ -40,7 +40,7 @@ struct RecipeBigCardView: View {
.resizable()
.scaledToFit()
.frame(width: 13, height: 13)
Text(recipe.time + "recipes.card.time".localized)
Text(String(recipe.duration) + "recipes.card.time".localized)
.font(.system(size: 14))
}
.padding(.horizontal, 8)
Expand All @@ -53,9 +53,9 @@ struct RecipeBigCardView: View {
.clipShape(.rect(cornerRadius: 8))
.tint(.black)
VStack {
Image(systemName: recipe.isInFavorites ? "star.fill" : "star")
Image(systemName: recipe.isInFavorites ?? false ? "star.fill" : "star")
.resizable()
.foregroundStyle(Color.yellow)
.foregroundStyle(Color.orange)
.fontWeight(.medium)
.gesture(TapGesture().onEnded({ _ in
recipe.changeStateOfFavorites()
Expand Down
Loading
Loading