diff --git a/HappyAnding/HappyAnding/Extensions/View/View+Navigation.swift b/HappyAnding/HappyAnding/Extensions/View/View+Navigation.swift index f36e8a5e..56e03800 100644 --- a/HappyAnding/HappyAnding/Extensions/View/View+Navigation.swift +++ b/HappyAnding/HappyAnding/Extensions/View/View+Navigation.swift @@ -115,8 +115,8 @@ struct NavigationViewModifier: ViewModifier { func body(content: Content) -> some View { content - .navigationDestination(for: User?.self) { data in - ShowProfileView(viewModel: ShowProfileViewModel(data: data ?? User())) + .navigationDestination(for: User.self) { data in + ShowProfileView(viewModel: ShowProfileViewModel(data: data)) } .navigationDestination(for: Curation.self) { data in ReadCurationView(viewModel: ReadCurationViewModel(data: data)) diff --git a/HappyAnding/HappyAnding/ViewModel/ReadShortcutViewModel.swift b/HappyAnding/HappyAnding/ViewModel/ReadShortcutViewModel.swift index 55f4f8e0..eb9e8fcc 100644 --- a/HappyAnding/HappyAnding/ViewModel/ReadShortcutViewModel.swift +++ b/HappyAnding/HappyAnding/ViewModel/ReadShortcutViewModel.swift @@ -13,7 +13,7 @@ final class ReadShortcutViewModel: ObservableObject { @Published private(set) var shortcut: Shortcuts - /// ReadShortcutView + // ReadShortcutView @Published var isDeletingShortcut = false @Published var isEditingShortcut = false @Published var isUpdatingShortcut = false @@ -32,32 +32,39 @@ final class ReadShortcutViewModel: ObservableObject { @Published var isEditingComment = false @Published var isUndoingCommentEdit = false - /// ReadShortcutViewHeader - @Published var userInformation: User? = nil + // ReadShortcutViewHeader + @Published var userInformation: User @Published var numberOfLike = 0 @Published private(set) var userGrade = Image(systemName: "person.crop.circle.fill") - /// ReadShortcutCommentView + // ReadShortcutCommentView @Published var isDeletingComment = false @Published var deletedComment = Comment(user_nickname: "", user_id: "", date: "", depth: 0, contents: "") - /// UpdateShortcutView + // UpdateShortcutView @Published var updatedLink = "" @Published var updateDescription = "" @Published var isLinkValid = false @Published var isDescriptionValid = false init(data: Shortcuts) { + self.userInformation = User() self.shortcut = shortcutsZipViewModel.fetchShortcutDetail(id: data.id) ?? data self.isMyLike = shortcutsZipViewModel.checkLikedShortrcut(shortcutID: data.id) self.isMyFirstLike = isMyLike self.comments = shortcutsZipViewModel.fetchComment(shortcutID: data.id) - shortcutsZipViewModel.fetchUser(userID: data.author, + self.numberOfLike = data.numberOfLike + fetchUser() + } + + private func fetchUser() { + shortcutsZipViewModel.fetchUser(userID: shortcut.author, isCurrentUser: false) { user in self.userInformation = user + let grade = self.shortcutsZipViewModel.checkShortcutGrade(userID: self.userInformation.id) + let image = self.shortcutsZipViewModel.fetchShortcutGradeImage(isBig: false, shortcutGrade: grade) + self.userGrade = image } - self.userGrade = shortcutsZipViewModel.fetchShortcutGradeImage(isBig: false, shortcutGrade: shortcutsZipViewModel.checkShortcutGrade(userID: userInformation?.id ?? "!")) - self.numberOfLike = data.numberOfLike } func checkIfDownloaded() { diff --git a/HappyAnding/HappyAnding/Views/Components/UserNameCell.swift b/HappyAnding/HappyAnding/Views/Components/UserNameCell.swift index ce0ce231..b0da346c 100644 --- a/HappyAnding/HappyAnding/Views/Components/UserNameCell.swift +++ b/HappyAnding/HappyAnding/Views/Components/UserNameCell.swift @@ -18,11 +18,11 @@ import SwiftUI - description: - 해당 뷰는 넓이가 부모 프레임에 꽉차도록 만들어졌습니다. 여백이 필요한 경우 부모프레임 또는 해당 뷰를 불러온 후 설정해주세요. - + */ struct UserNameCell: View { - var userInformation: User? - var gradeImage: Image? + var userInformation: User + var gradeImage: Image var body: some View { HStack { @@ -31,7 +31,7 @@ struct UserNameCell: View { .frame(width: 24, height: 24) .foregroundColor(.gray3) - if let userInformation, !userInformation.nickname.isEmpty { + if !userInformation.nickname.isEmpty { Text(userInformation.nickname) .shortcutsZipBody2() .foregroundColor(.gray4) @@ -43,7 +43,7 @@ struct UserNameCell: View { Spacer() - if userInformation?.nickname != nil { + if !userInformation.id.isEmpty { Image(systemName: "chevron.right") .shortcutsZipFootnote() .foregroundColor(.gray4) @@ -57,12 +57,12 @@ struct UserNameCell: View { .foregroundColor(.gray1) ) .navigationLinkRouter(data: self.userInformation) - .disabled(self.userInformation == nil) + .disabled(self.userInformation.id.isEmpty) } } struct UserNameCell_Previews: PreviewProvider { static var previews: some View { - UserNameCell() + UserNameCell(userInformation: User(), gradeImage: Image(systemName: "person.crop.circle.fill")) } }