From 2925a82b70dd70f5d7ad80e32860ca499dc95085 Mon Sep 17 00:00:00 2001 From: otoolz Date: Tue, 22 Nov 2022 15:05:22 +0900 Subject: [PATCH 01/19] =?UTF-8?q?[feat]=20"=EB=8B=89=EB=84=A4=EC=9E=84?= =?UTF-8?q?=EB=8B=98=EC=9D=84=20=EC=9C=84=ED=95=9C=20=EB=AA=A8=EC=9D=8C?= =?UTF-8?q?=EC=A7=91"=EC=9D=84=20=EC=9C=84=ED=95=9C=20CurationListView=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "닉네임님을 위한 모음집"을 위한 CurationListView 수정 --- .../Views/Components/CurationListView.swift | 15 +++++++++++---- .../ExploreCurationViews/ListCurationView.swift | 1 + 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/HappyAnding/HappyAnding/Views/Components/CurationListView.swift b/HappyAnding/HappyAnding/Views/Components/CurationListView.swift index 972b4392..bcdd08d9 100644 --- a/HappyAnding/HappyAnding/Views/Components/CurationListView.swift +++ b/HappyAnding/HappyAnding/Views/Components/CurationListView.swift @@ -9,6 +9,7 @@ import SwiftUI struct CurationListView: View { + @EnvironmentObject var shortcutsZipViewModel: ShortcutsZipViewModel @State var data: NavigationListCurationType @Binding var userCurations: [Curation] @@ -41,6 +42,8 @@ struct CurationListView: View { } struct CurationListHeader: View { + + @EnvironmentObject var shortcutsZipViewModel: ShortcutsZipViewModel @Binding var userCurations: [Curation] @State var data: NavigationListCurationType @@ -48,10 +51,14 @@ struct CurationListHeader: View { var body: some View { HStack(alignment: .bottom) { - Text(data.title ?? "") - .Title2() - .foregroundColor(.Gray5) - .onTapGesture { } + if data.type == .personalCuration { + Text("\(shortcutsZipViewModel.userInfo?.nickname ?? "")\(data.type.rawValue)") + } else { + Text(data.title ?? "") + .Title2() + .foregroundColor(.Gray5) + .onTapGesture { } + } Spacer() NavigationLink(value: data) { diff --git a/HappyAnding/HappyAnding/Views/ExploreCurationViews/ListCurationView.swift b/HappyAnding/HappyAnding/Views/ExploreCurationViews/ListCurationView.swift index 108873ab..4f116df8 100644 --- a/HappyAnding/HappyAnding/Views/ExploreCurationViews/ListCurationView.swift +++ b/HappyAnding/HappyAnding/Views/ExploreCurationViews/ListCurationView.swift @@ -9,6 +9,7 @@ import SwiftUI enum CurationType: String { case myCuration = "내가 작성한 큐레이션" case userCuration = "큐레이션 모아보기" + case personalCuration = "님을 위한 모음집" } /** From fb21f6f93d277ecb1702128b0ffe1d802884839a Mon Sep 17 00:00:00 2001 From: otoolz Date: Tue, 22 Nov 2022 15:09:48 +0900 Subject: [PATCH 02/19] =?UTF-8?q?[feat]=20"=EB=95=A1=EB=95=A1=EB=8B=98?= =?UTF-8?q?=EC=9D=84=20=EC=9C=84=ED=95=9C=20=EB=AA=A8=EC=9D=8C=EC=A7=91"?= =?UTF-8?q?=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=ED=81=90=EB=A0=88=EC=9D=B4?= =?UTF-8?q?=EC=85=98=20=EB=B7=B0=EC=97=90=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "땡땡님을 위한 모음집"리스트 큐레이션 뷰에 추가 --- .../HappyAnding/Views/Components/CurationListView.swift | 3 +++ .../Views/ExploreCurationViews/ExploreCurationView.swift | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/HappyAnding/HappyAnding/Views/Components/CurationListView.swift b/HappyAnding/HappyAnding/Views/Components/CurationListView.swift index bcdd08d9..35edb940 100644 --- a/HappyAnding/HappyAnding/Views/Components/CurationListView.swift +++ b/HappyAnding/HappyAnding/Views/Components/CurationListView.swift @@ -53,6 +53,9 @@ struct CurationListHeader: View { HStack(alignment: .bottom) { if data.type == .personalCuration { Text("\(shortcutsZipViewModel.userInfo?.nickname ?? "")\(data.type.rawValue)") + .Title2() + .foregroundColor(.Gray5) + .onTapGesture { } } else { Text(data.title ?? "") .Title2() diff --git a/HappyAnding/HappyAnding/Views/ExploreCurationViews/ExploreCurationView.swift b/HappyAnding/HappyAnding/Views/ExploreCurationViews/ExploreCurationView.swift index 11ad2a10..1044efe8 100644 --- a/HappyAnding/HappyAnding/Views/ExploreCurationViews/ExploreCurationView.swift +++ b/HappyAnding/HappyAnding/Views/ExploreCurationViews/ExploreCurationView.swift @@ -21,13 +21,21 @@ struct ExploreCurationView: View { .padding(.bottom, 32) //나의 큐레이션 + /* UserCurationListView(data: NavigationListCurationType(type: .myCuration, title: "내가 작성한 큐레이션", isAllUser: false, navigationParentView: .curations), userCurations: $shortcutsZipViewModel.curationsMadeByUser) .padding(.bottom, 20) + */ + //땡땡니을 위한 모음집 + CurationListView(data: NavigationListCurationType(type: .personalCuration, + title: "", + isAllUser: true, + navigationParentView: .curations), + userCurations: $shortcutsZipViewModel.userCurations) //추천 유저 큐레이션 CurationListView(data: NavigationListCurationType(type: .userCuration, title: "큐레이션 모아보기", From 8eba4226734ab22770684568f5723985a62a1dd1 Mon Sep 17 00:00:00 2001 From: otoolz Date: Tue, 22 Nov 2022 22:15:27 +0900 Subject: [PATCH 03/19] =?UTF-8?q?[feat]=20=EB=8B=A4=EC=9A=B4=EB=A1=9C?= =?UTF-8?q?=EB=93=9C=ED=96=88=EB=8D=98=20=EC=88=8F=EC=BB=B7=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20=ED=81=90=EB=A0=88=EC=9D=B4=EC=85=98=20=EC=A0=95?= =?UTF-8?q?=EB=A0=AC=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 다운로드했던 숏컷 관련 큐레이션 정렬 로직 추가 --- .../ViewModel/ShortcutsZipViewModel.swift | 1 + .../ExploreCurationView.swift | 27 ++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/HappyAnding/HappyAnding/ViewModel/ShortcutsZipViewModel.swift b/HappyAnding/HappyAnding/ViewModel/ShortcutsZipViewModel.swift index 48472eab..9a91928a 100644 --- a/HappyAnding/HappyAnding/ViewModel/ShortcutsZipViewModel.swift +++ b/HappyAnding/HappyAnding/ViewModel/ShortcutsZipViewModel.swift @@ -31,6 +31,7 @@ class ShortcutsZipViewModel: ObservableObject { @Published var curationsMadeByUser: [Curation] = [] // 유저가 만든 큐레이션배열 @Published var userCurations: [Curation] = [] + @Published var personalCurations: [Curation] = [] // "땡땡님을 위한 모음집" 큐레이션배열 @Published var adminCurations: [Curation] = [] @Published var allComments: [Comments] = [] diff --git a/HappyAnding/HappyAnding/Views/ExploreCurationViews/ExploreCurationView.swift b/HappyAnding/HappyAnding/Views/ExploreCurationViews/ExploreCurationView.swift index 1044efe8..72e09ff4 100644 --- a/HappyAnding/HappyAnding/Views/ExploreCurationViews/ExploreCurationView.swift +++ b/HappyAnding/HappyAnding/Views/ExploreCurationViews/ExploreCurationView.swift @@ -35,7 +35,32 @@ struct ExploreCurationView: View { title: "", isAllUser: true, navigationParentView: .curations), - userCurations: $shortcutsZipViewModel.userCurations) + userCurations: $shortcutsZipViewModel.personalCurations) + .onAppear { +// curationID를 싺다 저장해서 Set하고 + //userCuration Filter 에서 해당 ID만 필터링한걸 personal Curation에 넣기 + shortcutsZipViewModel.personalCurations.removeAll() + let personalCurationIDs = Set(shortcutsZipViewModel.shortcutsUserDownloaded.flatMap({ $0.curationIDs })) + print(personalCurationIDs) + for curationID in personalCurationIDs { + print("\n\n\n\n\ncurationID: \(curationID)") + shortcutsZipViewModel.personalCurations.append(shortcutsZipViewModel.userCurations.first(where: { $0.id == curationID})!) + print(shortcutsZipViewModel.personalCurations) + } + + /* + shortcutsZipViewModel.personalCurations = shortcutsZipViewModel.userCurations.filter { + var isEnvolved = false + let shortcuts = $0.shortcuts + for shortcutDownloaded in shortcutsZipViewModel.shortcutsUserDownloaded { + if shortcuts.map({ $0.id }).contains(shortcutDownloaded.id) { + return true + } + } + return isEnvolved + } + */ + } //추천 유저 큐레이션 CurationListView(data: NavigationListCurationType(type: .userCuration, title: "큐레이션 모아보기", From a92c22e90810a73c0119e71ff070c6b7895f2475 Mon Sep 17 00:00:00 2001 From: otoolz Date: Tue, 22 Nov 2022 22:47:12 +0900 Subject: [PATCH 04/19] =?UTF-8?q?[feat]=20=EB=AA=A8=EC=9D=8C=EC=A7=91=20?= =?UTF-8?q?=EB=8D=94=EB=B3=B4=EA=B8=B0=20=EC=8B=9C=20=EC=A0=84=EC=B2=B4=20?= =?UTF-8?q?=ED=81=90=EB=A0=88=EC=9D=B4=EC=85=98=20=EB=82=98=EC=98=A4?= =?UTF-8?q?=EB=8D=98=20=EB=B2=84=EA=B7=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 모음집 더보기 시 전체 큐레이션 나오던 버그 수정 --- .../ExploreCurationView.swift | 28 ++----------------- 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/HappyAnding/HappyAnding/Views/ExploreCurationViews/ExploreCurationView.swift b/HappyAnding/HappyAnding/Views/ExploreCurationViews/ExploreCurationView.swift index 72e09ff4..41fb3c28 100644 --- a/HappyAnding/HappyAnding/Views/ExploreCurationViews/ExploreCurationView.swift +++ b/HappyAnding/HappyAnding/Views/ExploreCurationViews/ExploreCurationView.swift @@ -20,25 +20,13 @@ struct ExploreCurationView: View { .padding(.top, 20) .padding(.bottom, 32) - //나의 큐레이션 - /* - UserCurationListView(data: NavigationListCurationType(type: .myCuration, - title: "내가 작성한 큐레이션", - isAllUser: false, - navigationParentView: .curations), - userCurations: $shortcutsZipViewModel.curationsMadeByUser) - .padding(.bottom, 20) - */ - //땡땡니을 위한 모음집 CurationListView(data: NavigationListCurationType(type: .personalCuration, title: "", - isAllUser: true, + isAllUser: false, navigationParentView: .curations), userCurations: $shortcutsZipViewModel.personalCurations) .onAppear { -// curationID를 싺다 저장해서 Set하고 - //userCuration Filter 에서 해당 ID만 필터링한걸 personal Curation에 넣기 shortcutsZipViewModel.personalCurations.removeAll() let personalCurationIDs = Set(shortcutsZipViewModel.shortcutsUserDownloaded.flatMap({ $0.curationIDs })) print(personalCurationIDs) @@ -47,20 +35,8 @@ struct ExploreCurationView: View { shortcutsZipViewModel.personalCurations.append(shortcutsZipViewModel.userCurations.first(where: { $0.id == curationID})!) print(shortcutsZipViewModel.personalCurations) } - - /* - shortcutsZipViewModel.personalCurations = shortcutsZipViewModel.userCurations.filter { - var isEnvolved = false - let shortcuts = $0.shortcuts - for shortcutDownloaded in shortcutsZipViewModel.shortcutsUserDownloaded { - if shortcuts.map({ $0.id }).contains(shortcutDownloaded.id) { - return true - } - } - return isEnvolved - } - */ } + //추천 유저 큐레이션 CurationListView(data: NavigationListCurationType(type: .userCuration, title: "큐레이션 모아보기", From 9c24887d3731a0b1042900bc95a1bfcb1a4f468d Mon Sep 17 00:00:00 2001 From: otoolz Date: Tue, 22 Nov 2022 22:55:55 +0900 Subject: [PATCH 05/19] =?UTF-8?q?[feat]=20=EB=8D=94=EB=B3=B4=EA=B8=B0=20?= =?UTF-8?q?=EB=93=A4=EC=96=B4=EA=B0=94=EC=9D=84=20=EB=95=8C=20=EB=84=A4?= =?UTF-8?q?=EB=B9=84=ED=83=80=EC=9D=B4=ED=8B=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 더보기 들어갔을 때 네비타이틀 수정 --- .../Views/ExploreCurationViews/ListCurationView.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HappyAnding/HappyAnding/Views/ExploreCurationViews/ListCurationView.swift b/HappyAnding/HappyAnding/Views/ExploreCurationViews/ListCurationView.swift index 4f116df8..f3520120 100644 --- a/HappyAnding/HappyAnding/Views/ExploreCurationViews/ListCurationView.swift +++ b/HappyAnding/HappyAnding/Views/ExploreCurationViews/ListCurationView.swift @@ -60,7 +60,7 @@ struct ListCurationView: View { .listStyle(.plain) .background(Color.Background.ignoresSafeArea(.all, edges: .all)) .scrollContentBackground(.hidden) - .navigationBarTitle(self.data.type.rawValue) + .navigationBarTitle("\(shortcutsZipViewModel.userInfo?.nickname ?? "")\(self.data.type.rawValue)") .navigationBarTitleDisplayMode(.inline) } } From b89fc08da6377b531f73f33592de70740f7a2210 Mon Sep 17 00:00:00 2001 From: "Elie (Jeon Jimin)" Date: Wed, 23 Nov 2022 03:34:31 +0900 Subject: [PATCH 06/19] [Feat] #288 - add comment function wip rebase develop --- HappyAnding/HappyAnding/Model/Comment.swift | 2 +- .../ViewModel/ShortcutsZipViewModel.swift | 44 +++++++++++-------- .../ReadShortcutCommentView.swift | 17 ++----- .../ReadShortcutView/ReadShortcutView.swift | 35 ++++++++------- 4 files changed, 49 insertions(+), 49 deletions(-) diff --git a/HappyAnding/HappyAnding/Model/Comment.swift b/HappyAnding/HappyAnding/Model/Comment.swift index b068068f..608b8ddf 100644 --- a/HappyAnding/HappyAnding/Model/Comment.swift +++ b/HappyAnding/HappyAnding/Model/Comment.swift @@ -7,7 +7,7 @@ import Foundation -struct Comments: Identifiable, Codable { +struct Comments: Identifiable, Codable, Equatable { var id: String //댓글이 달린 단축어 id var comments: [Comment] diff --git a/HappyAnding/HappyAnding/ViewModel/ShortcutsZipViewModel.swift b/HappyAnding/HappyAnding/ViewModel/ShortcutsZipViewModel.swift index 5894e33c..eb32035d 100644 --- a/HappyAnding/HappyAnding/ViewModel/ShortcutsZipViewModel.swift +++ b/HappyAnding/HappyAnding/ViewModel/ShortcutsZipViewModel.swift @@ -63,6 +63,9 @@ class ShortcutsZipViewModel: ObservableObject { fetchKeyword { keywords in self.keywords = keywords } + fetchCommentAll { comments in + self.allComments = comments + } } func initUserShortcut(user: User) { @@ -720,7 +723,7 @@ class ShortcutsZipViewModel: ObservableObject { //MARK: 모든 댓글을 가져오는 함수 - func fetchCommentAll(shortcutID: String, completionHandler: @escaping ([Comments]) -> ()) { + func fetchCommentAll(completionHandler: @escaping ([Comments]) -> ()) { var comments: [Comments] = [] var query: Query! @@ -731,6 +734,7 @@ class ShortcutsZipViewModel: ObservableObject { print("Error fetching snapshots: \(error!)") return } + print(snapshot.metadata.isFromCache ? "**local cache" : "**server") snapshot.documentChanges.forEach { diff in let decoder = JSONDecoder() @@ -743,12 +747,14 @@ class ShortcutsZipViewModel: ObservableObject { comments.insert(comment, at: 0) } if (diff.type == .modified) { - if let index = self.allComments.firstIndex(where: { $0.id == shortcutID}) { + print("**comment modified") + if let index = self.allComments.firstIndex(where: { $0.id == comment.id}) { self.allComments[index] = comment + print("**\(self.allComments[index])") } } if (diff.type == .removed) { - comments.removeAll(where: { $0.id == shortcutID}) + comments.removeAll(where: { $0.id == comment.id}) } } catch let error { print("error: \(error)") @@ -760,33 +766,33 @@ class ShortcutsZipViewModel: ObservableObject { //MARK: 단축어 ID에 해당하는 댓글 목록 불러오는 함수 - func fetchComment(shortcutID: String) -> Comments? { - if let index = allComments.firstIndex(where: {$0.id == shortcutID}) { - return allComments[index] + func fetchComment(shortcutID: String) -> Comments { + if let index = self.allComments.firstIndex(where: {$0.id == shortcutID}) { + return self.allComments[index] } - return nil + return Comments(id: shortcutID, comments: []) } func updateComment(shortcutID: String, comment: Comment) { - if var comments = fetchComment(shortcutID: shortcutID) { - comments.comments.append(comment) - setData(model: comments) - } + var data = comment + data.date = Date().getDate() + data.user_id = self.userInfo!.id + var comments = fetchComment(shortcutID: shortcutID) + comments.comments.append(data) + setData(model: comments) } //대댓글 삭제 시 이용 func deleteComment(shortcutID: String, commentID: String) { - if var comments = fetchComment(shortcutID: shortcutID) { - comments.comments.removeAll(where: { $0.id == commentID }) - setData(model: comments) - } + var comments = fetchComment(shortcutID: shortcutID) + comments.comments.removeAll(where: { $0.id == commentID }) + setData(model: comments) } //원댓글 삭제 시 이용 func deleteCommentByBundleID(shortcutID: String, bundleID: String) { - if var comments = fetchComment(shortcutID: shortcutID) { - comments.comments.removeAll(where: { $0.bundel_id == bundleID }) - setData(model: comments) - } + var comments = fetchComment(shortcutID: shortcutID) + comments.comments.removeAll(where: { $0.bundel_id == bundleID }) + setData(model: comments) } } diff --git a/HappyAnding/HappyAnding/Views/ShortcutDetailViews/ReadShortcutView/ReadShortcutCommentView.swift b/HappyAnding/HappyAnding/Views/ShortcutDetailViews/ReadShortcutView/ReadShortcutCommentView.swift index 57be1086..99a08593 100644 --- a/HappyAnding/HappyAnding/Views/ShortcutDetailViews/ReadShortcutView/ReadShortcutCommentView.swift +++ b/HappyAnding/HappyAnding/Views/ShortcutDetailViews/ReadShortcutView/ReadShortcutCommentView.swift @@ -8,9 +8,10 @@ import SwiftUI struct ReadShortcutCommentView: View { + @EnvironmentObject var shortcutsZipViewModel: ShortcutsZipViewModel @Binding var addedComment: Comment - @State var comments = [Comment]() - @State var isReply = true + @Binding var comments: [Comment] + let shortcutID: String var body: some View { VStack(alignment: .leading) { @@ -18,29 +19,19 @@ struct ReadShortcutCommentView: View { Text("등록된 댓글이 없습니다") .Body2() .foregroundColor(.Gray4) - } else { comment Spacer() } } .padding(.top, 16) - .onAppear { - //TODO: 댓글 데이터 불러오기 - for _ in 0...10 { - let comment = Comment(user_id: "1", date: "2022112211", - depth: Int.random(in: 0...1), - contents: "댓글을남겨요") - comments.append(comment) - } - } } var comment: some View { ForEach(comments, id: \.self) { comment in HStack(alignment: .top, spacing: 8) { - if comment.depth == 0 { + if comment.depth == 1 { Image(systemName: "arrow.turn.down.right") .foregroundColor(.Gray4) } diff --git a/HappyAnding/HappyAnding/Views/ShortcutDetailViews/ReadShortcutView/ReadShortcutView.swift b/HappyAnding/HappyAnding/Views/ShortcutDetailViews/ReadShortcutView/ReadShortcutView.swift index f0aa8988..96ad421e 100644 --- a/HappyAnding/HappyAnding/Views/ShortcutDetailViews/ReadShortcutView/ReadShortcutView.swift +++ b/HappyAnding/HappyAnding/Views/ShortcutDetailViews/ReadShortcutView/ReadShortcutView.swift @@ -30,6 +30,7 @@ struct ReadShortcutView: View { @State var isClickDownload = false @State var data: NavigationReadShortcutType + @State var comments: Comments = Comments(id: "", comments: []) @State var comment: Comment = Comment(user_id: "", date: "", depth: 0, contents: "") @State var height: CGFloat = UIScreen.screenHeight / 2 @@ -78,11 +79,6 @@ struct ReadShortcutView: View { } } .background(Color.Background) - .onAppear() { - data.shortcut = shortcutsZipViewModel.fetchShortcutDetail(id: data.shortcutID) - isMyLike = shortcutsZipViewModel.checkLikedShortrcut(shortcutID: data.shortcutID) - isFirstMyLike = isMyLike - } .onAppear(perform: {UINavigationBar.appearance().standardAppearance.configureWithTransparentBackground() }) .onChange(of: isEdit) { _ in if !isEdit { @@ -146,25 +142,30 @@ struct ReadShortcutView: View { data.shortcut = shortcutsZipViewModel.fetchShortcutDetail(id: data.shortcutID) isMyLike = shortcutsZipViewModel.checkLikedShortrcut(shortcutID: data.shortcutID) isFirstMyLike = isMyLike + self.comments = shortcutsZipViewModel.fetchComment(shortcutID: data.shortcutID) } .onChange(of: isEdit || isUpdating) { _ in if !isEdit || !isUpdating { data.shortcut = shortcutsZipViewModel.fetchShortcutDetail(id: data.shortcutID) } } + .onChange(of: shortcutsZipViewModel.allComments) { _ in + self.comments = shortcutsZipViewModel.fetchComment(shortcutID: data.shortcutID) + } .onDisappear() { if let shortcut = data.shortcut { let isAlreadyContained = shortcutsZipViewModel.userInfo?.downloadedShortcuts.firstIndex(where: { $0.id == self.data.shortcutID}) == nil if isClickDownload && isAlreadyContained { shortcutsZipViewModel.updateNumberOfDownload(shortcut: shortcut) shortcutsZipViewModel.shortcutsUserDownloaded.insert(shortcut, at: 0) - + let downloadedShortcut = DownloadedShortcut(id: shortcut.id, downloadLink: shortcut.downloadLink[0]) shortcutsZipViewModel.userInfo?.downloadedShortcuts.insert(downloadedShortcut, at: 0) } if isMyLike != isFirstMyLike { shortcutsZipViewModel.updateNumberOfLike(isMyLike: isMyLike, shortcut: shortcut) } + print("**\(shortcutsZipViewModel.fetchComment(shortcutID: shortcut.id))") } } .navigationBarTitleDisplayMode(NavigationBarItem.TitleDisplayMode.inline) @@ -244,8 +245,10 @@ struct ReadShortcutView: View { .focused($isFocused) Button { - //TODO: 서버에 데이터 전송 - print("click") + comment.contents = commentText + comments.comments.append(comment) + shortcutsZipViewModel.setData(model: comments) + commentText = "" } label: { Image(systemName: "paperplane.fill") .foregroundColor(.Gray5) @@ -357,14 +360,14 @@ extension ReadShortcutView { .preference(key: SizePreferenceKey.self, value: geometryProxy.size) }) -// case 2: -// ReadShortcutCommentView(addedComment: $comment) -// .background( -// GeometryReader { geometryProxy in -// Color.clear -// .preference(key: SizePreferenceKey.self, -// value: geometryProxy.size) -// }) + case 2: + ReadShortcutCommentView(addedComment: $comment, comments: $comments.comments, shortcutID: data.shortcutID) + .background( + GeometryReader { geometryProxy in + Color.clear + .preference(key: SizePreferenceKey.self, + value: geometryProxy.size) + }) default: EmptyView() } From 9a17856751e6b03828f3a96decfd5b2347c44849 Mon Sep 17 00:00:00 2001 From: "Elie (Jeon Jimin)" Date: Wed, 23 Nov 2022 07:53:20 +0900 Subject: [PATCH 07/19] [Feat] #288 - apply comment add function --- .../Extensions/View+Extension.swift | 15 ++++ HappyAnding/HappyAnding/Model/Comment.swift | 7 ++ .../ViewModel/ShortcutsZipViewModel.swift | 11 ++- .../ReadShortcutCommentView.swift | 5 +- .../ReadShortcutView/ReadShortcutView.swift | 73 ++++++++++++++----- 5 files changed, 84 insertions(+), 27 deletions(-) diff --git a/HappyAnding/HappyAnding/Extensions/View+Extension.swift b/HappyAnding/HappyAnding/Extensions/View+Extension.swift index 41203089..a2d60bd0 100644 --- a/HappyAnding/HappyAnding/Extensions/View+Extension.swift +++ b/HappyAnding/HappyAnding/Extensions/View+Extension.swift @@ -39,4 +39,19 @@ extension View { }) ) } + + func cornerRadius(_ radius: CGFloat, corners: UIRectCorner) -> some View { + clipShape( RoundedCorner(radius: radius, corners: corners) ) + } +} + +struct RoundedCorner: Shape { + + var radius: CGFloat = .infinity + var corners: UIRectCorner = .allCorners + + func path(in rect: CGRect) -> Path { + let path = UIBezierPath(roundedRect: rect, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius)) + return Path(path.cgPath) + } } diff --git a/HappyAnding/HappyAnding/Model/Comment.swift b/HappyAnding/HappyAnding/Model/Comment.swift index 608b8ddf..b9b5a327 100644 --- a/HappyAnding/HappyAnding/Model/Comment.swift +++ b/HappyAnding/HappyAnding/Model/Comment.swift @@ -20,6 +20,7 @@ struct Comments: Identifiable, Codable, Equatable { struct Comment: Identifiable, Codable, Hashable { var id = UUID().uuidString var bundel_id = "\(Date().getDate())_\(UUID().uuidString)" //원댓글과 대댓글을 묶는 id + var user_nickname: String //작성자 닉네임 var user_id: String //작성자 uid var date: String //처음 작성한 날짜만 저장 var depth: Int //0이면 원댓글, 1이면 대댓글 @@ -41,3 +42,9 @@ extension Comments { return sortedComments } } + +extension Comment { + func resetComment() -> Comment { + Comment(user_nickname: "", user_id: "", date: "", depth: 0, contents: "") + } +} diff --git a/HappyAnding/HappyAnding/ViewModel/ShortcutsZipViewModel.swift b/HappyAnding/HappyAnding/ViewModel/ShortcutsZipViewModel.swift index eb32035d..ee49f072 100644 --- a/HappyAnding/HappyAnding/ViewModel/ShortcutsZipViewModel.swift +++ b/HappyAnding/HappyAnding/ViewModel/ShortcutsZipViewModel.swift @@ -747,10 +747,8 @@ class ShortcutsZipViewModel: ObservableObject { comments.insert(comment, at: 0) } if (diff.type == .modified) { - print("**comment modified") - if let index = self.allComments.firstIndex(where: { $0.id == comment.id}) { - self.allComments[index] = comment - print("**\(self.allComments[index])") + if let index = comments.firstIndex(where: {$0.id == comment.id}) { + comments[index] = comment } } if (diff.type == .removed) { @@ -767,8 +765,9 @@ class ShortcutsZipViewModel: ObservableObject { //MARK: 단축어 ID에 해당하는 댓글 목록 불러오는 함수 func fetchComment(shortcutID: String) -> Comments { - if let index = self.allComments.firstIndex(where: {$0.id == shortcutID}) { - return self.allComments[index] + if let index = allComments.firstIndex(where: {$0.id == shortcutID}) { + allComments[index].comments = allComments[index].fetchSortedComment() + return allComments[index] } return Comments(id: shortcutID, comments: []) } diff --git a/HappyAnding/HappyAnding/Views/ShortcutDetailViews/ReadShortcutView/ReadShortcutCommentView.swift b/HappyAnding/HappyAnding/Views/ShortcutDetailViews/ReadShortcutView/ReadShortcutCommentView.swift index 99a08593..9009ec73 100644 --- a/HappyAnding/HappyAnding/Views/ShortcutDetailViews/ReadShortcutView/ReadShortcutCommentView.swift +++ b/HappyAnding/HappyAnding/Views/ShortcutDetailViews/ReadShortcutView/ReadShortcutCommentView.swift @@ -11,6 +11,7 @@ struct ReadShortcutCommentView: View { @EnvironmentObject var shortcutsZipViewModel: ShortcutsZipViewModel @Binding var addedComment: Comment @Binding var comments: [Comment] + @Binding var nestedCommentInfoText: String let shortcutID: String var body: some View { @@ -45,7 +46,7 @@ struct ReadShortcutCommentView: View { .frame(width: 24, height: 24) .foregroundColor(.Gray4) - Text(comment.user_id) + Text(comment.user_nickname) .Body2() .foregroundColor(.Gray4) } @@ -62,7 +63,7 @@ struct ReadShortcutCommentView: View { // MARK: Button HStack(spacing: 16) { Button { - print("답글") + nestedCommentInfoText = comment.user_nickname addedComment.bundel_id = comment.bundel_id addedComment.depth = 1 } label: { diff --git a/HappyAnding/HappyAnding/Views/ShortcutDetailViews/ReadShortcutView/ReadShortcutView.swift b/HappyAnding/HappyAnding/Views/ShortcutDetailViews/ReadShortcutView/ReadShortcutView.swift index 96ad421e..ee6ebeda 100644 --- a/HappyAnding/HappyAnding/Views/ShortcutDetailViews/ReadShortcutView/ReadShortcutView.swift +++ b/HappyAnding/HappyAnding/Views/ShortcutDetailViews/ReadShortcutView/ReadShortcutView.swift @@ -31,7 +31,8 @@ struct ReadShortcutView: View { @State var data: NavigationReadShortcutType @State var comments: Comments = Comments(id: "", comments: []) - @State var comment: Comment = Comment(user_id: "", date: "", depth: 0, contents: "") + @State var comment: Comment = Comment(user_nickname: "", user_id: "", date: "", depth: 0, contents: "") + @State var nestedCommentInfoText: String = "" @State var height: CGFloat = UIScreen.screenHeight / 2 @State var currentTab: Int = 0 @@ -165,7 +166,6 @@ struct ReadShortcutView: View { if isMyLike != isFirstMyLike { shortcutsZipViewModel.updateNumberOfLike(isMyLike: isMyLike, shortcut: shortcut) } - print("**\(shortcutsZipViewModel.fetchComment(shortcutID: shortcut.id))") } } .navigationBarTitleDisplayMode(NavigationBarItem.TitleDisplayMode.inline) @@ -235,33 +235,68 @@ struct ReadShortcutView: View { } var textField: some View { - HStack { + + VStack(spacing: 0) { if comment.depth == 1 { - Image(systemName: "arrow.turn.down.right") - .foregroundColor(.Gray4) + nestedCommentInfo } - TextField("댓글을 입력하세요", text: $commentText, axis: .vertical) - .Body2() - .focused($isFocused) - + HStack { + if comment.depth == 1 { + Image(systemName: "arrow.turn.down.right") + .foregroundColor(.Gray4) + } + TextField("댓글을 입력하세요", text: $commentText, axis: .vertical) + .Body2() + .focused($isFocused) + + Button { + comment.contents = commentText + comment.date = Date().getDate() + comment.user_id = shortcutsZipViewModel.userInfo!.id + comment.user_nickname = shortcutsZipViewModel.userInfo!.nickname + comments.comments.append(comment) + shortcutsZipViewModel.setData(model: comments) + commentText = "" + comment = comment.resetComment() + } label: { + Image(systemName: "paperplane.fill") + .foregroundColor(.Gray5) + } + } + .padding(.vertical, 12) + .padding(.horizontal, 16) + .background( + Rectangle() + .fill(Color.Gray1) + .cornerRadius(12 ,corners: comment.depth == 0 ? .allCorners : [.bottomLeft, .bottomRight]) + ) + .padding(.horizontal, 16) + .padding(.bottom, 20) + } + } + var nestedCommentInfo: some View { + HStack { + Text("@\(nestedCommentInfoText)") + .Footnote() + .foregroundColor(.Gray5) + Spacer() Button { - comment.contents = commentText - comments.comments.append(comment) - shortcutsZipViewModel.setData(model: comments) - commentText = "" + comment.bundel_id = "\(Date().getDate())_\(UUID().uuidString)" + comment.depth = 0 } label: { - Image(systemName: "paperplane.fill") + Image(systemName: "xmark") + .font(Font(UIFont.systemFont(ofSize: 17, weight: .medium))) .foregroundColor(.Gray5) } } - .padding(.vertical, 12) .padding(.horizontal, 16) + .padding(.vertical, 11) .background( - RoundedRectangle(cornerRadius: 12) - .fill(Color.Gray1) + Rectangle() + .fill(Color.Gray2) + .cornerRadius(12 ,corners: [.topLeft, .topRight]) ) .padding(.horizontal, 16) - .padding(.bottom, 20) } } @@ -361,7 +396,7 @@ extension ReadShortcutView { geometryProxy.size) }) case 2: - ReadShortcutCommentView(addedComment: $comment, comments: $comments.comments, shortcutID: data.shortcutID) + ReadShortcutCommentView(addedComment: $comment, comments: $comments.comments, nestedCommentInfoText: $nestedCommentInfoText, shortcutID: data.shortcutID) .background( GeometryReader { geometryProxy in Color.clear From 9b6e8bd63ec5de915c816c5c661ef5b93559a32d Mon Sep 17 00:00:00 2001 From: "Elie (Jeon Jimin)" Date: Wed, 23 Nov 2022 08:06:32 +0900 Subject: [PATCH 08/19] [Refactor] delete unnecessary function --- .../ReadShortcutView/ReadShortcutView.swift | 35 ++----------------- 1 file changed, 2 insertions(+), 33 deletions(-) diff --git a/HappyAnding/HappyAnding/Views/ShortcutDetailViews/ReadShortcutView/ReadShortcutView.swift b/HappyAnding/HappyAnding/Views/ShortcutDetailViews/ReadShortcutView/ReadShortcutView.swift index ee6ebeda..3d3243bd 100644 --- a/HappyAnding/HappyAnding/Views/ShortcutDetailViews/ReadShortcutView/ReadShortcutView.swift +++ b/HappyAnding/HappyAnding/Views/ShortcutDetailViews/ReadShortcutView/ReadShortcutView.swift @@ -80,36 +80,8 @@ struct ReadShortcutView: View { } } .background(Color.Background) - .onAppear(perform: {UINavigationBar.appearance().standardAppearance.configureWithTransparentBackground() }) - .onChange(of: isEdit) { _ in - if !isEdit { - data.shortcut = shortcutsZipViewModel.fetchShortcutDetail(id: data.shortcutID) - } - } - .onDisappear() { - if let shortcut = data.shortcut { - let isAlreadyContained = shortcutsZipViewModel.userInfo?.downloadedShortcuts.firstIndex(where: { $0.id == self.data.shortcutID}) == nil - if isClickDownload && isAlreadyContained { - shortcutsZipViewModel.updateNumberOfDownload(shortcut: shortcut) - shortcutsZipViewModel.shortcutsUserDownloaded.insert(shortcut, at: 0) - - let downloadedShortcut = DownloadedShortcut(id: shortcut.id, downloadLink: shortcut.downloadLink[0]) - shortcutsZipViewModel.userInfo?.downloadedShortcuts.insert(downloadedShortcut, at: 0) - } - if isMyLike != isFirstMyLike { - shortcutsZipViewModel.updateNumberOfLike(isMyLike: isMyLike, shortcut: shortcut) - if isMyLike { - shortcutsZipViewModel.userInfo?.likedShortcuts.insert(self.data.shortcutID, at: 0) - shortcutsZipViewModel.shortcutsUserLiked.insert(shortcut, at: 0) - } else { - shortcutsZipViewModel.userInfo?.likedShortcuts.removeAll(where: { $0 == self.data.shortcutID }) - shortcutsZipViewModel.shortcutsUserLiked.removeAll(where: { $0.id == self.data.shortcutID }) - } - } - } - } .safeAreaInset(edge: .bottom, spacing: 0) { - + VStack { if currentTab == 2 { textField @@ -138,8 +110,8 @@ struct ReadShortcutView: View { } .ignoresSafeArea(.keyboard) } - .background(Color.Background) .onAppear() { + UINavigationBar.appearance().standardAppearance.configureWithTransparentBackground() data.shortcut = shortcutsZipViewModel.fetchShortcutDetail(id: data.shortcutID) isMyLike = shortcutsZipViewModel.checkLikedShortrcut(shortcutID: data.shortcutID) isFirstMyLike = isMyLike @@ -150,9 +122,6 @@ struct ReadShortcutView: View { data.shortcut = shortcutsZipViewModel.fetchShortcutDetail(id: data.shortcutID) } } - .onChange(of: shortcutsZipViewModel.allComments) { _ in - self.comments = shortcutsZipViewModel.fetchComment(shortcutID: data.shortcutID) - } .onDisappear() { if let shortcut = data.shortcut { let isAlreadyContained = shortcutsZipViewModel.userInfo?.downloadedShortcuts.firstIndex(where: { $0.id == self.data.shortcutID}) == nil From abc5992922f2124678884c20520dfc05c3d2e7e6 Mon Sep 17 00:00:00 2001 From: "Elie (Jeon Jimin)" Date: Wed, 23 Nov 2022 08:17:17 +0900 Subject: [PATCH 09/19] [Refactor] change liked function location --- .../HappyAnding/ViewModel/ShortcutsZipViewModel.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/HappyAnding/HappyAnding/ViewModel/ShortcutsZipViewModel.swift b/HappyAnding/HappyAnding/ViewModel/ShortcutsZipViewModel.swift index ee49f072..08ffd5a8 100644 --- a/HappyAnding/HappyAnding/ViewModel/ShortcutsZipViewModel.swift +++ b/HappyAnding/HappyAnding/ViewModel/ShortcutsZipViewModel.swift @@ -424,6 +424,8 @@ class ShortcutsZipViewModel: ObservableObject { var increment = 0 if isMyLike { increment = 1 + shortcutsUserLiked.append(shortcut) + userInfo?.likedShortcuts.append(shortcut.id) self.fetchUser(userID: self.currentUser()) { data in var user = data user.likedShortcuts.append(shortcut.id) @@ -436,10 +438,11 @@ class ShortcutsZipViewModel: ObservableObject { } } else { increment = -1 + shortcutsUserLiked.removeAll(where: { $0.id == shortcut.id }) + userInfo?.likedShortcuts.removeAll(where: { $0 == shortcut.id }) self.fetchUser(userID: self.currentUser()) { data in var user = data user.likedShortcuts.removeAll(where: { $0 == shortcut.id }) - self.db.collection("User").document(user.id).setData(user.dictionary) { error in if let error { print(error.localizedDescription) From 5bf0e5922da0e3c8fc7783453656636d831698b7 Mon Sep 17 00:00:00 2001 From: "Elie (Jeon Jimin)" Date: Wed, 23 Nov 2022 08:53:40 +0900 Subject: [PATCH 10/19] [Style] fix variable name typo --- HappyAnding/HappyAnding/Model/Comment.swift | 6 +++--- .../HappyAnding/ViewModel/ShortcutsZipViewModel.swift | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/HappyAnding/HappyAnding/Model/Comment.swift b/HappyAnding/HappyAnding/Model/Comment.swift index b9b5a327..898d0c82 100644 --- a/HappyAnding/HappyAnding/Model/Comment.swift +++ b/HappyAnding/HappyAnding/Model/Comment.swift @@ -19,7 +19,7 @@ struct Comments: Identifiable, Codable, Equatable { struct Comment: Identifiable, Codable, Hashable { var id = UUID().uuidString - var bundel_id = "\(Date().getDate())_\(UUID().uuidString)" //원댓글과 대댓글을 묶는 id + var bundle_id = "\(Date().getDate())_\(UUID().uuidString)" //원댓글과 대댓글을 묶는 id var user_nickname: String //작성자 닉네임 var user_id: String //작성자 uid var date: String //처음 작성한 날짜만 저장 @@ -30,11 +30,11 @@ struct Comment: Identifiable, Codable, Hashable { extension Comments { func fetchSortedComment() -> [Comment] { let sortedComments = self.comments.sorted(by: { lhs, rhs in - if lhs.bundel_id == rhs.bundel_id { + if lhs.bundle_id == rhs.bundle_id { if lhs.depth < rhs.depth { return true } - } else if lhs.bundel_id < rhs.bundel_id { + } else if lhs.bundle_id < rhs.bundle_id { return true } return false diff --git a/HappyAnding/HappyAnding/ViewModel/ShortcutsZipViewModel.swift b/HappyAnding/HappyAnding/ViewModel/ShortcutsZipViewModel.swift index 08ffd5a8..a80a9945 100644 --- a/HappyAnding/HappyAnding/ViewModel/ShortcutsZipViewModel.swift +++ b/HappyAnding/HappyAnding/ViewModel/ShortcutsZipViewModel.swift @@ -794,7 +794,7 @@ class ShortcutsZipViewModel: ObservableObject { //원댓글 삭제 시 이용 func deleteCommentByBundleID(shortcutID: String, bundleID: String) { var comments = fetchComment(shortcutID: shortcutID) - comments.comments.removeAll(where: { $0.bundel_id == bundleID }) + comments.comments.removeAll(where: { $0.bundle_id == bundleID }) setData(model: comments) } } From d08bccc32cc4c251d9f508e0c68b87dc86d6bd31 Mon Sep 17 00:00:00 2001 From: "Elie (Jeon Jimin)" Date: Wed, 23 Nov 2022 08:54:12 +0900 Subject: [PATCH 11/19] [Feat] #288 - apply comment delete function --- .../ReadShortcutCommentView.swift | 33 ++++++++++++++++--- .../ReadShortcutView/ReadShortcutView.swift | 7 ++-- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/HappyAnding/HappyAnding/Views/ShortcutDetailViews/ReadShortcutView/ReadShortcutCommentView.swift b/HappyAnding/HappyAnding/Views/ShortcutDetailViews/ReadShortcutView/ReadShortcutCommentView.swift index 9009ec73..cbe57478 100644 --- a/HappyAnding/HappyAnding/Views/ShortcutDetailViews/ReadShortcutView/ReadShortcutCommentView.swift +++ b/HappyAnding/HappyAnding/Views/ShortcutDetailViews/ReadShortcutView/ReadShortcutCommentView.swift @@ -10,13 +10,15 @@ import SwiftUI struct ReadShortcutCommentView: View { @EnvironmentObject var shortcutsZipViewModel: ShortcutsZipViewModel @Binding var addedComment: Comment - @Binding var comments: [Comment] + @Binding var comments: Comments @Binding var nestedCommentInfoText: String + @State var isTappedDeleteButton = false + @State var deletedComment: Comment = Comment(user_nickname: "", user_id: "", date: "", depth: 0, contents: "") let shortcutID: String var body: some View { VStack(alignment: .leading) { - if comments.isEmpty { + if comments.comments.isEmpty { Text("등록된 댓글이 없습니다") .Body2() .foregroundColor(.Gray4) @@ -26,10 +28,31 @@ struct ReadShortcutCommentView: View { } } .padding(.top, 16) + .alert("댓글 삭제", isPresented: $isTappedDeleteButton) { + Button(role: .cancel) { + + } label: { + Text("닫기") + } + + Button(role: .destructive) { + if deletedComment.depth == 0 { + comments.comments.removeAll(where: { $0.bundle_id == deletedComment.bundle_id}) + } else { + comments.comments.removeAll(where: { $0.id == deletedComment.id}) + } + + shortcutsZipViewModel.setData(model: comments) + } label: { + Text("삭제") + } + } message: { + Text("대댓글도 함께 삭제됩니다. 댓글을 삭제하시겠습니까?") + } } var comment: some View { - ForEach(comments, id: \.self) { comment in + ForEach(comments.comments, id: \.self) { comment in HStack(alignment: .top, spacing: 8) { if comment.depth == 1 { @@ -64,7 +87,7 @@ struct ReadShortcutCommentView: View { HStack(spacing: 16) { Button { nestedCommentInfoText = comment.user_nickname - addedComment.bundel_id = comment.bundel_id + addedComment.bundle_id = comment.bundle_id addedComment.depth = 1 } label: { Text("답글") @@ -82,6 +105,8 @@ struct ReadShortcutCommentView: View { Button { print("삭제") + isTappedDeleteButton.toggle() + deletedComment = comment } label: { Text("삭제") .Footnote() diff --git a/HappyAnding/HappyAnding/Views/ShortcutDetailViews/ReadShortcutView/ReadShortcutView.swift b/HappyAnding/HappyAnding/Views/ShortcutDetailViews/ReadShortcutView/ReadShortcutView.swift index 3d3243bd..50500dbf 100644 --- a/HappyAnding/HappyAnding/Views/ShortcutDetailViews/ReadShortcutView/ReadShortcutView.swift +++ b/HappyAnding/HappyAnding/Views/ShortcutDetailViews/ReadShortcutView/ReadShortcutView.swift @@ -122,6 +122,9 @@ struct ReadShortcutView: View { data.shortcut = shortcutsZipViewModel.fetchShortcutDetail(id: data.shortcutID) } } + .onChange(of: shortcutsZipViewModel.allComments) { _ in + self.comments = shortcutsZipViewModel.fetchComment(shortcutID: data.shortcutID) + } .onDisappear() { if let shortcut = data.shortcut { let isAlreadyContained = shortcutsZipViewModel.userInfo?.downloadedShortcuts.firstIndex(where: { $0.id == self.data.shortcutID}) == nil @@ -250,7 +253,7 @@ struct ReadShortcutView: View { .foregroundColor(.Gray5) Spacer() Button { - comment.bundel_id = "\(Date().getDate())_\(UUID().uuidString)" + comment.bundle_id = "\(Date().getDate())_\(UUID().uuidString)" comment.depth = 0 } label: { Image(systemName: "xmark") @@ -365,7 +368,7 @@ extension ReadShortcutView { geometryProxy.size) }) case 2: - ReadShortcutCommentView(addedComment: $comment, comments: $comments.comments, nestedCommentInfoText: $nestedCommentInfoText, shortcutID: data.shortcutID) + ReadShortcutCommentView(addedComment: $comment, comments: $comments, nestedCommentInfoText: $nestedCommentInfoText, shortcutID: data.shortcutID) .background( GeometryReader { geometryProxy in Color.clear From 3f952d84457eb7081a05970afa323491124d74fe Mon Sep 17 00:00:00 2001 From: "Elie (Jeon Jimin)" Date: Wed, 23 Nov 2022 14:09:30 +0900 Subject: [PATCH 12/19] [Feat] #288 - add comment delete function --- .../ReadShortcutView/ReadShortcutCommentView.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/HappyAnding/HappyAnding/Views/ShortcutDetailViews/ReadShortcutView/ReadShortcutCommentView.swift b/HappyAnding/HappyAnding/Views/ShortcutDetailViews/ReadShortcutView/ReadShortcutCommentView.swift index cbe57478..d10b9be5 100644 --- a/HappyAnding/HappyAnding/Views/ShortcutDetailViews/ReadShortcutView/ReadShortcutCommentView.swift +++ b/HappyAnding/HappyAnding/Views/ShortcutDetailViews/ReadShortcutView/ReadShortcutCommentView.swift @@ -104,7 +104,6 @@ struct ReadShortcutCommentView: View { } Button { - print("삭제") isTappedDeleteButton.toggle() deletedComment = comment } label: { From f236c45e2fe67f8fe88574c325a70f80677181bf Mon Sep 17 00:00:00 2001 From: "Elie (Jeon Jimin)" Date: Wed, 23 Nov 2022 14:18:37 +0900 Subject: [PATCH 13/19] [Feat] #288 - resolve rebase conflict --- .../ReadShortcutView/ReadShortcutCommentView.swift | 2 +- .../ShortcutDetailViews/ReadShortcutView/ReadShortcutView.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/HappyAnding/HappyAnding/Views/ShortcutDetailViews/ReadShortcutView/ReadShortcutCommentView.swift b/HappyAnding/HappyAnding/Views/ShortcutDetailViews/ReadShortcutView/ReadShortcutCommentView.swift index d10b9be5..42e5e352 100644 --- a/HappyAnding/HappyAnding/Views/ShortcutDetailViews/ReadShortcutView/ReadShortcutCommentView.swift +++ b/HappyAnding/HappyAnding/Views/ShortcutDetailViews/ReadShortcutView/ReadShortcutCommentView.swift @@ -47,7 +47,7 @@ struct ReadShortcutCommentView: View { Text("삭제") } } message: { - Text("대댓글도 함께 삭제됩니다. 댓글을 삭제하시겠습니까?") + Text("답글도 함께 삭제됩니다. 댓글을 삭제하시겠습니까?") } } diff --git a/HappyAnding/HappyAnding/Views/ShortcutDetailViews/ReadShortcutView/ReadShortcutView.swift b/HappyAnding/HappyAnding/Views/ShortcutDetailViews/ReadShortcutView/ReadShortcutView.swift index 50500dbf..9505c118 100644 --- a/HappyAnding/HappyAnding/Views/ShortcutDetailViews/ReadShortcutView/ReadShortcutView.swift +++ b/HappyAnding/HappyAnding/Views/ShortcutDetailViews/ReadShortcutView/ReadShortcutView.swift @@ -41,7 +41,7 @@ struct ReadShortcutView: View { @Namespace var namespace private let contentSize = UIScreen.screenHeight / 2 - private let tabItems = ["기본 정보", "버전 정보"/*, "댓글"*/] + private let tabItems = ["기본 정보", "버전 정보", "댓글"] var body: some View { ScrollView { From 08343fe2c33c5eeb811d17ef0319dd65d0514fa1 Mon Sep 17 00:00:00 2001 From: "Elie (Jeon Jimin)" Date: Wed, 23 Nov 2022 14:28:04 +0900 Subject: [PATCH 14/19] [Feat] #288 - apply button disabled color --- .../ReadShortcutView/ReadShortcutView.swift | 119 +++++++++--------- 1 file changed, 59 insertions(+), 60 deletions(-) diff --git a/HappyAnding/HappyAnding/Views/ShortcutDetailViews/ReadShortcutView/ReadShortcutView.swift b/HappyAnding/HappyAnding/Views/ShortcutDetailViews/ReadShortcutView/ReadShortcutView.swift index 9505c118..382f69f6 100644 --- a/HappyAnding/HappyAnding/Views/ShortcutDetailViews/ReadShortcutView/ReadShortcutView.swift +++ b/HappyAnding/HappyAnding/Views/ShortcutDetailViews/ReadShortcutView/ReadShortcutView.swift @@ -232,8 +232,9 @@ struct ReadShortcutView: View { comment = comment.resetComment() } label: { Image(systemName: "paperplane.fill") - .foregroundColor(.Gray5) + .foregroundColor(commentText == "" ? Color.Gray2 : Color.Gray5) } + .disabled(commentText == "" ? true : false) } .padding(.vertical, 12) .padding(.horizontal, 16) @@ -340,66 +341,65 @@ extension ReadShortcutView { var detailInformationView: some View { VStack { - if let shortcut = data.shortcut { - ZStack { - TabView(selection: self.$currentTab) { - Color.clear.tag(0) - Color.clear.tag(1) - Color.clear.tag(2) - } - .tabViewStyle(.page(indexDisplayMode: .never)) - .frame(height: height) - - switch(currentTab) { - case 0: - ReadShortcutContentView(shortcut: $data.shortcut.unwrap()!) - .background( - GeometryReader { geometryProxy in - Color.clear - .preference(key: SizePreferenceKey.self, - value: geometryProxy.size) - }) - case 1: - ReadShortcutVersionView(shortcut: $data.shortcut.unwrap()!, isUpdating: $isUpdating) - .background( - GeometryReader { geometryProxy in - Color.clear - .preference(key: SizePreferenceKey.self, value: - geometryProxy.size) - }) - case 2: - ReadShortcutCommentView(addedComment: $comment, comments: $comments, nestedCommentInfoText: $nestedCommentInfoText, shortcutID: data.shortcutID) - .background( - GeometryReader { geometryProxy in - Color.clear - .preference(key: SizePreferenceKey.self, - value: geometryProxy.size) - }) - default: - EmptyView() - } + ZStack { + TabView(selection: self.$currentTab) { + Color.clear.tag(0) + Color.clear.tag(1) + Color.clear.tag(2) } + .tabViewStyle(.page(indexDisplayMode: .never)) + .frame(height: height) - .animation(.easeInOut, value: currentTab) - .onPreferenceChange(SizePreferenceKey.self) { newSize in - height = contentSize > newSize.height ? contentSize : newSize.height + switch(currentTab) { + case 0: + ReadShortcutContentView(shortcut: $data.shortcut.unwrap()!) + .background( + GeometryReader { geometryProxy in + Color.clear + .preference(key: SizePreferenceKey.self, + value: geometryProxy.size) + }) + case 1: + ReadShortcutVersionView(shortcut: $data.shortcut.unwrap()!, isUpdating: $isUpdating) + .background( + GeometryReader { geometryProxy in + Color.clear + .preference(key: SizePreferenceKey.self, value: + geometryProxy.size) + }) + case 2: + ReadShortcutCommentView(addedComment: $comment, comments: $comments, nestedCommentInfoText: $nestedCommentInfoText, shortcutID: data.shortcutID) + .background( + GeometryReader { geometryProxy in + Color.clear + .preference(key: SizePreferenceKey.self, + value: geometryProxy.size) + }) + default: + EmptyView() } - .gesture(DragGesture(minimumDistance: 20, coordinateSpace: .global) - .onEnded { value in - let horizontalAmount = value.translation.width - let verticalAmount = value.translation.height - - if abs(horizontalAmount) > abs(verticalAmount) { - if horizontalAmount < 0 { - if currentTab < 2 { - currentTab += 1 - } + } + + .animation(.easeInOut, value: currentTab) + .onPreferenceChange(SizePreferenceKey.self) { newSize in + height = contentSize > newSize.height ? contentSize : newSize.height + } + .gesture(DragGesture(minimumDistance: 20, coordinateSpace: .global) + .onEnded { value in + let horizontalAmount = value.translation.width + let verticalAmount = value.translation.height + + if abs(horizontalAmount) > abs(verticalAmount) { + if horizontalAmount < 0 { + if currentTab < 2 { + currentTab += 1 + } + } else { + if currentTab > 0 { + currentTab -= 1 } else { - if currentTab > 0 { - currentTab -= 1 - } else { - - // MARK: Navigation pop 코드 + + // MARK: Navigation pop 코드 // print("swipe back") // switch data.navigationParentView { // case .shortcuts: @@ -413,11 +413,10 @@ extension ReadShortcutView { // case .writeShortcut: // writeShortcutNavigation.navigationPath.removeLast() // } - } } } - }) - } + } + }) } } From 25708cd1c83d6cb3d8593d6cbfeb24ae50d1136b Mon Sep 17 00:00:00 2001 From: "Elie (Jeon Jimin)" Date: Wed, 23 Nov 2022 14:36:58 +0900 Subject: [PATCH 15/19] [Style] hide comment edit button --- .../ReadShortcutView/ReadShortcutCommentView.swift | 14 +++++++------- .../ReadShortcutView/ReadShortcutView.swift | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/HappyAnding/HappyAnding/Views/ShortcutDetailViews/ReadShortcutView/ReadShortcutCommentView.swift b/HappyAnding/HappyAnding/Views/ShortcutDetailViews/ReadShortcutView/ReadShortcutCommentView.swift index 42e5e352..caccf140 100644 --- a/HappyAnding/HappyAnding/Views/ShortcutDetailViews/ReadShortcutView/ReadShortcutCommentView.swift +++ b/HappyAnding/HappyAnding/Views/ShortcutDetailViews/ReadShortcutView/ReadShortcutCommentView.swift @@ -95,13 +95,13 @@ struct ReadShortcutCommentView: View { .foregroundColor(.Gray4) } - Button { - print("수정") - } label: { - Text("수정") - .Footnote() - .foregroundColor(.Gray4) - } +// Button { +// print("수정") +// } label: { +// Text("수정") +// .Footnote() +// .foregroundColor(.Gray4) +// } Button { isTappedDeleteButton.toggle() diff --git a/HappyAnding/HappyAnding/Views/ShortcutDetailViews/ReadShortcutView/ReadShortcutView.swift b/HappyAnding/HappyAnding/Views/ShortcutDetailViews/ReadShortcutView/ReadShortcutView.swift index 382f69f6..ca32d694 100644 --- a/HappyAnding/HappyAnding/Views/ShortcutDetailViews/ReadShortcutView/ReadShortcutView.swift +++ b/HappyAnding/HappyAnding/Views/ShortcutDetailViews/ReadShortcutView/ReadShortcutView.swift @@ -249,7 +249,7 @@ struct ReadShortcutView: View { } var nestedCommentInfo: some View { HStack { - Text("@\(nestedCommentInfoText)") + Text("@ \(nestedCommentInfoText)") .Footnote() .foregroundColor(.Gray5) Spacer() From b09478653a3a95d2f1b1c33597a39ec02099d6b5 Mon Sep 17 00:00:00 2001 From: otoolz Date: Wed, 23 Nov 2022 14:48:23 +0900 Subject: [PATCH 16/19] =?UTF-8?q?[feat]=20=EB=AA=A8=EC=9D=8C=EC=A7=91=20?= =?UTF-8?q?=EB=A6=AC=EC=8A=A4=ED=8A=B8=20bottom=20=ED=8C=A8=EB=94=A9=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 모음집 리스트 bottom 패딩 추가 --- .../Views/ExploreCurationViews/ExploreCurationView.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/HappyAnding/HappyAnding/Views/ExploreCurationViews/ExploreCurationView.swift b/HappyAnding/HappyAnding/Views/ExploreCurationViews/ExploreCurationView.swift index 41fb3c28..88a06a65 100644 --- a/HappyAnding/HappyAnding/Views/ExploreCurationViews/ExploreCurationView.swift +++ b/HappyAnding/HappyAnding/Views/ExploreCurationViews/ExploreCurationView.swift @@ -36,6 +36,7 @@ struct ExploreCurationView: View { print(shortcutsZipViewModel.personalCurations) } } + .padding(.bottom, 32) //추천 유저 큐레이션 CurationListView(data: NavigationListCurationType(type: .userCuration, From 09d8a3837fdc1c04c5e880ba4746a802f15cc701 Mon Sep 17 00:00:00 2001 From: otoolz Date: Wed, 23 Nov 2022 14:58:09 +0900 Subject: [PATCH 17/19] =?UTF-8?q?[fix]=20optional=20=EA=B4=80=EB=A0=A8=20?= =?UTF-8?q?=EC=97=90=EB=9F=AC=EB=94=B0=EB=A5=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit optional 관련 에러따른 수정 Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value --- .../Views/ExploreCurationViews/ExploreCurationView.swift | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/HappyAnding/HappyAnding/Views/ExploreCurationViews/ExploreCurationView.swift b/HappyAnding/HappyAnding/Views/ExploreCurationViews/ExploreCurationView.swift index 88a06a65..3445a194 100644 --- a/HappyAnding/HappyAnding/Views/ExploreCurationViews/ExploreCurationView.swift +++ b/HappyAnding/HappyAnding/Views/ExploreCurationViews/ExploreCurationView.swift @@ -29,11 +29,10 @@ struct ExploreCurationView: View { .onAppear { shortcutsZipViewModel.personalCurations.removeAll() let personalCurationIDs = Set(shortcutsZipViewModel.shortcutsUserDownloaded.flatMap({ $0.curationIDs })) - print(personalCurationIDs) for curationID in personalCurationIDs { - print("\n\n\n\n\ncurationID: \(curationID)") - shortcutsZipViewModel.personalCurations.append(shortcutsZipViewModel.userCurations.first(where: { $0.id == curationID})!) - print(shortcutsZipViewModel.personalCurations) + if let curation = shortcutsZipViewModel.userCurations.first(where: { $0.id == curationID }) { + shortcutsZipViewModel.personalCurations.append(curation) + } } } .padding(.bottom, 32) From 95c7e2aff47fc4a89835bcfacfddb8b1777a6a57 Mon Sep 17 00:00:00 2001 From: "Elie (Jeon Jimin)" Date: Wed, 23 Nov 2022 15:16:59 +0900 Subject: [PATCH 18/19] [Style] change Shortcut Cell interval in ReadCurationView --- .../ReadAdminCurationView.swift | 14 +++++++------ .../ReadUserCurationView.swift | 21 +++++++++++-------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/HappyAnding/HappyAnding/Views/ExploreCurationViews/ReadAdminCurationView.swift b/HappyAnding/HappyAnding/Views/ExploreCurationViews/ReadAdminCurationView.swift index f9592529..b973318c 100644 --- a/HappyAnding/HappyAnding/Views/ExploreCurationViews/ReadAdminCurationView.swift +++ b/HappyAnding/HappyAnding/Views/ExploreCurationViews/ReadAdminCurationView.swift @@ -43,12 +43,14 @@ struct ReadAdminCurationView: View { titleAndSubtitle .padding(.bottom, 8) - ForEach(Array(curation.shortcuts.enumerated()), id: \.offset) { index, shortcut in - let data = NavigationReadShortcutType(shortcutID: shortcut.id, - navigationParentView: .curations) - NavigationLink(value: data) { - ShortcutCell(shortcutCell: shortcut, - navigationParentView: .curations) + VStack(spacing: 0) { + ForEach(Array(curation.shortcuts.enumerated()), id: \.offset) { index, shortcut in + let data = NavigationReadShortcutType(shortcutID: shortcut.id, + navigationParentView: .curations) + NavigationLink(value: data) { + ShortcutCell(shortcutCell: shortcut, + navigationParentView: .curations) + } } } diff --git a/HappyAnding/HappyAnding/Views/ExploreCurationViews/ReadUserCurationView.swift b/HappyAnding/HappyAnding/Views/ExploreCurationViews/ReadUserCurationView.swift index 52193ac2..2735f18f 100644 --- a/HappyAnding/HappyAnding/Views/ExploreCurationViews/ReadUserCurationView.swift +++ b/HappyAnding/HappyAnding/Views/ExploreCurationViews/ReadUserCurationView.swift @@ -34,7 +34,7 @@ struct ReadUserCurationView: View { } .frame(minHeight: 371) - VStack{ + VStack { userInformation .padding(.top, 103) .padding(.bottom, 22) @@ -44,16 +44,19 @@ struct ReadUserCurationView: View { .padding(.bottom, 12) } } - ForEach(Array(self.data.userCuration.shortcuts.enumerated()), id: \.offset) { index, shortcut in - let data = NavigationReadShortcutType(shortcutID: shortcut.id, - navigationParentView: self.data.navigationParentView) - - NavigationLink(value: data) { - ShortcutCell(shortcutCell: shortcut, - navigationParentView: self.data.navigationParentView) - .padding(.bottom, index == self.data.userCuration.shortcuts.count - 1 ? 44 : 0) + VStack(spacing: 0){ + ForEach(Array(self.data.userCuration.shortcuts.enumerated()), id: \.offset) { index, shortcut in + let data = NavigationReadShortcutType(shortcutID: shortcut.id, + navigationParentView: self.data.navigationParentView) + + NavigationLink(value: data) { + ShortcutCell(shortcutCell: shortcut, + navigationParentView: self.data.navigationParentView) + .padding(.bottom, index == self.data.userCuration.shortcuts.count - 1 ? 44 : 0) + } } } + } .onChange(of: isWriting) { _ in if !isWriting { From b3cf8c37d116512748ee550e71d8b1d41668b943 Mon Sep 17 00:00:00 2001 From: otoolz Date: Wed, 23 Nov 2022 15:38:00 +0900 Subject: [PATCH 19/19] =?UTF-8?q?[HOTFIX]=20merge=20error=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit merge error 수정 --- .../Views/ExploreCurationViews/ListCurationView.swift | 9 --------- 1 file changed, 9 deletions(-) diff --git a/HappyAnding/HappyAnding/Views/ExploreCurationViews/ListCurationView.swift b/HappyAnding/HappyAnding/Views/ExploreCurationViews/ListCurationView.swift index 3b394c95..2fe30d0c 100644 --- a/HappyAnding/HappyAnding/Views/ExploreCurationViews/ListCurationView.swift +++ b/HappyAnding/HappyAnding/Views/ExploreCurationViews/ListCurationView.swift @@ -73,15 +73,6 @@ struct ListCurationView: View { .navigationBarTitleDisplayMode(.inline) } - .scrollIndicators(.hidden) - .navigationDestination(for: NavigationReadUserCurationType.self) { data in - ReadUserCurationView(data: data) - } - .listStyle(.plain) - .background(Color.Background.ignoresSafeArea(.all, edges: .all)) - .scrollContentBackground(.hidden) - .navigationBarTitle("\(shortcutsZipViewModel.userInfo?.nickname ?? "")\(self.data.type.rawValue)") - .navigationBarTitleDisplayMode(.inline) } }