Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[Feat] Explore curatoin view model 적용 #469

Merged
merged 14 commits into from
Jul 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions HappyAnding/HappyAnding.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@
8786B33C29ABA588000B46A1 /* View+Gesture.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8786B33B29ABA588000B46A1 /* View+Gesture.swift */; };
8786B33E29ABA5A9000B46A1 /* View+Shape.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8786B33D29ABA5A9000B46A1 /* View+Shape.swift */; };
8788374A2920D549009B3F54 /* Binding+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 878837492920D549009B3F54 /* Binding+Extension.swift */; };
8788E19D2A475AB3007C3852 /* ListCurationViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8788E19C2A475AB3007C3852 /* ListCurationViewModel.swift */; };
8788E1A02A48408F007C3852 /* ExploreCurationViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8788E19F2A48408F007C3852 /* ExploreCurationViewModel.swift */; };
8792478D2918CE450040D5C3 /* UINavigationContoller+Gesture.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8792478C2918CE450040D5C3 /* UINavigationContoller+Gesture.swift */; };
8792479B291BDF820040D5C3 /* SearchView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8792479A291BDF820040D5C3 /* SearchView.swift */; };
8795A170292AB945004B765F /* UIScreen+Size.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8795A16F292AB945004B765F /* UIScreen+Size.swift */; };
87B47F3B2A3DC2740009E75F /* ReadCurationViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87B47F3A2A3DC2740009E75F /* ReadCurationViewModel.swift */; };
87CFD8492939187200F97B86 /* NicknameTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87CFD8482939187200F97B86 /* NicknameTextField.swift */; };
87DBFB062A2127C0000CC442 /* CheckVersionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87DBFB052A2127C0000CC442 /* CheckVersionView.swift */; };
87E606B0291062F900C3DA13 /* AppleAuthCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87E606AF291062F900C3DA13 /* AppleAuthCoordinator.swift */; };
Expand Down Expand Up @@ -203,9 +206,12 @@
8786B33B29ABA588000B46A1 /* View+Gesture.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "View+Gesture.swift"; sourceTree = "<group>"; };
8786B33D29ABA5A9000B46A1 /* View+Shape.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "View+Shape.swift"; sourceTree = "<group>"; };
878837492920D549009B3F54 /* Binding+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Binding+Extension.swift"; sourceTree = "<group>"; };
8788E19C2A475AB3007C3852 /* ListCurationViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListCurationViewModel.swift; sourceTree = "<group>"; };
8788E19F2A48408F007C3852 /* ExploreCurationViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExploreCurationViewModel.swift; sourceTree = "<group>"; };
8792478C2918CE450040D5C3 /* UINavigationContoller+Gesture.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UINavigationContoller+Gesture.swift"; sourceTree = "<group>"; };
8792479A291BDF820040D5C3 /* SearchView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchView.swift; sourceTree = "<group>"; };
8795A16F292AB945004B765F /* UIScreen+Size.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIScreen+Size.swift"; sourceTree = "<group>"; };
87B47F3A2A3DC2740009E75F /* ReadCurationViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReadCurationViewModel.swift; sourceTree = "<group>"; };
87CFD8482939187200F97B86 /* NicknameTextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NicknameTextField.swift; sourceTree = "<group>"; };
87DBFB052A2127C0000CC442 /* CheckVersionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckVersionView.swift; sourceTree = "<group>"; };
87E606AD2910623C00C3DA13 /* HappyAnding.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = HappyAnding.entitlements; sourceTree = "<group>"; };
Expand Down Expand Up @@ -356,6 +362,51 @@
path = View;
sourceTree = "<group>";
};
8788E19E2A483FDF007C3852 /* ExploreCurationViewModels */ = {
isa = PBXGroup;
children = (
87B47F3A2A3DC2740009E75F /* ReadCurationViewModel.swift */,
8788E19C2A475AB3007C3852 /* ListCurationViewModel.swift */,
8788E19F2A48408F007C3852 /* ExploreCurationViewModel.swift */,
);
path = ExploreCurationViewModels;
sourceTree = "<group>";
};
8788E1A12A484518007C3852 /* ExploreShortcutViewModels */ = {
isa = PBXGroup;
children = (
);
path = ExploreShortcutViewModels;
sourceTree = "<group>";
};
8788E1A22A484528007C3852 /* WriteShortcutViewModels */ = {
isa = PBXGroup;
children = (
);
path = WriteShortcutViewModels;
sourceTree = "<group>";
};
8788E1A32A484533007C3852 /* ReadShortcutViewModels */ = {
isa = PBXGroup;
children = (
);
path = ReadShortcutViewModels;
sourceTree = "<group>";
};
8788E1A42A484542007C3852 /* WriteCurationViewModels */ = {
isa = PBXGroup;
children = (
);
path = WriteCurationViewModels;
sourceTree = "<group>";
};
8788E1A52A48456E007C3852 /* MyPageViewModels */ = {
isa = PBXGroup;
children = (
);
path = MyPageViewModels;
sourceTree = "<group>";
};
87E606AE291062D300C3DA13 /* SignInViews */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -593,6 +644,12 @@
A0F822AA2910B8B900AF4448 /* ViewModel */ = {
isa = PBXGroup;
children = (
8788E1A12A484518007C3852 /* ExploreShortcutViewModels */,
8788E1A22A484528007C3852 /* WriteShortcutViewModels */,
8788E1A32A484533007C3852 /* ReadShortcutViewModels */,
8788E19E2A483FDF007C3852 /* ExploreCurationViewModels */,
8788E1A42A484542007C3852 /* WriteCurationViewModels */,
8788E1A52A48456E007C3852 /* MyPageViewModels */,
A0F822AB2910B8F100AF4448 /* ShortcutsZipViewModel.swift */,
4D61A766291E1EE8000EF531 /* NavigationViewModel.swift */,
F9AC2BB52935201C00165820 /* CheckUpdateVersion.swift */,
Expand Down Expand Up @@ -881,6 +938,7 @@
4D7D16072986BBD7008B3332 /* TextLiteral.swift in Sources */,
87E99CC128FFF2B5009B691F /* CategoryModalView.swift in Sources */,
87E606B829114FB200C3DA13 /* UserAuth.swift in Sources */,
8788E1A02A48408F007C3852 /* ExploreCurationViewModel.swift in Sources */,
8786B33E29ABA5A9000B46A1 /* View+Shape.swift in Sources */,
A3C404D62A23D0E800C3BA75 /* UpdateInfoView.swift in Sources */,
F91A72C1299915C500CA135A /* MoreCaptionTextView.swift in Sources */,
Expand All @@ -903,6 +961,7 @@
87E606B22910649B00C3DA13 /* SignInWithAppleView.swift in Sources */,
F91F09DF29AE0B5E00E04FA0 /* GradeAlertView.swift in Sources */,
87E99CEC29080C30009B691F /* Curation.swift in Sources */,
8788E19D2A475AB3007C3852 /* ListCurationViewModel.swift in Sources */,
F9136EB6293612310034AAB2 /* ShortcutsZipView.swift in Sources */,
87E99CB128FFF273009B691F /* WriteCurationSetView.swift in Sources */,
4D61A767291E1EE8000EF531 /* NavigationViewModel.swift in Sources */,
Expand All @@ -927,6 +986,7 @@
F9724BBF292755E400860F8A /* Comment.swift in Sources */,
87E99CA328FFF22E009B691F /* ExploreCurationView.swift in Sources */,
A0F822B729164D2300AF4448 /* ListCategoryShortcutView.swift in Sources */,
87B47F3B2A3DC2740009E75F /* ReadCurationViewModel.swift in Sources */,
872B5D3D2A2E0FF9008DCC57 /* CurationType.swift in Sources */,
4D3DBB88292E67E600DE8160 /* EditNicknameView.swift in Sources */,
87E99CE82907C6E6009B691F /* Shortcuts.swift in Sources */,
Expand Down
12 changes: 6 additions & 6 deletions HappyAnding/HappyAnding/Extensions/View/View+Navigation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ extension View {
ListShortcutView(data: data as! NavigationListShortcutType)
case is NavigationReadShortcutType:
ReadShortcutView(data: data as! NavigationReadShortcutType)
case is NavigationReadCurationType:
ReadCurationView(data: data as! NavigationReadCurationType)
case is Curation:
ReadCurationView(viewModel: ReadCurationViewModel(data: data as! Curation))
case is CurationType:
ListCurationView(curationType: data as! CurationType)
ListCurationView(viewModel: ListCurationViewModel(data: data as! CurationType))
case is NavigationProfile:
ShowProfileView(data: data as! NavigationProfile)
case is NavigationSearch:
Expand Down Expand Up @@ -118,11 +118,11 @@ struct NavigationViewModifier: ViewModifier {
.navigationDestination(for: NavigationProfile.self) { data in
ShowProfileView(data: data)
}
.navigationDestination(for: NavigationReadCurationType.self) { data in
ReadCurationView(data: data)
.navigationDestination(for: Curation.self) { data in
ReadCurationView(viewModel: ReadCurationViewModel(data: data))
}
.navigationDestination(for: CurationType.self) { data in
ListCurationView(curationType: data)
ListCurationView(viewModel: ListCurationViewModel(data: data))
}
.navigationDestination(for: NavigationReadShortcutType.self) { data in
ReadShortcutView(data: data)
Expand Down
22 changes: 22 additions & 0 deletions HappyAnding/HappyAnding/Model/Curation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,28 @@ struct Curation: Identifiable, Equatable, Codable, Hashable {
let data = (try? JSONEncoder().encode(self)) ?? Data()
return (try? JSONSerialization.jsonObject(with: data, options: .mutableContainers) as? [String: Any]) ?? [:]
}

init(title: String, subtitle: String, isAdmin: Bool, background: String, author: String, shortcuts: [ShortcutCellModel]) {
self.id = UUID().uuidString
self.title = title
self.subtitle = subtitle
self.dateTime = Date().getDate()
self.isAdmin = isAdmin
self.background = background
self.author = author
self.shortcuts = shortcuts
}

init() {
self.id = UUID().uuidString
self.title = ""
self.subtitle = ""
self.dateTime = Date().getDate()
self.isAdmin = false
self.background = ""
self.author = ""
self.shortcuts = []
}
}

struct ShortcutCellModel: Identifiable, Codable, Equatable, Hashable {
Expand Down
15 changes: 0 additions & 15 deletions HappyAnding/HappyAnding/Model/NavigationStackModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,6 @@ struct NavigationReadShortcutType: Identifiable, Hashable {
let navigationParentView: NavigationParentView
}

struct NavigationReadCurationType: Identifiable, Hashable {
var id = UUID().uuidString

var isAdmin: Bool = false
let curation: Curation
let navigationParentView: NavigationParentView
}

struct NavigationListCurationType: Identifiable, Hashable {
var id = UUID().uuidString

var type: CurationType
let navigationParentView: NavigationParentView
}

struct NavigationProfile: Identifiable, Hashable {
var id = UUID().uuidString

Expand Down
14 changes: 14 additions & 0 deletions HappyAnding/HappyAnding/Model/User.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ struct User: Identifiable, Codable, Hashable {
let data = (try? JSONEncoder().encode(self)) ?? Data()
return (try? JSONSerialization.jsonObject(with: data, options: .mutableContainers) as? [String: Any]) ?? [:]
}

init() {
self.id = ""
self.nickname = ""
self.likedShortcuts = []
self.downloadedShortcuts = []
}

init(id: String, nickname: String, likedShortcuts: [String], downloadedShortcuts: [DownloadedShortcut]) {
self.id = id
self.nickname = nickname
self.likedShortcuts = likedShortcuts
self.downloadedShortcuts = downloadedShortcuts
}
}

struct DownloadedShortcut: Identifiable, Codable, Hashable {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// ExploreCurationViewModel.swift
// HappyAnding
//
// Created by 이지원 on 2023/06/25.
//

import Foundation

final class ExploreCurationViewModel: ObservableObject {
private let shortcutsZipViewModel = ShortcutsZipViewModel.share
@Published var adminCurationList = [Curation]()
@Published var personalCurationList = [Curation]()
@Published var userCurationList = [Curation]()

init() {
fetchAdminCurationList()
}

private func fetchAdminCurationList() {
self.adminCurationList = shortcutsZipViewModel.adminCurations
}

func getCurationList(with curationType: CurationType) -> [Curation] {
curationType.filterCuration(from: shortcutsZipViewModel)
}

func getSectionTitle(with curationType: CurationType) -> String {
switch curationType {
case .personalCuration:
return (shortcutsZipViewModel.userInfo?.nickname ?? "") + curationType.title
default:
return curationType.title
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// ListCurationViewModel.swift
// HappyAnding
//
// Created by 이지원 on 2023/06/25.
//

import Foundation

final class ListCurationViewModel: ObservableObject {
private let shortcutsZipViewModel = ShortcutsZipViewModel.share

@Published var curationType: CurationType
@Published private(set) var curationList = [Curation]()
@Published private(set) var sectionTitle: String = ""

init(data: CurationType) {
self.curationType = data
self.curationList = curationType.filterCuration(from: shortcutsZipViewModel)
self.sectionTitle = fetchSectionTitle()
print("new viewModel: ", curationType, curationList)
}

private func fetchSectionTitle() -> String {
switch curationType {
case .personalCuration:
return (shortcutsZipViewModel.userInfo?.nickname ?? "") + curationType.title
default:
return curationType.title
}
}

func getEmptyContentsWording() -> String {
"아직 \(sectionTitle)\(sectionTitle.contains("단축어") ? "가" : "이") 없어요"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//
// ReadCurationViewModel.swift
// HappyAnding
//
// Created by 이지원 on 2023/06/17.
//

import SwiftUI


final class ReadCurationViewModel: ObservableObject {
private let shortcutsZipViewModel = ShortcutsZipViewModel.share

@Published var isWriting = false
@Published var isTappedDeleteButton = false
@Published var curation: Curation
@Published private(set) var authInformation: User
@Published private(set) var gradeImage = Image(systemName: "person.crop.circle.fill")
@Published private(set) var isAdmin = false

init(data: Curation) {
self.curation = data
self.authInformation = User()
self.isAdmin = curation.isAdmin
fetchUserGrade()
}

private func fetchUserGrade() {
shortcutsZipViewModel.fetchUser(userID: curation.author,
isCurrentUser: false) { user in
self.authInformation = user
let grade = self.shortcutsZipViewModel.checkShortcutGrade(userID: self.authInformation.id)
let image = self.shortcutsZipViewModel.fetchShortcutGradeImage(isBig: false, shortcutGrade: grade)
self.gradeImage = image
}
}

func checkAuthor() -> Bool {
return curation.author == shortcutsZipViewModel.currentUser()
}

func deleteCuration() {
shortcutsZipViewModel.deleteData(model: curation)
shortcutsZipViewModel.curationsMadeByUser = shortcutsZipViewModel.curationsMadeByUser.filter { $0.id != curation.id }
}

func shareCuration() {
guard let deepLink = URL(string: "ShortcutsZip://myPage/CurationDetailView?curationID=\(curation.id)") else { return }

let activityVC = UIActivityViewController(activityItems: [deepLink], applicationActivities: nil)
let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene
guard let window = windowScene?.windows.first else { return }
window.rootViewController?.present(activityVC, animated: true, completion: nil)
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ class ShortcutsZipViewModel: ObservableObject {
@Published var shortcutsInCategory: [[Shortcuts]] = [[Shortcuts]].init(repeating: [], count: Category.allCases.count) // Category에서 사용할 숏컷 배열

@Published var curationsMadeByUser: [Curation] = [] // 유저가 만든 큐레이션배열
@Published var userCurations: [Curation] = []
@Published var userCurations: [Curation] = [] {
didSet {
self.refreshPersonalCurations()
}
}
@Published var personalCurations: [Curation] = [] // "땡땡님을 위한 모음집" 큐레이션배열
@Published var adminCurations: [Curation] = []

Expand Down
Loading