From bf10a440159816a347491f0aefaea15c74fc0022 Mon Sep 17 00:00:00 2001 From: jim4020key Date: Sun, 25 Jun 2023 01:40:47 +0900 Subject: [PATCH 01/11] [Chore] #471 - Move ExploreShortcutView to the right folder --- .../HappyAnding.xcodeproj/project.pbxproj | 8 +- .../ExploreShortcutView.swift | 195 +++++++++++++++- .../ExploreShortcutView.swift | 208 ------------------ 3 files changed, 188 insertions(+), 223 deletions(-) delete mode 100644 HappyAnding/HappyAnding/Views/ExploreShortcutViews/ExploreShortcutView/ExploreShortcutView.swift diff --git a/HappyAnding/HappyAnding.xcodeproj/project.pbxproj b/HappyAnding/HappyAnding.xcodeproj/project.pbxproj index a2ec4dac..3cf164bb 100644 --- a/HappyAnding/HappyAnding.xcodeproj/project.pbxproj +++ b/HappyAnding/HappyAnding.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 4D061BB82A47531800F76835 /* ExploreShortcutView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D061BB72A47531800F76835 /* ExploreShortcutView.swift */; }; 4D3DBB88292E67E600DE8160 /* EditNicknameView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D3DBB87292E67E500DE8160 /* EditNicknameView.swift */; }; 4D3DBB962934E31A00DE8160 /* ShowProfileView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D3DBB952934E31A00DE8160 /* ShowProfileView.swift */; }; 4D61A767291E1EE8000EF531 /* NavigationViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D61A766291E1EE8000EF531 /* NavigationViewModel.swift */; }; @@ -55,7 +56,6 @@ 87E99CA128FFF225009B691F /* MyPageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87E99CA028FFF225009B691F /* MyPageView.swift */; }; 87E99CA328FFF22E009B691F /* ExploreCurationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87E99CA228FFF22E009B691F /* ExploreCurationView.swift */; }; 87E99CA728FFF23E009B691F /* ListCurationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87E99CA628FFF23E009B691F /* ListCurationView.swift */; }; - 87E99CA928FFF24F009B691F /* ExploreShortcutView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87E99CA828FFF24F009B691F /* ExploreShortcutView.swift */; }; 87E99CAD28FFF261009B691F /* ReadShortcutView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87E99CAC28FFF261009B691F /* ReadShortcutView.swift */; }; 87E99CB128FFF273009B691F /* WriteCurationSetView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87E99CB028FFF273009B691F /* WriteCurationSetView.swift */; }; 87E99CB528FFF282009B691F /* WriteCurationInfoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87E99CB428FFF282009B691F /* WriteCurationInfoView.swift */; }; @@ -186,6 +186,7 @@ /* Begin PBXFileReference section */ 3D41EE06290A458B008BE986 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = ""; }; 3D41EE07290A4C18008BE986 /* Launch Screen.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = "Launch Screen.storyboard"; sourceTree = ""; }; + 4D061BB72A47531800F76835 /* ExploreShortcutView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExploreShortcutView.swift; sourceTree = ""; }; 4D3DBB87292E67E500DE8160 /* EditNicknameView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EditNicknameView.swift; sourceTree = ""; }; 4D3DBB952934E31A00DE8160 /* ShowProfileView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShowProfileView.swift; sourceTree = ""; }; 4D61A766291E1EE8000EF531 /* NavigationViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationViewModel.swift; sourceTree = ""; }; @@ -233,7 +234,6 @@ 87E99CA028FFF225009B691F /* MyPageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyPageView.swift; sourceTree = ""; }; 87E99CA228FFF22E009B691F /* ExploreCurationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExploreCurationView.swift; sourceTree = ""; }; 87E99CA628FFF23E009B691F /* ListCurationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListCurationView.swift; sourceTree = ""; }; - 87E99CA828FFF24F009B691F /* ExploreShortcutView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = ExploreShortcutView.swift; path = ExploreShortcutView/ExploreShortcutView.swift; sourceTree = ""; }; 87E99CAC28FFF261009B691F /* ReadShortcutView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReadShortcutView.swift; sourceTree = ""; }; 87E99CB028FFF273009B691F /* WriteCurationSetView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WriteCurationSetView.swift; sourceTree = ""; }; 87E99CB428FFF282009B691F /* WriteCurationInfoView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WriteCurationInfoView.swift; sourceTree = ""; }; @@ -540,7 +540,7 @@ 87E99C9B28FFF1F4009B691F /* ExploreShortcutViews */ = { isa = PBXGroup; children = ( - 87E99CA828FFF24F009B691F /* ExploreShortcutView.swift */, + 4D061BB72A47531800F76835 /* ExploreShortcutView.swift */, 87E99CC8290145B8009B691F /* ListShortcutView.swift */, A0F822B629164D2300AF4448 /* ListCategoryShortcutView.swift */, ); @@ -945,7 +945,6 @@ 4DAD635E292AB61700ABF8C1 /* UpdateShortcutView.swift in Sources */, 87E99C9F28FFF21B009B691F /* SettingView.swift in Sources */, A34BF82829AF3D55009BC946 /* AnnouncementCell.swift in Sources */, - 87E99CA928FFF24F009B691F /* ExploreShortcutView.swift in Sources */, A04ACB082903DECC004A85A6 /* MyShortcutCardListView.swift in Sources */, 8786B2EC29A7FAD2000B46A1 /* UIColor+Extension.swift in Sources */, 87E99CA128FFF225009B691F /* MyPageView.swift in Sources */, @@ -960,6 +959,7 @@ A33F74AE2908D8C800B8D0D0 /* CheckBoxShortcutCell.swift in Sources */, 87E606B22910649B00C3DA13 /* SignInWithAppleView.swift in Sources */, F91F09DF29AE0B5E00E04FA0 /* GradeAlertView.swift in Sources */, + 4D061BB82A47531800F76835 /* ExploreShortcutView.swift in Sources */, 87E99CEC29080C30009B691F /* Curation.swift in Sources */, 8788E19D2A475AB3007C3852 /* ListCurationViewModel.swift in Sources */, F9136EB6293612310034AAB2 /* ShortcutsZipView.swift in Sources */, diff --git a/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ExploreShortcutView.swift b/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ExploreShortcutView.swift index 8a2fe41b..a5ff6dde 100644 --- a/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ExploreShortcutView.swift +++ b/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ExploreShortcutView.swift @@ -9,27 +9,200 @@ import SwiftUI struct ExploreShortcutView: View { - let firebase = FirebaseService() - @State var shortcutsArray: [Shortcuts] = [] + @EnvironmentObject var shortcutsZipViewModel: ShortcutsZipViewModel + + // TODO: 추후 UpdateInfoView 제작 시 true로 변경해서 cell 보이게 하기 + @AppStorage("isUpdateAnnnouncementShow") var isUpdateAnnnouncementShow: Bool = false + + @Binding var isCategoryCellViewFolded: Bool + + @State var isTappedAnnouncementCell = false + @State private var numberOfDisplayedCategories = 6 + + let randomCategories: [Category] var body: some View { - Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) - .onAppear { - firebase.fetchShortcut(model: "Shortcut") { shortcuts in - shortcutsArray = shortcuts + ScrollView { + VStack(spacing: 32) { + if isUpdateAnnnouncementShow { + Button { + isTappedAnnouncementCell = true + } label: { + AnnouncementCell(icon: "updateAppIcon", + tagName: TextLiteral.updateTag, + discription: TextLiteral.updateCellDescription, + isAnnouncementShow: $isUpdateAnnnouncementShow) + } + .id(000) } + + sectionView(with: .recent) + .id(111) + + categoryCardView(with: randomCategories[0]) + + sectionView(with: .download) + + categoryCardView(with: randomCategories[1]) + + sectionView(with: .popular) + + VStack { + HStack { + SubtitleTextView(text: TextLiteral.categoryViewTitle) + + Spacer() + + Button(action: { + self.isCategoryCellViewFolded.toggle() + }, label: { + MoreCaptionTextView(text: isCategoryCellViewFolded ? TextLiteral.categoryViewUnfold : TextLiteral.categoryViewFold) + }) + .onChange(of: isCategoryCellViewFolded) { _ in + numberOfDisplayedCategories = isCategoryCellViewFolded ? 6 : 12 + } + } + .padding(.horizontal, 16) + + LazyVGrid(columns: [GridItem(.flexible()), GridItem(.flexible())]) { + ForEach(Array(Category.allCases.enumerated()), id: \.offset) { index, value in + + let data = NavigationListCategoryShortcutType(shortcuts: [], + categoryName: value, + navigationParentView: .shortcuts) + + if index < numberOfDisplayedCategories { + + categoryCellView(with: value.translateName()) + .navigationLinkRouter(data: data) + + } + } + } + .padding(.horizontal, 16) + .padding(.bottom, 16) + .id(999) + } + } + .padding(.top, 20) + .padding(.bottom, 44) + } + .scrollIndicators(.hidden) + .navigationBarTitle(TextLiteral.exploreShortcutViewTitle) + .navigationBarTitleDisplayMode(.large) + .background(Color.shortcutsZipBackground) + .toolbar { + ToolbarItem { + Image(systemName: "magnifyingglass") + .shortcutsZipHeadline() + .foregroundColor(.gray5) + .navigationLinkRouter(data: NavigationSearch.first) } - .onTapGesture { - firebase.fetchCategoryLikedList(category: "education") { shortcuts in - shortcutsArray = shortcuts - print(shortcutsArray) + } + .navigationBarBackground ({ Color.shortcutsZipBackground }) + .sheet(isPresented: $isTappedAnnouncementCell) { + UpdateInfoView() + .presentationDetents([.large]) + .presentationDragIndicator(.visible) + } + } + +} + +// MARK: ViewBuilder +extension ExploreShortcutView { + + @ViewBuilder + private func sectionView(with sectionType: SectionType) -> some View { + + let shortcuts = sectionType.filterShortcuts(from: shortcutsZipViewModel) + + VStack(spacing: 0) { + HStack { + SubtitleTextView(text: sectionType.title) + + Spacer() + + MoreCaptionTextView(text: TextLiteral.more) + .navigationLinkRouter(data: NavigationListShortcutType(sectionType: sectionType, + shortcuts: shortcuts, + navigationParentView: .shortcuts)) + } + .padding(.horizontal, 16) + .padding(.bottom, 12) + + ForEach(Array(shortcuts.enumerated()), id:\.offset) { index, shortcut in + if index < 3 { + let data = NavigationReadShortcutType(shortcutID:shortcut.id, + navigationParentView: .shortcuts) + + ShortcutCell(shortcut: shortcut, + rankNumber: index + 1, + navigationParentView: .shortcuts) + .navigationLinkRouter(data: data) } } + .background(Color.shortcutsZipBackground) + } + } + + @ViewBuilder + private func categoryCardView(with category: Category) -> some View { + + VStack(spacing: 0) { + HStack { + + SubtitleTextView(text: category.translateName()) + + Spacer() + + MoreCaptionTextView(text: TextLiteral.more) + .navigationLinkRouter(data: NavigationListCategoryShortcutType(shortcuts: [], + categoryName: category, + navigationParentView: .shortcuts)) + } + .padding(.horizontal, 16) + .padding(.bottom, 12) + + ScrollView(.horizontal, showsIndicators: false) { + HStack { + ForEach(Array((shortcutsZipViewModel.shortcutsInCategory[randomCategories[0].index].enumerated())), id: \.offset) { index, shortcut in + if index < 7 { + let data = NavigationReadShortcutType( + shortcutID: shortcut.id, + navigationParentView: .shortcuts) + + ShortcutCardCell( + categoryShortcutIcon: shortcut.sfSymbol, + categoryShortcutName: shortcut.title, + categoryShortcutColor: shortcut.color) + .navigationLinkRouter(data: data) + } + } + } + .padding(.horizontal, 16) + } + } + } + + @ViewBuilder + private func categoryCellView(with categoryName: String) -> some View { + RoundedRectangle(cornerSize: CGSize(width: 12, height: 12)) + .strokeBorder(Color.gray1, lineWidth: 1) + .background(Color.shortcutsZipWhite) + .cornerRadius(12) + .frame(maxWidth: .infinity, minHeight:48, maxHeight: 48) + .overlay { + Text(categoryName) + .shortcutsZipBody2() + .foregroundColor(Color.gray5) + } } } struct ExploreShortcutView_Previews: PreviewProvider { static var previews: some View { - ExploreShortcutView() + ExploreShortcutView(isCategoryCellViewFolded: .constant(true), randomCategories: [Category.lifestyle, Category.utility]) } } + diff --git a/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ExploreShortcutView/ExploreShortcutView.swift b/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ExploreShortcutView/ExploreShortcutView.swift deleted file mode 100644 index a5ff6dde..00000000 --- a/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ExploreShortcutView/ExploreShortcutView.swift +++ /dev/null @@ -1,208 +0,0 @@ -// -// ExploreShortcutView.swift -// HappyAnding -// -// Created by 이지원 on 2022/10/19. -// - -import SwiftUI - -struct ExploreShortcutView: View { - - @EnvironmentObject var shortcutsZipViewModel: ShortcutsZipViewModel - - // TODO: 추후 UpdateInfoView 제작 시 true로 변경해서 cell 보이게 하기 - @AppStorage("isUpdateAnnnouncementShow") var isUpdateAnnnouncementShow: Bool = false - - @Binding var isCategoryCellViewFolded: Bool - - @State var isTappedAnnouncementCell = false - @State private var numberOfDisplayedCategories = 6 - - let randomCategories: [Category] - - var body: some View { - ScrollView { - VStack(spacing: 32) { - if isUpdateAnnnouncementShow { - Button { - isTappedAnnouncementCell = true - } label: { - AnnouncementCell(icon: "updateAppIcon", - tagName: TextLiteral.updateTag, - discription: TextLiteral.updateCellDescription, - isAnnouncementShow: $isUpdateAnnnouncementShow) - } - .id(000) - } - - sectionView(with: .recent) - .id(111) - - categoryCardView(with: randomCategories[0]) - - sectionView(with: .download) - - categoryCardView(with: randomCategories[1]) - - sectionView(with: .popular) - - VStack { - HStack { - SubtitleTextView(text: TextLiteral.categoryViewTitle) - - Spacer() - - Button(action: { - self.isCategoryCellViewFolded.toggle() - }, label: { - MoreCaptionTextView(text: isCategoryCellViewFolded ? TextLiteral.categoryViewUnfold : TextLiteral.categoryViewFold) - }) - .onChange(of: isCategoryCellViewFolded) { _ in - numberOfDisplayedCategories = isCategoryCellViewFolded ? 6 : 12 - } - } - .padding(.horizontal, 16) - - LazyVGrid(columns: [GridItem(.flexible()), GridItem(.flexible())]) { - ForEach(Array(Category.allCases.enumerated()), id: \.offset) { index, value in - - let data = NavigationListCategoryShortcutType(shortcuts: [], - categoryName: value, - navigationParentView: .shortcuts) - - if index < numberOfDisplayedCategories { - - categoryCellView(with: value.translateName()) - .navigationLinkRouter(data: data) - - } - } - } - .padding(.horizontal, 16) - .padding(.bottom, 16) - .id(999) - } - } - .padding(.top, 20) - .padding(.bottom, 44) - } - .scrollIndicators(.hidden) - .navigationBarTitle(TextLiteral.exploreShortcutViewTitle) - .navigationBarTitleDisplayMode(.large) - .background(Color.shortcutsZipBackground) - .toolbar { - ToolbarItem { - Image(systemName: "magnifyingglass") - .shortcutsZipHeadline() - .foregroundColor(.gray5) - .navigationLinkRouter(data: NavigationSearch.first) - } - } - .navigationBarBackground ({ Color.shortcutsZipBackground }) - .sheet(isPresented: $isTappedAnnouncementCell) { - UpdateInfoView() - .presentationDetents([.large]) - .presentationDragIndicator(.visible) - } - } - -} - -// MARK: ViewBuilder -extension ExploreShortcutView { - - @ViewBuilder - private func sectionView(with sectionType: SectionType) -> some View { - - let shortcuts = sectionType.filterShortcuts(from: shortcutsZipViewModel) - - VStack(spacing: 0) { - HStack { - SubtitleTextView(text: sectionType.title) - - Spacer() - - MoreCaptionTextView(text: TextLiteral.more) - .navigationLinkRouter(data: NavigationListShortcutType(sectionType: sectionType, - shortcuts: shortcuts, - navigationParentView: .shortcuts)) - } - .padding(.horizontal, 16) - .padding(.bottom, 12) - - ForEach(Array(shortcuts.enumerated()), id:\.offset) { index, shortcut in - if index < 3 { - let data = NavigationReadShortcutType(shortcutID:shortcut.id, - navigationParentView: .shortcuts) - - ShortcutCell(shortcut: shortcut, - rankNumber: index + 1, - navigationParentView: .shortcuts) - .navigationLinkRouter(data: data) - } - } - .background(Color.shortcutsZipBackground) - } - } - - @ViewBuilder - private func categoryCardView(with category: Category) -> some View { - - VStack(spacing: 0) { - HStack { - - SubtitleTextView(text: category.translateName()) - - Spacer() - - MoreCaptionTextView(text: TextLiteral.more) - .navigationLinkRouter(data: NavigationListCategoryShortcutType(shortcuts: [], - categoryName: category, - navigationParentView: .shortcuts)) - } - .padding(.horizontal, 16) - .padding(.bottom, 12) - - ScrollView(.horizontal, showsIndicators: false) { - HStack { - ForEach(Array((shortcutsZipViewModel.shortcutsInCategory[randomCategories[0].index].enumerated())), id: \.offset) { index, shortcut in - if index < 7 { - let data = NavigationReadShortcutType( - shortcutID: shortcut.id, - navigationParentView: .shortcuts) - - ShortcutCardCell( - categoryShortcutIcon: shortcut.sfSymbol, - categoryShortcutName: shortcut.title, - categoryShortcutColor: shortcut.color) - .navigationLinkRouter(data: data) - } - } - } - .padding(.horizontal, 16) - } - } - } - - @ViewBuilder - private func categoryCellView(with categoryName: String) -> some View { - RoundedRectangle(cornerSize: CGSize(width: 12, height: 12)) - .strokeBorder(Color.gray1, lineWidth: 1) - .background(Color.shortcutsZipWhite) - .cornerRadius(12) - .frame(maxWidth: .infinity, minHeight:48, maxHeight: 48) - .overlay { - Text(categoryName) - .shortcutsZipBody2() - .foregroundColor(Color.gray5) - } - } -} - -struct ExploreShortcutView_Previews: PreviewProvider { - static var previews: some View { - ExploreShortcutView(isCategoryCellViewFolded: .constant(true), randomCategories: [Category.lifestyle, Category.utility]) - } -} - From f716f83a83214e92dfbeccc9df168bd045bcc6a0 Mon Sep 17 00:00:00 2001 From: jim4020key Date: Fri, 30 Jun 2023 17:40:03 +0900 Subject: [PATCH 02/11] [Feat] #471 - Add ExploreShortcutViewModel --- .../HappyAnding.xcodeproj/project.pbxproj | 4 + .../ViewModel/ExploreShortcutViewModel.swift | 31 ++++ .../ExploreShortcutView.swift | 157 ++++++++---------- .../Views/TabView/ShortcutTabView.swift | 9 +- 4 files changed, 109 insertions(+), 92 deletions(-) create mode 100644 HappyAnding/HappyAnding/ViewModel/ExploreShortcutViewModel.swift diff --git a/HappyAnding/HappyAnding.xcodeproj/project.pbxproj b/HappyAnding/HappyAnding.xcodeproj/project.pbxproj index 3cf164bb..ba2c1e4b 100644 --- a/HappyAnding/HappyAnding.xcodeproj/project.pbxproj +++ b/HappyAnding/HappyAnding.xcodeproj/project.pbxproj @@ -8,6 +8,7 @@ /* Begin PBXBuildFile section */ 4D061BB82A47531800F76835 /* ExploreShortcutView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D061BB72A47531800F76835 /* ExploreShortcutView.swift */; }; + 4D061BBA2A475EE800F76835 /* ExploreShortcutViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D061BB92A475EE800F76835 /* ExploreShortcutViewModel.swift */; }; 4D3DBB88292E67E600DE8160 /* EditNicknameView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D3DBB87292E67E500DE8160 /* EditNicknameView.swift */; }; 4D3DBB962934E31A00DE8160 /* ShowProfileView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D3DBB952934E31A00DE8160 /* ShowProfileView.swift */; }; 4D61A767291E1EE8000EF531 /* NavigationViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D61A766291E1EE8000EF531 /* NavigationViewModel.swift */; }; @@ -187,6 +188,7 @@ 3D41EE06290A458B008BE986 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = ""; }; 3D41EE07290A4C18008BE986 /* Launch Screen.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = "Launch Screen.storyboard"; sourceTree = ""; }; 4D061BB72A47531800F76835 /* ExploreShortcutView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExploreShortcutView.swift; sourceTree = ""; }; + 4D061BB92A475EE800F76835 /* ExploreShortcutViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExploreShortcutViewModel.swift; sourceTree = ""; }; 4D3DBB87292E67E500DE8160 /* EditNicknameView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EditNicknameView.swift; sourceTree = ""; }; 4D3DBB952934E31A00DE8160 /* ShowProfileView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShowProfileView.swift; sourceTree = ""; }; 4D61A766291E1EE8000EF531 /* NavigationViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationViewModel.swift; sourceTree = ""; }; @@ -653,6 +655,7 @@ A0F822AB2910B8F100AF4448 /* ShortcutsZipViewModel.swift */, 4D61A766291E1EE8000EF531 /* NavigationViewModel.swift */, F9AC2BB52935201C00165820 /* CheckUpdateVersion.swift */, + 4D061BB92A475EE800F76835 /* ExploreShortcutViewModel.swift */, ); path = ViewModel; sourceTree = ""; @@ -909,6 +912,7 @@ F9131B6B2922D38D00868A0E /* Keyword.swift in Sources */, F94B432E2907088400987819 /* UserCurationListView.swift in Sources */, A3FF0183291648A300384211 /* MailView.swift in Sources */, + 4D061BBA2A475EE800F76835 /* ExploreShortcutViewModel.swift in Sources */, A0F822AC2910B8F100AF4448 /* ShortcutsZipViewModel.swift in Sources */, 87276C382933F6AB00C92F4C /* CustomTextEditor.swift in Sources */, A34BF82D29AFC34F009BC946 /* AboutShortcutGradeView.swift in Sources */, diff --git a/HappyAnding/HappyAnding/ViewModel/ExploreShortcutViewModel.swift b/HappyAnding/HappyAnding/ViewModel/ExploreShortcutViewModel.swift new file mode 100644 index 00000000..8ae69669 --- /dev/null +++ b/HappyAnding/HappyAnding/ViewModel/ExploreShortcutViewModel.swift @@ -0,0 +1,31 @@ +// +// ExploreShortcutViewModel.swift +// HappyAnding +// +// Created by kimjimin on 2023/06/25. +// + +import SwiftUI + +final class ExploreShortcutViewModel: ObservableObject { + + var shortcutsZipViewModel = ShortcutsZipViewModel.share + + @Published private(set) var isCategoryCellViewFolded = true + @Published var isTappedAnnouncementCell = false + @Published private(set) var numberOfDisplayedCategories = 6 + @Published private(set) var randomCategories = Category.allCases.shuffled().prefix(2) + + func changeNumberOfCategories() { + isCategoryCellViewFolded.toggle() + numberOfDisplayedCategories = isCategoryCellViewFolded ? 6 : 12 + } + + func isShowingAnnouncement() { + isTappedAnnouncementCell = true + } + + func fetchShortcutsByCategories(category: Category) -> [Shortcuts] { + shortcutsZipViewModel.shortcutsInCategory[category.index] + } +} diff --git a/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ExploreShortcutView.swift b/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ExploreShortcutView.swift index a5ff6dde..fa2d353b 100644 --- a/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ExploreShortcutView.swift +++ b/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ExploreShortcutView.swift @@ -9,83 +9,80 @@ import SwiftUI struct ExploreShortcutView: View { - @EnvironmentObject var shortcutsZipViewModel: ShortcutsZipViewModel + @StateObject var viewModel: ExploreShortcutViewModel // TODO: 추후 UpdateInfoView 제작 시 true로 변경해서 cell 보이게 하기 @AppStorage("isUpdateAnnnouncementShow") var isUpdateAnnnouncementShow: Bool = false - @Binding var isCategoryCellViewFolded: Bool - - @State var isTappedAnnouncementCell = false - @State private var numberOfDisplayedCategories = 6 - - let randomCategories: [Category] - var body: some View { - ScrollView { - VStack(spacing: 32) { - if isUpdateAnnnouncementShow { - Button { - isTappedAnnouncementCell = true - } label: { - AnnouncementCell(icon: "updateAppIcon", - tagName: TextLiteral.updateTag, - discription: TextLiteral.updateCellDescription, - isAnnouncementShow: $isUpdateAnnnouncementShow) - } - .id(000) - } - - sectionView(with: .recent) - .id(111) - - categoryCardView(with: randomCategories[0]) - - sectionView(with: .download) - - categoryCardView(with: randomCategories[1]) - - sectionView(with: .popular) - - VStack { - HStack { - SubtitleTextView(text: TextLiteral.categoryViewTitle) - - Spacer() - - Button(action: { - self.isCategoryCellViewFolded.toggle() - }, label: { - MoreCaptionTextView(text: isCategoryCellViewFolded ? TextLiteral.categoryViewUnfold : TextLiteral.categoryViewFold) - }) - .onChange(of: isCategoryCellViewFolded) { _ in - numberOfDisplayedCategories = isCategoryCellViewFolded ? 6 : 12 + ScrollViewReader { proxy in + ScrollView { + VStack(spacing: 32) { + if isUpdateAnnnouncementShow { + Button { + viewModel.isShowingAnnouncement() + } label: { + AnnouncementCell(icon: "updateAppIcon", + tagName: TextLiteral.updateTag, + discription: TextLiteral.updateCellDescription, + isAnnouncementShow: $isUpdateAnnnouncementShow) } + .id(000) } - .padding(.horizontal, 16) - LazyVGrid(columns: [GridItem(.flexible()), GridItem(.flexible())]) { - ForEach(Array(Category.allCases.enumerated()), id: \.offset) { index, value in + sectionView(with: .recent) + .id(111) + + categoryCardView(with: viewModel.randomCategories[0]) + + sectionView(with: .download) + + categoryCardView(with: viewModel.randomCategories[1]) + + sectionView(with: .popular) + + VStack { + HStack { + SubtitleTextView(text: TextLiteral.categoryViewTitle) - let data = NavigationListCategoryShortcutType(shortcuts: [], - categoryName: value, - navigationParentView: .shortcuts) + Spacer() - if index < numberOfDisplayedCategories { + Button { + viewModel.changeNumberOfCategories() + } label: { + MoreCaptionTextView(text: viewModel.isCategoryCellViewFolded ? TextLiteral.categoryViewUnfold : TextLiteral.categoryViewFold) + } + } + .padding(.horizontal, 16) + + LazyVGrid(columns: [GridItem(.flexible()), GridItem(.flexible())]) { + ForEach(Array(Category.allCases.enumerated()), id: \.offset) { index, value in - categoryCellView(with: value.translateName()) - .navigationLinkRouter(data: data) + let data = NavigationListCategoryShortcutType(shortcuts: [], + categoryName: value, + navigationParentView: .shortcuts) + if index < viewModel.numberOfDisplayedCategories { + + categoryCellView(with: value.translateName()) + .navigationLinkRouter(data: data) + + } } } + .padding(.horizontal, 16) + .padding(.bottom, 16) + .id(999) } - .padding(.horizontal, 16) - .padding(.bottom, 16) - .id(999) + } + .padding(.top, 20) + .padding(.bottom, 44) + } + .onChange(of: viewModel.isCategoryCellViewFolded) { _ in + withAnimation { + proxy.scrollTo(999, anchor: .bottom) } } - .padding(.top, 20) - .padding(.bottom, 44) } .scrollIndicators(.hidden) .navigationBarTitle(TextLiteral.exploreShortcutViewTitle) @@ -100,7 +97,7 @@ struct ExploreShortcutView: View { } } .navigationBarBackground ({ Color.shortcutsZipBackground }) - .sheet(isPresented: $isTappedAnnouncementCell) { + .sheet(isPresented: $viewModel.isTappedAnnouncementCell) { UpdateInfoView() .presentationDetents([.large]) .presentationDragIndicator(.visible) @@ -115,7 +112,7 @@ extension ExploreShortcutView { @ViewBuilder private func sectionView(with sectionType: SectionType) -> some View { - let shortcuts = sectionType.filterShortcuts(from: shortcutsZipViewModel) + let shortcuts = sectionType.filterShortcuts(from: viewModel.shortcutsZipViewModel) VStack(spacing: 0) { HStack { @@ -151,11 +148,11 @@ extension ExploreShortcutView { VStack(spacing: 0) { HStack { - + SubtitleTextView(text: category.translateName()) - + Spacer() - + MoreCaptionTextView(text: TextLiteral.more) .navigationLinkRouter(data: NavigationListCategoryShortcutType(shortcuts: [], categoryName: category, @@ -163,21 +160,19 @@ extension ExploreShortcutView { } .padding(.horizontal, 16) .padding(.bottom, 12) - + ScrollView(.horizontal, showsIndicators: false) { HStack { - ForEach(Array((shortcutsZipViewModel.shortcutsInCategory[randomCategories[0].index].enumerated())), id: \.offset) { index, shortcut in - if index < 7 { - let data = NavigationReadShortcutType( - shortcutID: shortcut.id, - navigationParentView: .shortcuts) - - ShortcutCardCell( - categoryShortcutIcon: shortcut.sfSymbol, - categoryShortcutName: shortcut.title, - categoryShortcutColor: shortcut.color) - .navigationLinkRouter(data: data) - } + ForEach(viewModel.fetchShortcutsByCategories(category: category).prefix(7), id: \.self) { shortcut in + let data = NavigationReadShortcutType( + shortcutID: shortcut.id, + navigationParentView: .shortcuts) + + ShortcutCardCell( + categoryShortcutIcon: shortcut.sfSymbol, + categoryShortcutName: shortcut.title, + categoryShortcutColor: shortcut.color) + .navigationLinkRouter(data: data) } } .padding(.horizontal, 16) @@ -200,9 +195,3 @@ extension ExploreShortcutView { } } -struct ExploreShortcutView_Previews: PreviewProvider { - static var previews: some View { - ExploreShortcutView(isCategoryCellViewFolded: .constant(true), randomCategories: [Category.lifestyle, Category.utility]) - } -} - diff --git a/HappyAnding/HappyAnding/Views/TabView/ShortcutTabView.swift b/HappyAnding/HappyAnding/Views/TabView/ShortcutTabView.swift index db91ece5..4b17c112 100644 --- a/HappyAnding/HappyAnding/Views/TabView/ShortcutTabView.swift +++ b/HappyAnding/HappyAnding/Views/TabView/ShortcutTabView.swift @@ -27,8 +27,6 @@ struct ShortcutTabView: View { @State private var tempShortcutId = "" @State private var tempCurationId = "" - @State private var randomCategories = Category.allCases.shuffled().prefix(2) - @State var isFolded = true @State private var twiceTappedTab = 0 @State private var firstTabID = UUID() @@ -72,11 +70,6 @@ struct ShortcutTabView: View { } self.twiceTappedTab = 0 } - .onChange(of: isFolded) { _ in - withAnimation { - proxy.scrollTo(999, anchor: .bottom) - } - } .environmentObject(shortcutNavigation) .tabItem { Label("단축어", systemImage: "square.stack.3d.up.fill") @@ -113,7 +106,7 @@ struct ShortcutTabView: View { @ViewBuilder private func firstTab() -> some View { - ExploreShortcutView(isCategoryCellViewFolded: $isFolded, randomCategories: Array(randomCategories)) + ExploreShortcutView(viewModel: ExploreShortcutViewModel()) .modifierNavigation() .navigationBarBackground ({ Color.shortcutsZipBackground }) .id(firstTabID) From 2a5c32a995ffa9b5cf9e03e29a4bf9b61debc9f3 Mon Sep 17 00:00:00 2001 From: jim4020key Date: Fri, 30 Jun 2023 17:46:15 +0900 Subject: [PATCH 03/11] [Feat] #471 - Add ListShortcutViewModel --- .../HappyAnding.xcodeproj/project.pbxproj | 4 + .../Extensions/View/View+Navigation.swift | 4 +- .../ViewModel/ListShortcutViewModel.swift | 33 ++++++++ .../ListShortcutView.swift | 83 ++++++++----------- 4 files changed, 72 insertions(+), 52 deletions(-) create mode 100644 HappyAnding/HappyAnding/ViewModel/ListShortcutViewModel.swift diff --git a/HappyAnding/HappyAnding.xcodeproj/project.pbxproj b/HappyAnding/HappyAnding.xcodeproj/project.pbxproj index ba2c1e4b..9c23fb66 100644 --- a/HappyAnding/HappyAnding.xcodeproj/project.pbxproj +++ b/HappyAnding/HappyAnding.xcodeproj/project.pbxproj @@ -18,6 +18,7 @@ 4D7D16072986BBD7008B3332 /* TextLiteral.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D7D16062986BBD7008B3332 /* TextLiteral.swift */; }; 4D7D16082986BBDE008B3332 /* TextLiteral.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D7D16062986BBD7008B3332 /* TextLiteral.swift */; }; 4DAD635E292AB61700ABF8C1 /* UpdateShortcutView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DAD635D292AB61700ABF8C1 /* UpdateShortcutView.swift */; }; + 4DF15D732A4ECC7D0014F854 /* ListShortcutViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DF15D722A4ECC7D0014F854 /* ListShortcutViewModel.swift */; }; 4DF62DD52A0550ED00A8B377 /* UIScreen+Size.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8795A16F292AB945004B765F /* UIScreen+Size.swift */; }; 87276C382933F6AB00C92F4C /* CustomTextEditor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87276C372933F6AB00C92F4C /* CustomTextEditor.swift */; }; 872A7D8F2918393B004A05B8 /* PrivacyPolicyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 872A7D8E2918393B004A05B8 /* PrivacyPolicyView.swift */; }; @@ -196,6 +197,7 @@ 4D778A33290A53BA00C15AC4 /* UIApplication+Keyboard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIApplication+Keyboard.swift"; sourceTree = ""; }; 4D7D16062986BBD7008B3332 /* TextLiteral.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = TextLiteral.swift; path = HappyAnding/TextLiteral.swift; sourceTree = SOURCE_ROOT; }; 4DAD635D292AB61700ABF8C1 /* UpdateShortcutView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UpdateShortcutView.swift; sourceTree = ""; }; + 4DF15D722A4ECC7D0014F854 /* ListShortcutViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListShortcutViewModel.swift; sourceTree = ""; }; 87276C372933F6AB00C92F4C /* CustomTextEditor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomTextEditor.swift; sourceTree = ""; }; 872A7D8E2918393B004A05B8 /* PrivacyPolicyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrivacyPolicyView.swift; sourceTree = ""; }; 872B5D3C2A2E0FF9008DCC57 /* CurationType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CurationType.swift; sourceTree = ""; }; @@ -656,6 +658,7 @@ 4D61A766291E1EE8000EF531 /* NavigationViewModel.swift */, F9AC2BB52935201C00165820 /* CheckUpdateVersion.swift */, 4D061BB92A475EE800F76835 /* ExploreShortcutViewModel.swift */, + 4DF15D722A4ECC7D0014F854 /* ListShortcutViewModel.swift */, ); path = ViewModel; sourceTree = ""; @@ -926,6 +929,7 @@ A38115BA292B447D0043E8B8 /* ShortcutCardCell.swift in Sources */, 8792479B291BDF820040D5C3 /* SearchView.swift in Sources */, A3FF018E291ACFA500384211 /* WithdrawalView.swift in Sources */, + 4DF15D732A4ECC7D0014F854 /* ListShortcutViewModel.swift in Sources */, 4D778A34290A53BA00C15AC4 /* UIApplication+Keyboard.swift in Sources */, A3766B232904330300708F83 /* ReadCurationView.swift in Sources */, 87E606B0291062F900C3DA13 /* AppleAuthCoordinator.swift in Sources */, diff --git a/HappyAnding/HappyAnding/Extensions/View/View+Navigation.swift b/HappyAnding/HappyAnding/Extensions/View/View+Navigation.swift index d3722e17..dc604c1e 100644 --- a/HappyAnding/HappyAnding/Extensions/View/View+Navigation.swift +++ b/HappyAnding/HappyAnding/Extensions/View/View+Navigation.swift @@ -78,7 +78,7 @@ extension View { func getDestination(data: T) -> some View { switch data { case is NavigationListShortcutType: - ListShortcutView(data: data as! NavigationListShortcutType) + ListShortcutView(viewModel: ListShortcutViewModel(data: data as! NavigationListShortcutType)) case is NavigationReadShortcutType: ReadShortcutView(data: data as! NavigationReadShortcutType) case is Curation: @@ -128,7 +128,7 @@ struct NavigationViewModifier: ViewModifier { ReadShortcutView(data: data) } .navigationDestination(for: NavigationListShortcutType.self) { data in - ListShortcutView(data: data) + ListShortcutView(viewModel: ListShortcutViewModel(data: data)) } .navigationDestination(for: NavigationListCategoryShortcutType.self) { data in ListCategoryShortcutView(data: data) diff --git a/HappyAnding/HappyAnding/ViewModel/ListShortcutViewModel.swift b/HappyAnding/HappyAnding/ViewModel/ListShortcutViewModel.swift new file mode 100644 index 00000000..b02c3216 --- /dev/null +++ b/HappyAnding/HappyAnding/ViewModel/ListShortcutViewModel.swift @@ -0,0 +1,33 @@ +// +// ListShortcutViewModel.swift +// HappyAnding +// +// Created by kimjimin on 2023/06/30. +// + +import SwiftUI + +final class ListShortcutViewModel: ObservableObject { + + var shortcutsZipViewModel = ShortcutsZipViewModel.share + + @Published private(set) var shortcuts: [Shortcuts] = [] + @Published private(set) var sectionType: SectionType = .download + + + init(data: NavigationListShortcutType) { + shortcuts = data.shortcuts ?? [] + sectionType = data.sectionType + } + + func fetchShortcutsBySectionType() -> [Shortcuts] { + switch self.sectionType { + case .recent: return shortcutsZipViewModel.allShortcuts + case .download: return shortcutsZipViewModel.sortedShortcutsByDownload + case .popular: return shortcutsZipViewModel.sortedShortcutsByLike + case .myDownloadShortcut: return shortcutsZipViewModel.shortcutsUserDownloaded + case .myLovingShortcut: return shortcutsZipViewModel.shortcutsUserLiked + case .myShortcut: return shortcutsZipViewModel.shortcutsMadeByUser + } + } +} diff --git a/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ListShortcutView.swift b/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ListShortcutView.swift index 5d21a150..f3c6bc8d 100644 --- a/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ListShortcutView.swift +++ b/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ListShortcutView.swift @@ -11,56 +11,39 @@ import SwiftUI /// sectionType: 다운로드 순위에서 접근할 시, .download를, 사랑받는 앱에서 접근시 .popular를 넣어주세요. struct ListShortcutView: View { - @EnvironmentObject var shortcutsZipViewModel: ShortcutsZipViewModel - - @State var data: NavigationListShortcutType - @State private var isLastItem = false + @StateObject var viewModel: ListShortcutViewModel var body: some View { - if let shortcuts = data.shortcuts { - if shortcuts.count == 0 { - Text("아직 \(data.sectionType.title)가 없어요") - .shortcutsZipBody2() - .foregroundColor(Color.gray4) - .frame(maxWidth: .infinity, maxHeight: .infinity) - - .background(Color.shortcutsZipBackground.ignoresSafeArea(.all, edges: .all)) - .navigationTitle(data.sectionType.title) - .navigationBarTitleDisplayMode(.inline) - } else { - ScrollView { - LazyVStack(spacing: 0) { - - //TODO: 무한 스크롤을 위한 업데이트 함수 필요 - switch data.sectionType { - case .recent: - makeShortcutCellList(shortcutsZipViewModel.allShortcuts) - case .download: - makeIndexShortcutCellList(shortcutsZipViewModel.sortedShortcutsByDownload) - case .popular: - makeShortcutCellList(shortcutsZipViewModel.sortedShortcutsByLike) - case .myDownloadShortcut: - makeShortcutCellList(shortcutsZipViewModel.shortcutsUserDownloaded) - case .myLovingShortcut: - makeShortcutCellList(shortcutsZipViewModel.shortcutsUserLiked) - case .myShortcut: - makeShortcutCellList(shortcutsZipViewModel.shortcutsMadeByUser) - } - Rectangle() - .fill(Color.shortcutsZipBackground) - .frame(height: 44) - .listRowInsets(EdgeInsets()) - .listRowSeparator(.hidden) - } - } - .listRowBackground(Color.shortcutsZipBackground) - .listStyle(.plain) + if viewModel.shortcuts.count == 0 { + Text("아직 \(viewModel.sectionType.title)가 없어요") + .shortcutsZipBody2() + .foregroundColor(Color.gray4) + .frame(maxWidth: .infinity, maxHeight: .infinity) + .background(Color.shortcutsZipBackground.ignoresSafeArea(.all, edges: .all)) - .scrollContentBackground(.hidden) - .navigationTitle(data.sectionType.title) + .navigationTitle(viewModel.sectionType.title) .navigationBarTitleDisplayMode(.inline) - .navigationBarBackground ({ Color.shortcutsZipBackground }) + } else { + ScrollView { + LazyVStack(spacing: 0) { + + //TODO: 무한 스크롤을 위한 업데이트 함수 필요 + makeShortcutCellList(viewModel.fetchShortcutsBySectionType()) + + Rectangle() + .fill(Color.shortcutsZipBackground) + .frame(height: 44) + .listRowInsets(EdgeInsets()) + .listRowSeparator(.hidden) + } } + .listRowBackground(Color.shortcutsZipBackground) + .listStyle(.plain) + .background(Color.shortcutsZipBackground.ignoresSafeArea(.all, edges: .all)) + .scrollContentBackground(.hidden) + .navigationTitle(viewModel.sectionType.title) + .navigationBarTitleDisplayMode(.inline) + .navigationBarBackground ({ Color.shortcutsZipBackground }) } } @@ -69,10 +52,10 @@ struct ListShortcutView: View { ForEach(shortcuts, id: \.self) { shortcut in let navigationData = NavigationReadShortcutType(shortcut: shortcut, shortcutID: shortcut.id, - navigationParentView: self.data.navigationParentView) + navigationParentView: .shortcuts) ShortcutCell(shortcut: shortcut, - sectionType: data.sectionType, - navigationParentView: data.navigationParentView) + sectionType: viewModel.sectionType, + navigationParentView: .shortcuts) .navigationLinkRouter(data: navigationData) } @@ -83,10 +66,10 @@ struct ListShortcutView: View { ForEach(Array(shortcuts.enumerated()), id: \.offset) { index, shortcut in let navigationData = NavigationReadShortcutType(shortcut: shortcut, shortcutID: shortcut.id, - navigationParentView: self.data.navigationParentView) + navigationParentView: .shortcuts) ShortcutCell(shortcut: shortcut, rankNumber: index + 1, - navigationParentView: data.navigationParentView) + navigationParentView: .shortcuts) .navigationLinkRouter(data: navigationData) .listRowInsets(EdgeInsets()) .listRowSeparator(.hidden) From d7a5c37c41629fc643979282f9f082d5ed81f0b6 Mon Sep 17 00:00:00 2001 From: jim4020key Date: Fri, 30 Jun 2023 18:35:13 +0900 Subject: [PATCH 04/11] [Feat] #471 - Add ListCategoryShortcutViewModel --- .../HappyAnding.xcodeproj/project.pbxproj | 4 ++++ .../Extensions/View/View+Navigation.swift | 4 ++-- .../ListCategoryShortcutViewModel.swift | 22 +++++++++++++++++++ .../ListCategoryShortcutView.swift | 21 ++++++------------ 4 files changed, 35 insertions(+), 16 deletions(-) create mode 100644 HappyAnding/HappyAnding/ViewModel/ListCategoryShortcutViewModel.swift diff --git a/HappyAnding/HappyAnding.xcodeproj/project.pbxproj b/HappyAnding/HappyAnding.xcodeproj/project.pbxproj index 9c23fb66..b26ee96a 100644 --- a/HappyAnding/HappyAnding.xcodeproj/project.pbxproj +++ b/HappyAnding/HappyAnding.xcodeproj/project.pbxproj @@ -19,6 +19,7 @@ 4D7D16082986BBDE008B3332 /* TextLiteral.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D7D16062986BBD7008B3332 /* TextLiteral.swift */; }; 4DAD635E292AB61700ABF8C1 /* UpdateShortcutView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DAD635D292AB61700ABF8C1 /* UpdateShortcutView.swift */; }; 4DF15D732A4ECC7D0014F854 /* ListShortcutViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DF15D722A4ECC7D0014F854 /* ListShortcutViewModel.swift */; }; + 4DF15D752A4ECE1F0014F854 /* ListCategoryShortcutViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DF15D742A4ECE1F0014F854 /* ListCategoryShortcutViewModel.swift */; }; 4DF62DD52A0550ED00A8B377 /* UIScreen+Size.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8795A16F292AB945004B765F /* UIScreen+Size.swift */; }; 87276C382933F6AB00C92F4C /* CustomTextEditor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87276C372933F6AB00C92F4C /* CustomTextEditor.swift */; }; 872A7D8F2918393B004A05B8 /* PrivacyPolicyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 872A7D8E2918393B004A05B8 /* PrivacyPolicyView.swift */; }; @@ -198,6 +199,7 @@ 4D7D16062986BBD7008B3332 /* TextLiteral.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = TextLiteral.swift; path = HappyAnding/TextLiteral.swift; sourceTree = SOURCE_ROOT; }; 4DAD635D292AB61700ABF8C1 /* UpdateShortcutView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UpdateShortcutView.swift; sourceTree = ""; }; 4DF15D722A4ECC7D0014F854 /* ListShortcutViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListShortcutViewModel.swift; sourceTree = ""; }; + 4DF15D742A4ECE1F0014F854 /* ListCategoryShortcutViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListCategoryShortcutViewModel.swift; sourceTree = ""; }; 87276C372933F6AB00C92F4C /* CustomTextEditor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomTextEditor.swift; sourceTree = ""; }; 872A7D8E2918393B004A05B8 /* PrivacyPolicyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrivacyPolicyView.swift; sourceTree = ""; }; 872B5D3C2A2E0FF9008DCC57 /* CurationType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CurationType.swift; sourceTree = ""; }; @@ -659,6 +661,7 @@ F9AC2BB52935201C00165820 /* CheckUpdateVersion.swift */, 4D061BB92A475EE800F76835 /* ExploreShortcutViewModel.swift */, 4DF15D722A4ECC7D0014F854 /* ListShortcutViewModel.swift */, + 4DF15D742A4ECE1F0014F854 /* ListCategoryShortcutViewModel.swift */, ); path = ViewModel; sourceTree = ""; @@ -937,6 +940,7 @@ 8795A170292AB945004B765F /* UIScreen+Size.swift in Sources */, 8786B2E629A7F987000B46A1 /* String+Date.swift in Sources */, F96D45B72980301F000C2441 /* SubtitleTextView.swift in Sources */, + 4DF15D752A4ECE1F0014F854 /* ListCategoryShortcutViewModel.swift in Sources */, 87E99CDB29042CCA009B691F /* Category.swift in Sources */, 876B4F6F299E3D91009672D9 /* NavigationRouter.swift in Sources */, A04ACB062903D0B2004A85A6 /* MyShortcutCardView.swift in Sources */, diff --git a/HappyAnding/HappyAnding/Extensions/View/View+Navigation.swift b/HappyAnding/HappyAnding/Extensions/View/View+Navigation.swift index dc604c1e..7657eb24 100644 --- a/HappyAnding/HappyAnding/Extensions/View/View+Navigation.swift +++ b/HappyAnding/HappyAnding/Extensions/View/View+Navigation.swift @@ -90,7 +90,7 @@ extension View { case is NavigationSearch: SearchView() case is NavigationListCategoryShortcutType: - ListCategoryShortcutView(data: data as! NavigationListCategoryShortcutType) + ListCategoryShortcutView(viewModel: ListCategoryShortcutViewModel(data: data as! NavigationListCategoryShortcutType)) case is NavigationNicknameView: EditNicknameView() case is NavigationSettingView: @@ -131,7 +131,7 @@ struct NavigationViewModifier: ViewModifier { ListShortcutView(viewModel: ListShortcutViewModel(data: data)) } .navigationDestination(for: NavigationListCategoryShortcutType.self) { data in - ListCategoryShortcutView(data: data) + ListCategoryShortcutView(viewModel: ListCategoryShortcutViewModel(data: data)) } .navigationDestination(for: NavigationLisence.self) { value in LicenseView() diff --git a/HappyAnding/HappyAnding/ViewModel/ListCategoryShortcutViewModel.swift b/HappyAnding/HappyAnding/ViewModel/ListCategoryShortcutViewModel.swift new file mode 100644 index 00000000..c111e5b8 --- /dev/null +++ b/HappyAnding/HappyAnding/ViewModel/ListCategoryShortcutViewModel.swift @@ -0,0 +1,22 @@ +// +// ListCategoryShortcutViewModel.swift +// HappyAnding +// +// Created by kimjimin on 2023/06/30. +// + +import SwiftUI + +final class ListCategoryShortcutViewModel: ObservableObject { + + var shortcutsZipViewModel = ShortcutsZipViewModel.share + + @Published private(set) var shortcuts: [Shortcuts] = [] + @Published private(set) var categoryName: Category = .business + + init(data: NavigationListCategoryShortcutType) { + shortcuts = shortcutsZipViewModel.shortcutsInCategory[data.categoryName.index] + categoryName = data.categoryName + } + +} diff --git a/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ListCategoryShortcutView.swift b/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ListCategoryShortcutView.swift index 2cb26e76..2d749b88 100644 --- a/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ListCategoryShortcutView.swift +++ b/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ListCategoryShortcutView.swift @@ -1,5 +1,5 @@ // -// ShortcutsListView.swift +// ListCategoryShortcutView.swift // HappyAnding // // Created by KiWoong Hong on 2022/11/05. @@ -9,11 +9,7 @@ import SwiftUI struct ListCategoryShortcutView: View { - @EnvironmentObject var shortcutsZipViewModel: ShortcutsZipViewModel - - @State var navigationTitle = "" - @State var isLastShortcut: Bool = false - @State var data: NavigationListCategoryShortcutType + @StateObject var viewModel: ListCategoryShortcutViewModel var body: some View { ScrollView { @@ -21,12 +17,12 @@ struct ListCategoryShortcutView: View { scrollHeader LazyVStack(spacing: 0) { - ForEach(data.shortcuts, id: \.self) { shortcut in + ForEach(viewModel.shortcuts, id: \.self) { shortcut in let data = NavigationReadShortcutType(shortcut: shortcut, shortcutID: shortcut.id, - navigationParentView: self.data.navigationParentView) + navigationParentView: .shortcuts) ShortcutCell(shortcut: shortcut, - navigationParentView: self.data.navigationParentView) + navigationParentView: .shortcuts) .navigationLinkRouter(data: data) .listRowInsets(EdgeInsets()) .listRowSeparator(.hidden) @@ -34,18 +30,15 @@ struct ListCategoryShortcutView: View { } .padding(.bottom, 44) } - .navigationBarTitle(data.categoryName.translateName()) + .navigationBarTitle(viewModel.categoryName.translateName()) .navigationBarTitleDisplayMode(.inline) .background(Color.shortcutsZipBackground) .navigationBarBackground ({ Color.shortcutsZipBackground }) - .onAppear { - self.data.shortcuts = shortcutsZipViewModel.shortcutsInCategory[data.categoryName.index] - } } var scrollHeader: some View { VStack { - Text(data.categoryName.fetchDescription().lineBreaking) + Text(viewModel.categoryName.fetchDescription().lineBreaking) } .foregroundColor(.gray5) .shortcutsZipBody2() From b4317c4b800261f6a25bcb6cd6908d60a8d00d9d Mon Sep 17 00:00:00 2001 From: jim4020key Date: Fri, 30 Jun 2023 19:03:30 +0900 Subject: [PATCH 05/11] [Feat] #471 - Remove NavigationListShortcutType --- .../HappyAnding/Extensions/View/View+Navigation.swift | 6 +++--- HappyAnding/HappyAnding/Model/NavigationStackModel.swift | 8 -------- .../HappyAnding/ViewModel/ListShortcutViewModel.swift | 6 +++--- .../Views/Components/MyShortcutCardListView.swift | 7 +------ .../Views/ExploreShortcutViews/ExploreShortcutView.swift | 4 +--- .../Views/ExploreShortcutViews/ListShortcutView.swift | 2 +- .../HappyAnding/Views/MyPageViews/MyPageView.swift | 7 +------ 7 files changed, 10 insertions(+), 30 deletions(-) diff --git a/HappyAnding/HappyAnding/Extensions/View/View+Navigation.swift b/HappyAnding/HappyAnding/Extensions/View/View+Navigation.swift index 7657eb24..92c0798d 100644 --- a/HappyAnding/HappyAnding/Extensions/View/View+Navigation.swift +++ b/HappyAnding/HappyAnding/Extensions/View/View+Navigation.swift @@ -77,8 +77,8 @@ extension View { @ViewBuilder func getDestination(data: T) -> some View { switch data { - case is NavigationListShortcutType: - ListShortcutView(viewModel: ListShortcutViewModel(data: data as! NavigationListShortcutType)) + case is SectionType: + ListShortcutView(viewModel: ListShortcutViewModel(data: data as! SectionType)) case is NavigationReadShortcutType: ReadShortcutView(data: data as! NavigationReadShortcutType) case is Curation: @@ -127,7 +127,7 @@ struct NavigationViewModifier: ViewModifier { .navigationDestination(for: NavigationReadShortcutType.self) { data in ReadShortcutView(data: data) } - .navigationDestination(for: NavigationListShortcutType.self) { data in + .navigationDestination(for: SectionType.self) { data in ListShortcutView(viewModel: ListShortcutViewModel(data: data)) } .navigationDestination(for: NavigationListCategoryShortcutType.self) { data in diff --git a/HappyAnding/HappyAnding/Model/NavigationStackModel.swift b/HappyAnding/HappyAnding/Model/NavigationStackModel.swift index 5760ec24..dc562151 100644 --- a/HappyAnding/HappyAnding/Model/NavigationStackModel.swift +++ b/HappyAnding/HappyAnding/Model/NavigationStackModel.swift @@ -7,14 +7,6 @@ import SwiftUI -struct NavigationListShortcutType: Identifiable, Hashable { - var id = UUID().uuidString - - var sectionType: SectionType - var shortcuts: [Shortcuts]? - let navigationParentView: NavigationParentView -} - struct NavigationReadShortcutType: Identifiable, Hashable { var id = UUID().uuidString diff --git a/HappyAnding/HappyAnding/ViewModel/ListShortcutViewModel.swift b/HappyAnding/HappyAnding/ViewModel/ListShortcutViewModel.swift index b02c3216..77fcf0c3 100644 --- a/HappyAnding/HappyAnding/ViewModel/ListShortcutViewModel.swift +++ b/HappyAnding/HappyAnding/ViewModel/ListShortcutViewModel.swift @@ -15,9 +15,9 @@ final class ListShortcutViewModel: ObservableObject { @Published private(set) var sectionType: SectionType = .download - init(data: NavigationListShortcutType) { - shortcuts = data.shortcuts ?? [] - sectionType = data.sectionType + init(data: SectionType) { + sectionType = data + shortcuts = fetchShortcutsBySectionType() } func fetchShortcutsBySectionType() -> [Shortcuts] { diff --git a/HappyAnding/HappyAnding/Views/Components/MyShortcutCardListView.swift b/HappyAnding/HappyAnding/Views/Components/MyShortcutCardListView.swift index 70d5634b..f480d218 100644 --- a/HappyAnding/HappyAnding/Views/Components/MyShortcutCardListView.swift +++ b/HappyAnding/HappyAnding/Views/Components/MyShortcutCardListView.swift @@ -21,11 +21,6 @@ struct MyShortcutCardListView: View { @State var isGradeAlertPresented = false var shortcuts: [Shortcuts]? - var data: NavigationListShortcutType { - NavigationListShortcutType(sectionType: .myShortcut, - shortcuts: self.shortcuts, - navigationParentView: self.navigationParentView) - } let navigationParentView: NavigationParentView @@ -37,7 +32,7 @@ struct MyShortcutCardListView: View { Spacer() MoreCaptionTextView(text: TextLiteral.more) - .navigationLinkRouter(data: data) + .navigationLinkRouter(data: SectionType.myShortcut) } .padding(.horizontal, 16) diff --git a/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ExploreShortcutView.swift b/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ExploreShortcutView.swift index fa2d353b..8c9a66d0 100644 --- a/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ExploreShortcutView.swift +++ b/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ExploreShortcutView.swift @@ -121,9 +121,7 @@ extension ExploreShortcutView { Spacer() MoreCaptionTextView(text: TextLiteral.more) - .navigationLinkRouter(data: NavigationListShortcutType(sectionType: sectionType, - shortcuts: shortcuts, - navigationParentView: .shortcuts)) + .navigationLinkRouter(data: sectionType) } .padding(.horizontal, 16) .padding(.bottom, 12) diff --git a/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ListShortcutView.swift b/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ListShortcutView.swift index f3c6bc8d..25e3d711 100644 --- a/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ListShortcutView.swift +++ b/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ListShortcutView.swift @@ -28,7 +28,7 @@ struct ListShortcutView: View { LazyVStack(spacing: 0) { //TODO: 무한 스크롤을 위한 업데이트 함수 필요 - makeShortcutCellList(viewModel.fetchShortcutsBySectionType()) + makeShortcutCellList(viewModel.shortcuts) Rectangle() .fill(Color.shortcutsZipBackground) diff --git a/HappyAnding/HappyAnding/Views/MyPageViews/MyPageView.swift b/HappyAnding/HappyAnding/Views/MyPageViews/MyPageView.swift index 24d32177..8189d867 100644 --- a/HappyAnding/HappyAnding/Views/MyPageViews/MyPageView.swift +++ b/HappyAnding/HappyAnding/Views/MyPageViews/MyPageView.swift @@ -88,11 +88,6 @@ struct MyPageShortcutListCell: View { var type: SectionType let shortcuts: [Shortcuts] - var data: NavigationListShortcutType { - NavigationListShortcutType(sectionType: self.type, - shortcuts: self.shortcuts, - navigationParentView: .myPage) - } var body: some View { HStack() { Text(type == .myLovingShortcut ? TextLiteral.myPageViewLikedShortcuts : TextLiteral.myPageViewDownloadedShortcuts) @@ -119,6 +114,6 @@ struct MyPageShortcutListCell: View { } .frame(maxWidth: .infinity, alignment: .leading) .padding(.horizontal, 16) - .navigationLinkRouter(data: data) + .navigationLinkRouter(data: self.type) } } From 526b90b8923beafaca03f17e3c1b0dd624dc5939 Mon Sep 17 00:00:00 2001 From: jim4020key Date: Fri, 30 Jun 2023 19:13:44 +0900 Subject: [PATCH 06/11] [Feat] #471 - Remove NavigationListCategoryShortcutType --- .../HappyAnding/Extensions/View/View+Navigation.swift | 6 +++--- HappyAnding/HappyAnding/Model/NavigationStackModel.swift | 9 --------- .../ViewModel/ListCategoryShortcutViewModel.swift | 8 ++++---- .../Views/ExploreShortcutViews/ExploreShortcutView.swift | 8 ++------ .../ExploreShortcutViews/ListCategoryShortcutView.swift | 4 ++-- 5 files changed, 11 insertions(+), 24 deletions(-) diff --git a/HappyAnding/HappyAnding/Extensions/View/View+Navigation.swift b/HappyAnding/HappyAnding/Extensions/View/View+Navigation.swift index 92c0798d..cd1bf32c 100644 --- a/HappyAnding/HappyAnding/Extensions/View/View+Navigation.swift +++ b/HappyAnding/HappyAnding/Extensions/View/View+Navigation.swift @@ -89,8 +89,8 @@ extension View { ShowProfileView(data: data as! NavigationProfile) case is NavigationSearch: SearchView() - case is NavigationListCategoryShortcutType: - ListCategoryShortcutView(viewModel: ListCategoryShortcutViewModel(data: data as! NavigationListCategoryShortcutType)) + case is Category: + ListCategoryShortcutView(viewModel: ListCategoryShortcutViewModel(data: data as! Category)) case is NavigationNicknameView: EditNicknameView() case is NavigationSettingView: @@ -130,7 +130,7 @@ struct NavigationViewModifier: ViewModifier { .navigationDestination(for: SectionType.self) { data in ListShortcutView(viewModel: ListShortcutViewModel(data: data)) } - .navigationDestination(for: NavigationListCategoryShortcutType.self) { data in + .navigationDestination(for: Category.self) { data in ListCategoryShortcutView(viewModel: ListCategoryShortcutViewModel(data: data)) } .navigationDestination(for: NavigationLisence.self) { value in diff --git a/HappyAnding/HappyAnding/Model/NavigationStackModel.swift b/HappyAnding/HappyAnding/Model/NavigationStackModel.swift index dc562151..0e58a781 100644 --- a/HappyAnding/HappyAnding/Model/NavigationStackModel.swift +++ b/HappyAnding/HappyAnding/Model/NavigationStackModel.swift @@ -21,15 +21,6 @@ struct NavigationProfile: Identifiable, Hashable { var userInfo: User? } -struct NavigationListCategoryShortcutType: Identifiable, Hashable { - - var id = UUID().uuidString - - var shortcuts: [Shortcuts] - var categoryName: Category - var navigationParentView: NavigationParentView -} - struct WriteCurationInfoType: Identifiable, Hashable { var id = UUID().uuidString diff --git a/HappyAnding/HappyAnding/ViewModel/ListCategoryShortcutViewModel.swift b/HappyAnding/HappyAnding/ViewModel/ListCategoryShortcutViewModel.swift index c111e5b8..dd6f6db3 100644 --- a/HappyAnding/HappyAnding/ViewModel/ListCategoryShortcutViewModel.swift +++ b/HappyAnding/HappyAnding/ViewModel/ListCategoryShortcutViewModel.swift @@ -12,11 +12,11 @@ final class ListCategoryShortcutViewModel: ObservableObject { var shortcutsZipViewModel = ShortcutsZipViewModel.share @Published private(set) var shortcuts: [Shortcuts] = [] - @Published private(set) var categoryName: Category = .business + @Published private(set) var category: Category = .business - init(data: NavigationListCategoryShortcutType) { - shortcuts = shortcutsZipViewModel.shortcutsInCategory[data.categoryName.index] - categoryName = data.categoryName + init(data: Category) { + shortcuts = shortcutsZipViewModel.shortcutsInCategory[data.index] + category = data } } diff --git a/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ExploreShortcutView.swift b/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ExploreShortcutView.swift index 8c9a66d0..72b10137 100644 --- a/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ExploreShortcutView.swift +++ b/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ExploreShortcutView.swift @@ -58,9 +58,7 @@ struct ExploreShortcutView: View { LazyVGrid(columns: [GridItem(.flexible()), GridItem(.flexible())]) { ForEach(Array(Category.allCases.enumerated()), id: \.offset) { index, value in - let data = NavigationListCategoryShortcutType(shortcuts: [], - categoryName: value, - navigationParentView: .shortcuts) + let data = value if index < viewModel.numberOfDisplayedCategories { @@ -152,9 +150,7 @@ extension ExploreShortcutView { Spacer() MoreCaptionTextView(text: TextLiteral.more) - .navigationLinkRouter(data: NavigationListCategoryShortcutType(shortcuts: [], - categoryName: category, - navigationParentView: .shortcuts)) + .navigationLinkRouter(data: category) } .padding(.horizontal, 16) .padding(.bottom, 12) diff --git a/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ListCategoryShortcutView.swift b/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ListCategoryShortcutView.swift index 2d749b88..b7043037 100644 --- a/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ListCategoryShortcutView.swift +++ b/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ListCategoryShortcutView.swift @@ -30,7 +30,7 @@ struct ListCategoryShortcutView: View { } .padding(.bottom, 44) } - .navigationBarTitle(viewModel.categoryName.translateName()) + .navigationBarTitle(viewModel.category.translateName()) .navigationBarTitleDisplayMode(.inline) .background(Color.shortcutsZipBackground) .navigationBarBackground ({ Color.shortcutsZipBackground }) @@ -38,7 +38,7 @@ struct ListCategoryShortcutView: View { var scrollHeader: some View { VStack { - Text(viewModel.categoryName.fetchDescription().lineBreaking) + Text(viewModel.category.fetchDescription().lineBreaking) } .foregroundColor(.gray5) .shortcutsZipBody2() From fa73943d3882ed2353362717ef79441550140887 Mon Sep 17 00:00:00 2001 From: jim4020key Date: Fri, 30 Jun 2023 19:54:57 +0900 Subject: [PATCH 07/11] [Style] #471 - Remove unused lines --- .../ExploreShortcutView.swift | 4 +--- .../ListCategoryShortcutView.swift | 9 ++++----- .../ExploreShortcutViews/ListShortcutView.swift | 15 --------------- 3 files changed, 5 insertions(+), 23 deletions(-) diff --git a/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ExploreShortcutView.swift b/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ExploreShortcutView.swift index 72b10137..c633d7cb 100644 --- a/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ExploreShortcutView.swift +++ b/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ExploreShortcutView.swift @@ -58,12 +58,10 @@ struct ExploreShortcutView: View { LazyVGrid(columns: [GridItem(.flexible()), GridItem(.flexible())]) { ForEach(Array(Category.allCases.enumerated()), id: \.offset) { index, value in - let data = value - if index < viewModel.numberOfDisplayedCategories { categoryCellView(with: value.translateName()) - .navigationLinkRouter(data: data) + .navigationLinkRouter(data: value) } } diff --git a/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ListCategoryShortcutView.swift b/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ListCategoryShortcutView.swift index b7043037..872540c0 100644 --- a/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ListCategoryShortcutView.swift +++ b/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ListCategoryShortcutView.swift @@ -12,9 +12,10 @@ struct ListCategoryShortcutView: View { @StateObject var viewModel: ListCategoryShortcutViewModel var body: some View { + ScrollView { - scrollHeader + categoryHeader LazyVStack(spacing: 0) { ForEach(viewModel.shortcuts, id: \.self) { shortcut in @@ -36,10 +37,8 @@ struct ListCategoryShortcutView: View { .navigationBarBackground ({ Color.shortcutsZipBackground }) } - var scrollHeader: some View { - VStack { - Text(viewModel.category.fetchDescription().lineBreaking) - } + var categoryHeader: some View { + Text(viewModel.category.fetchDescription().lineBreaking) .foregroundColor(.gray5) .shortcutsZipBody2() .padding(16) diff --git a/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ListShortcutView.swift b/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ListShortcutView.swift index 25e3d711..9aeac984 100644 --- a/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ListShortcutView.swift +++ b/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ListShortcutView.swift @@ -60,19 +60,4 @@ struct ListShortcutView: View { } } - - @ViewBuilder - private func makeIndexShortcutCellList(_ shortcuts: [Shortcuts]) -> some View { - ForEach(Array(shortcuts.enumerated()), id: \.offset) { index, shortcut in - let navigationData = NavigationReadShortcutType(shortcut: shortcut, - shortcutID: shortcut.id, - navigationParentView: .shortcuts) - ShortcutCell(shortcut: shortcut, - rankNumber: index + 1, - navigationParentView: .shortcuts) - .navigationLinkRouter(data: navigationData) - .listRowInsets(EdgeInsets()) - .listRowSeparator(.hidden) - } - } } From 44476df0e6320ad316275ca17b08e63299a5434e Mon Sep 17 00:00:00 2001 From: jim4020key Date: Fri, 30 Jun 2023 20:10:28 +0900 Subject: [PATCH 08/11] [Feat] #471 - Relocate property --- .../HappyAnding/ViewModel/ExploreShortcutViewModel.swift | 1 - .../Views/ExploreShortcutViews/ExploreShortcutView.swift | 6 ++++-- HappyAnding/HappyAnding/Views/TabView/ShortcutTabView.swift | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/HappyAnding/HappyAnding/ViewModel/ExploreShortcutViewModel.swift b/HappyAnding/HappyAnding/ViewModel/ExploreShortcutViewModel.swift index 8ae69669..9e0b5fc3 100644 --- a/HappyAnding/HappyAnding/ViewModel/ExploreShortcutViewModel.swift +++ b/HappyAnding/HappyAnding/ViewModel/ExploreShortcutViewModel.swift @@ -14,7 +14,6 @@ final class ExploreShortcutViewModel: ObservableObject { @Published private(set) var isCategoryCellViewFolded = true @Published var isTappedAnnouncementCell = false @Published private(set) var numberOfDisplayedCategories = 6 - @Published private(set) var randomCategories = Category.allCases.shuffled().prefix(2) func changeNumberOfCategories() { isCategoryCellViewFolded.toggle() diff --git a/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ExploreShortcutView.swift b/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ExploreShortcutView.swift index c633d7cb..7692a3b3 100644 --- a/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ExploreShortcutView.swift +++ b/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ExploreShortcutView.swift @@ -14,6 +14,8 @@ struct ExploreShortcutView: View { // TODO: 추후 UpdateInfoView 제작 시 true로 변경해서 cell 보이게 하기 @AppStorage("isUpdateAnnnouncementShow") var isUpdateAnnnouncementShow: Bool = false + let randomCategories: [Category] + var body: some View { ScrollViewReader { proxy in ScrollView { @@ -33,11 +35,11 @@ struct ExploreShortcutView: View { sectionView(with: .recent) .id(111) - categoryCardView(with: viewModel.randomCategories[0]) + categoryCardView(with: randomCategories[0]) sectionView(with: .download) - categoryCardView(with: viewModel.randomCategories[1]) + categoryCardView(with: randomCategories[1]) sectionView(with: .popular) diff --git a/HappyAnding/HappyAnding/Views/TabView/ShortcutTabView.swift b/HappyAnding/HappyAnding/Views/TabView/ShortcutTabView.swift index 4b17c112..cfadb0a0 100644 --- a/HappyAnding/HappyAnding/Views/TabView/ShortcutTabView.swift +++ b/HappyAnding/HappyAnding/Views/TabView/ShortcutTabView.swift @@ -27,6 +27,7 @@ struct ShortcutTabView: View { @State private var tempShortcutId = "" @State private var tempCurationId = "" + @State private var randomCategories = Category.allCases.shuffled().prefix(2) @State private var twiceTappedTab = 0 @State private var firstTabID = UUID() @@ -106,7 +107,7 @@ struct ShortcutTabView: View { @ViewBuilder private func firstTab() -> some View { - ExploreShortcutView(viewModel: ExploreShortcutViewModel()) + ExploreShortcutView(viewModel: ExploreShortcutViewModel(), randomCategories: Array(randomCategories)) .modifierNavigation() .navigationBarBackground ({ Color.shortcutsZipBackground }) .id(firstTabID) From d51f2f4a838a427c3492246250dded04af05d395 Mon Sep 17 00:00:00 2001 From: jim4020key Date: Tue, 25 Jul 2023 07:35:13 +0900 Subject: [PATCH 09/11] [Feat] #471 - Set Access Modifiers --- .../HappyAnding/ViewModel/ExploreShortcutViewModel.swift | 8 ++++++-- .../ViewModel/ListCategoryShortcutViewModel.swift | 2 +- .../HappyAnding/ViewModel/ListShortcutViewModel.swift | 3 +-- .../Views/ExploreShortcutViews/ExploreShortcutView.swift | 4 ++-- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/HappyAnding/HappyAnding/ViewModel/ExploreShortcutViewModel.swift b/HappyAnding/HappyAnding/ViewModel/ExploreShortcutViewModel.swift index 9e0b5fc3..9c6ebfb1 100644 --- a/HappyAnding/HappyAnding/ViewModel/ExploreShortcutViewModel.swift +++ b/HappyAnding/HappyAnding/ViewModel/ExploreShortcutViewModel.swift @@ -9,7 +9,7 @@ import SwiftUI final class ExploreShortcutViewModel: ObservableObject { - var shortcutsZipViewModel = ShortcutsZipViewModel.share + private let shortcutsZipViewModel = ShortcutsZipViewModel.share @Published private(set) var isCategoryCellViewFolded = true @Published var isTappedAnnouncementCell = false @@ -24,7 +24,11 @@ final class ExploreShortcutViewModel: ObservableObject { isTappedAnnouncementCell = true } - func fetchShortcutsByCategories(category: Category) -> [Shortcuts] { + func fetchShortcuts(by category: Category) -> [Shortcuts] { shortcutsZipViewModel.shortcutsInCategory[category.index] } + + func fetchShortcuts(by sectionType: SectionType) -> [Shortcuts] { + sectionType.filterShortcuts(from: shortcutsZipViewModel) + } } diff --git a/HappyAnding/HappyAnding/ViewModel/ListCategoryShortcutViewModel.swift b/HappyAnding/HappyAnding/ViewModel/ListCategoryShortcutViewModel.swift index dd6f6db3..a90df18e 100644 --- a/HappyAnding/HappyAnding/ViewModel/ListCategoryShortcutViewModel.swift +++ b/HappyAnding/HappyAnding/ViewModel/ListCategoryShortcutViewModel.swift @@ -9,7 +9,7 @@ import SwiftUI final class ListCategoryShortcutViewModel: ObservableObject { - var shortcutsZipViewModel = ShortcutsZipViewModel.share + private let shortcutsZipViewModel = ShortcutsZipViewModel.share @Published private(set) var shortcuts: [Shortcuts] = [] @Published private(set) var category: Category = .business diff --git a/HappyAnding/HappyAnding/ViewModel/ListShortcutViewModel.swift b/HappyAnding/HappyAnding/ViewModel/ListShortcutViewModel.swift index 77fcf0c3..187add77 100644 --- a/HappyAnding/HappyAnding/ViewModel/ListShortcutViewModel.swift +++ b/HappyAnding/HappyAnding/ViewModel/ListShortcutViewModel.swift @@ -9,12 +9,11 @@ import SwiftUI final class ListShortcutViewModel: ObservableObject { - var shortcutsZipViewModel = ShortcutsZipViewModel.share + private let shortcutsZipViewModel = ShortcutsZipViewModel.share @Published private(set) var shortcuts: [Shortcuts] = [] @Published private(set) var sectionType: SectionType = .download - init(data: SectionType) { sectionType = data shortcuts = fetchShortcutsBySectionType() diff --git a/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ExploreShortcutView.swift b/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ExploreShortcutView.swift index 7692a3b3..bb96dbf2 100644 --- a/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ExploreShortcutView.swift +++ b/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ExploreShortcutView.swift @@ -110,7 +110,7 @@ extension ExploreShortcutView { @ViewBuilder private func sectionView(with sectionType: SectionType) -> some View { - let shortcuts = sectionType.filterShortcuts(from: viewModel.shortcutsZipViewModel) + let shortcuts = viewModel.fetchShortcuts(by: sectionType) VStack(spacing: 0) { HStack { @@ -157,7 +157,7 @@ extension ExploreShortcutView { ScrollView(.horizontal, showsIndicators: false) { HStack { - ForEach(viewModel.fetchShortcutsByCategories(category: category).prefix(7), id: \.self) { shortcut in + ForEach(viewModel.fetchShortcuts(by: category).prefix(7), id: \.self) { shortcut in let data = NavigationReadShortcutType( shortcutID: shortcut.id, navigationParentView: .shortcuts) From 8b51a77017cd76332d7bccce565d79ad3f916c87 Mon Sep 17 00:00:00 2001 From: jim4020key Date: Tue, 25 Jul 2023 07:40:51 +0900 Subject: [PATCH 10/11] [Chore] #471 - Change location of files --- HappyAnding/HappyAnding.xcodeproj/project.pbxproj | 6 +++--- .../ExploreShortcutViewModel.swift | 0 .../ListCategoryShortcutViewModel.swift | 0 .../ListShortcutViewModel.swift | 0 4 files changed, 3 insertions(+), 3 deletions(-) rename HappyAnding/HappyAnding/ViewModel/{ => ExploreShortcutViewModels}/ExploreShortcutViewModel.swift (100%) rename HappyAnding/HappyAnding/ViewModel/{ => ExploreShortcutViewModels}/ListCategoryShortcutViewModel.swift (100%) rename HappyAnding/HappyAnding/ViewModel/{ => ExploreShortcutViewModels}/ListShortcutViewModel.swift (100%) diff --git a/HappyAnding/HappyAnding.xcodeproj/project.pbxproj b/HappyAnding/HappyAnding.xcodeproj/project.pbxproj index b26ee96a..640674cb 100644 --- a/HappyAnding/HappyAnding.xcodeproj/project.pbxproj +++ b/HappyAnding/HappyAnding.xcodeproj/project.pbxproj @@ -381,6 +381,9 @@ 8788E1A12A484518007C3852 /* ExploreShortcutViewModels */ = { isa = PBXGroup; children = ( + 4D061BB92A475EE800F76835 /* ExploreShortcutViewModel.swift */, + 4DF15D722A4ECC7D0014F854 /* ListShortcutViewModel.swift */, + 4DF15D742A4ECE1F0014F854 /* ListCategoryShortcutViewModel.swift */, ); path = ExploreShortcutViewModels; sourceTree = ""; @@ -659,9 +662,6 @@ A0F822AB2910B8F100AF4448 /* ShortcutsZipViewModel.swift */, 4D61A766291E1EE8000EF531 /* NavigationViewModel.swift */, F9AC2BB52935201C00165820 /* CheckUpdateVersion.swift */, - 4D061BB92A475EE800F76835 /* ExploreShortcutViewModel.swift */, - 4DF15D722A4ECC7D0014F854 /* ListShortcutViewModel.swift */, - 4DF15D742A4ECE1F0014F854 /* ListCategoryShortcutViewModel.swift */, ); path = ViewModel; sourceTree = ""; diff --git a/HappyAnding/HappyAnding/ViewModel/ExploreShortcutViewModel.swift b/HappyAnding/HappyAnding/ViewModel/ExploreShortcutViewModels/ExploreShortcutViewModel.swift similarity index 100% rename from HappyAnding/HappyAnding/ViewModel/ExploreShortcutViewModel.swift rename to HappyAnding/HappyAnding/ViewModel/ExploreShortcutViewModels/ExploreShortcutViewModel.swift diff --git a/HappyAnding/HappyAnding/ViewModel/ListCategoryShortcutViewModel.swift b/HappyAnding/HappyAnding/ViewModel/ExploreShortcutViewModels/ListCategoryShortcutViewModel.swift similarity index 100% rename from HappyAnding/HappyAnding/ViewModel/ListCategoryShortcutViewModel.swift rename to HappyAnding/HappyAnding/ViewModel/ExploreShortcutViewModels/ListCategoryShortcutViewModel.swift diff --git a/HappyAnding/HappyAnding/ViewModel/ListShortcutViewModel.swift b/HappyAnding/HappyAnding/ViewModel/ExploreShortcutViewModels/ListShortcutViewModel.swift similarity index 100% rename from HappyAnding/HappyAnding/ViewModel/ListShortcutViewModel.swift rename to HappyAnding/HappyAnding/ViewModel/ExploreShortcutViewModels/ListShortcutViewModel.swift From 6536aa1ede5a660397d20a5d1ae6f4b052cde018 Mon Sep 17 00:00:00 2001 From: jim4020key Date: Tue, 25 Jul 2023 07:49:49 +0900 Subject: [PATCH 11/11] [Style] #471 - Rename properties --- .../ExploreShortcutViewModel.swift | 16 ++++++++-------- .../ListCategoryShortcutViewModel.swift | 4 ++-- .../ListShortcutViewModel.swift | 4 ++-- .../ExploreShortcutView.swift | 6 +++--- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/HappyAnding/HappyAnding/ViewModel/ExploreShortcutViewModels/ExploreShortcutViewModel.swift b/HappyAnding/HappyAnding/ViewModel/ExploreShortcutViewModels/ExploreShortcutViewModel.swift index 9c6ebfb1..dca00d12 100644 --- a/HappyAnding/HappyAnding/ViewModel/ExploreShortcutViewModels/ExploreShortcutViewModel.swift +++ b/HappyAnding/HappyAnding/ViewModel/ExploreShortcutViewModels/ExploreShortcutViewModel.swift @@ -12,23 +12,23 @@ final class ExploreShortcutViewModel: ObservableObject { private let shortcutsZipViewModel = ShortcutsZipViewModel.share @Published private(set) var isCategoryCellViewFolded = true - @Published var isTappedAnnouncementCell = false + @Published var isAnnouncementCellShowing = false @Published private(set) var numberOfDisplayedCategories = 6 - func changeNumberOfCategories() { - isCategoryCellViewFolded.toggle() - numberOfDisplayedCategories = isCategoryCellViewFolded ? 6 : 12 + func changeDisplayedCategories() { + self.isCategoryCellViewFolded.toggle() + self.numberOfDisplayedCategories = isCategoryCellViewFolded ? 6 : 12 } - func isShowingAnnouncement() { - isTappedAnnouncementCell = true + func announcementCellDidTap() { + self.isAnnouncementCellShowing = true } func fetchShortcuts(by category: Category) -> [Shortcuts] { - shortcutsZipViewModel.shortcutsInCategory[category.index] + self.shortcutsZipViewModel.shortcutsInCategory[category.index] } func fetchShortcuts(by sectionType: SectionType) -> [Shortcuts] { - sectionType.filterShortcuts(from: shortcutsZipViewModel) + sectionType.filterShortcuts(from: self.shortcutsZipViewModel) } } diff --git a/HappyAnding/HappyAnding/ViewModel/ExploreShortcutViewModels/ListCategoryShortcutViewModel.swift b/HappyAnding/HappyAnding/ViewModel/ExploreShortcutViewModels/ListCategoryShortcutViewModel.swift index a90df18e..e029f62e 100644 --- a/HappyAnding/HappyAnding/ViewModel/ExploreShortcutViewModels/ListCategoryShortcutViewModel.swift +++ b/HappyAnding/HappyAnding/ViewModel/ExploreShortcutViewModels/ListCategoryShortcutViewModel.swift @@ -15,8 +15,8 @@ final class ListCategoryShortcutViewModel: ObservableObject { @Published private(set) var category: Category = .business init(data: Category) { - shortcuts = shortcutsZipViewModel.shortcutsInCategory[data.index] - category = data + self.shortcuts = shortcutsZipViewModel.shortcutsInCategory[data.index] + self.category = data } } diff --git a/HappyAnding/HappyAnding/ViewModel/ExploreShortcutViewModels/ListShortcutViewModel.swift b/HappyAnding/HappyAnding/ViewModel/ExploreShortcutViewModels/ListShortcutViewModel.swift index 187add77..06e1b292 100644 --- a/HappyAnding/HappyAnding/ViewModel/ExploreShortcutViewModels/ListShortcutViewModel.swift +++ b/HappyAnding/HappyAnding/ViewModel/ExploreShortcutViewModels/ListShortcutViewModel.swift @@ -15,8 +15,8 @@ final class ListShortcutViewModel: ObservableObject { @Published private(set) var sectionType: SectionType = .download init(data: SectionType) { - sectionType = data - shortcuts = fetchShortcutsBySectionType() + self.sectionType = data + self.shortcuts = fetchShortcutsBySectionType() } func fetchShortcutsBySectionType() -> [Shortcuts] { diff --git a/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ExploreShortcutView.swift b/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ExploreShortcutView.swift index bb96dbf2..39dd83be 100644 --- a/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ExploreShortcutView.swift +++ b/HappyAnding/HappyAnding/Views/ExploreShortcutViews/ExploreShortcutView.swift @@ -22,7 +22,7 @@ struct ExploreShortcutView: View { VStack(spacing: 32) { if isUpdateAnnnouncementShow { Button { - viewModel.isShowingAnnouncement() + viewModel.announcementCellDidTap() } label: { AnnouncementCell(icon: "updateAppIcon", tagName: TextLiteral.updateTag, @@ -50,7 +50,7 @@ struct ExploreShortcutView: View { Spacer() Button { - viewModel.changeNumberOfCategories() + viewModel.changeDisplayedCategories() } label: { MoreCaptionTextView(text: viewModel.isCategoryCellViewFolded ? TextLiteral.categoryViewUnfold : TextLiteral.categoryViewFold) } @@ -95,7 +95,7 @@ struct ExploreShortcutView: View { } } .navigationBarBackground ({ Color.shortcutsZipBackground }) - .sheet(isPresented: $viewModel.isTappedAnnouncementCell) { + .sheet(isPresented: $viewModel.isAnnouncementCellShowing) { UpdateInfoView() .presentationDetents([.large]) .presentationDragIndicator(.visible)