-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #469 from DeveloperAcademy-POSTECH/feature/468-rea…
…dCuratoinViewModel [Feat] Explore curatoin view model 적용
- Loading branch information
Showing
19 changed files
with
301 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
HappyAnding/HappyAnding/ViewModel/ExploreCurationViewModels/ExploreCurationViewModel.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
HappyAnding/HappyAnding/ViewModel/ExploreCurationViewModels/ListCurationViewModel.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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("단축어") ? "가" : "이") 없어요" | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
HappyAnding/HappyAnding/ViewModel/ExploreCurationViewModels/ReadCurationViewModel.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.