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] write curation view model #476

Closed
wants to merge 59 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
435e84c
[Style] #468 init 함수 생성
JIWON1923 Jun 18, 2023
784843a
[Feat] View Model 생성
JIWON1923 Jun 18, 2023
63370d5
[Refactor] Curation 데이터 활용
JIWON1923 Jun 18, 2023
94e3b87
[Style] #468 - 파일 명 수정
JIWON1923 Jun 25, 2023
400f320
[Feat] #472 - ListCurationViewModel 생성
JIWON1923 Jun 25, 2023
e37e624
[Feat] #472 - Explore Curation View Model 생성
JIWON1923 Jun 25, 2023
fe76a7c
[Feat] #472 - ViewModel 적용
JIWON1923 Jun 25, 2023
949476c
[Style] #472 - 뷰모델 폴더 구조 생성
JIWON1923 Jun 25, 2023
7a1afe9
[Feat] #472 - NavigationCurationType 삭제
JIWON1923 Jun 25, 2023
21f7f14
[Refactor] #468 - 코드리뷰 반영
JIWON1923 Jun 25, 2023
3a50e44
[Fix] #468 - 탈퇴한 회원 정보 오류 수정
JIWON1923 Jun 25, 2023
e01ab0d
[Feat] #470 - WriteCurationViewModel 생성
JMM00 Jun 25, 2023
d636f8d
[Feat] #470 - checkbox shortcut 뷰모델 연결
JMM00 Jun 30, 2023
aee2cbc
[Feat] #470 - checkboxCell 합치기.
JMM00 Jul 8, 2023
c2a2621
[Style] 불필요한 파일 삭제
JMM00 Jul 19, 2023
70cc4e0
Update HappyAnding/HappyAnding/ViewModel/ExploreCurationViewModels/Ex…
JIWON1923 Jul 22, 2023
0649903
[Refactor] #472 - Private
JIWON1923 Jul 22, 2023
4ecac9c
[Refactor] #472 - Private
JIWON1923 Jul 22, 2023
dc35877
Merge pull request #469 from DeveloperAcademy-POSTECH/feature/468-rea…
JIWON1923 Jul 22, 2023
7f322fa
[Feat] #473 - Add ShowProfileViewModel
jim4020key Jul 10, 2023
69a9c14
[Feat] #473 - Add ReadShortcutViewModel
jim4020key Jul 16, 2023
c39b1bd
[Feat] #473 - Add ReadShortcutViewModel to UpdateShortcutView
jim4020key Jul 16, 2023
30d6706
[Feat] #473 - Move properties to view model
jim4020key Jul 16, 2023
2d7c12b
[Feat] #473 - Sort comments
jim4020key Jul 16, 2023
2db1839
[Style] #473 - Fix typo
jim4020key Jul 16, 2023
ae563ed
[Feat] #473 - Add .onDisappear method
jim4020key Jul 20, 2023
ff46b6e
[Feat] #473 - Disable withdrawn user
jim4020key Jul 24, 2023
aedd754
[Feat] #473 - Add functions to ShowProfileViewModel
jim4020key Jul 24, 2023
597055d
[Style] #473 - Modify properties
jim4020key Jul 24, 2023
8172fa2
[Feat] #473 - Resolve Conflicts
jim4020key Jul 24, 2023
bf10a44
[Chore] #471 - Move ExploreShortcutView to the right folder
jim4020key Jun 24, 2023
f716f83
[Feat] #471 - Add ExploreShortcutViewModel
jim4020key Jun 30, 2023
2a5c32a
[Feat] #471 - Add ListShortcutViewModel
jim4020key Jun 30, 2023
d7a5c37
[Feat] #471 - Add ListCategoryShortcutViewModel
jim4020key Jun 30, 2023
b4317c4
[Feat] #471 - Remove NavigationListShortcutType
jim4020key Jun 30, 2023
526b90b
[Feat] #471 - Remove NavigationListCategoryShortcutType
jim4020key Jun 30, 2023
fa73943
[Style] #471 - Remove unused lines
jim4020key Jun 30, 2023
44476df
[Feat] #471 - Relocate property
jim4020key Jun 30, 2023
d51f2f4
[Feat] #471 - Set Access Modifiers
jim4020key Jul 24, 2023
8b51a77
[Chore] #471 - Change location of files
jim4020key Jul 24, 2023
6536aa1
[Style] #471 - Rename properties
jim4020key Jul 24, 2023
99f5b04
[Fix] #473 - Resolve warning
jim4020key Aug 12, 2023
2cd3a4b
Merge pull request #479 from DeveloperAcademy-POSTECH/feature/473-rea…
jim4020key Aug 12, 2023
ba2f9b6
[Chore] #471 - Resolve Conflicts
jim4020key Aug 12, 2023
d2c29f7
[Chore] #471 - Resolve Conflicts
jim4020key Aug 12, 2023
bf2a253
Merge branch 'develop' into feature/471-exploreshortcutviewmodel
jim4020key Aug 12, 2023
909dc74
Merge pull request #480 from DeveloperAcademy-POSTECH/feature/471-exp…
jim4020key Aug 12, 2023
bcb0803
[Feat] #470 - WriteCurationViewModel 생성
JMM00 Jun 25, 2023
b1ebefa
[Feat] #470 - checkbox shortcut 뷰모델 연결
JMM00 Jun 30, 2023
46cf7ce
[Feat] #470 - checkboxCell 합치기.
JMM00 Jul 8, 2023
45d051a
[Style] 불필요한 파일 삭제
JMM00 Jul 19, 2023
82cebc1
Merge branch 'feature/470-writeCurationViewModel' of https://github.c…
JMM00 Aug 13, 2023
caf5adf
[Feat] #470 - isWriting 연결
JMM00 Aug 13, 2023
89eff63
[Style] 불필요한 부분 삭제
JMM00 Aug 13, 2023
20b0b76
[Feat] #470 - userCurationCell 업데이트 함수 추가
JMM00 Aug 13, 2023
7f5e7e6
[Feat] #470 - userCurationCell의 curation을 Binding으로 변경
JMM00 Aug 13, 2023
788e06b
[Fix] resolve error
JMM00 Aug 13, 2023
a98e568
[Feat] #470 - 네비게이션 초기화 추가
JMM00 Aug 13, 2023
a53867b
[Fix] resolve update NavigationAuthority bound path tried to update m…
JMM00 Aug 13, 2023
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
96 changes: 88 additions & 8 deletions HappyAnding/HappyAnding.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

48 changes: 24 additions & 24 deletions HappyAnding/HappyAnding/Extensions/View/View+Navigation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ extension View {
@ViewBuilder
func getDestination<T: Hashable>(data: T, isPresented: Binding<Bool>) -> some View {
switch data {
case is WriteCurationInfoType:
WriteCurationInfoView(data: data as! WriteCurationInfoType, isWriting: isPresented)
case is WriteCurationViewModel:
WriteCurationInfoView(viewModel: data as! WriteCurationViewModel, isWriting: isPresented)
default:
EmptyView()
}
Expand All @@ -77,20 +77,20 @@ extension View {
@ViewBuilder
func getDestination<T: Hashable>(data: T) -> some View {
switch data {
case is NavigationListShortcutType:
ListShortcutView(data: data as! NavigationListShortcutType)
case is NavigationReadShortcutType:
ReadShortcutView(data: data as! NavigationReadShortcutType)
case is NavigationReadCurationType:
ReadCurationView(data: data as! NavigationReadCurationType)
case is SectionType:
ListShortcutView(viewModel: ListShortcutViewModel(data: data as! SectionType))
case is Shortcuts:
ReadShortcutView(viewModel: ReadShortcutViewModel(data: data as! Shortcuts))
case is Curation:
ReadCurationView(viewModel: ReadCurationViewModel(data: data as! Curation))
case is CurationType:
ListCurationView(curationType: data as! CurationType)
case is NavigationProfile:
ShowProfileView(data: data as! NavigationProfile)
ListCurationView(viewModel: ListCurationViewModel(data: data as! CurationType))
case is User:
ShowProfileView(viewModel: ShowProfileViewModel(data: data as! User))
case is NavigationSearch:
SearchView()
case is NavigationListCategoryShortcutType:
ListCategoryShortcutView(data: data as! NavigationListCategoryShortcutType)
case is Category:
ListCategoryShortcutView(viewModel: ListCategoryShortcutViewModel(data: data as! Category))
case is NavigationNicknameView:
EditNicknameView()
case is NavigationSettingView:
Expand All @@ -115,23 +115,23 @@ struct NavigationViewModifier: ViewModifier {
func body(content: Content) -> some View {
content

.navigationDestination(for: NavigationProfile.self) { data in
ShowProfileView(data: data)
.navigationDestination(for: User.self) { data in
ShowProfileView(viewModel: ShowProfileViewModel(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)
.navigationDestination(for: Shortcuts.self) { data in
ReadShortcutView(viewModel: ReadShortcutViewModel(data: data))
}
.navigationDestination(for: NavigationListShortcutType.self) { data in
ListShortcutView(data: data)
.navigationDestination(for: SectionType.self) { data in
ListShortcutView(viewModel: ListShortcutViewModel(data: data))
}
.navigationDestination(for: NavigationListCategoryShortcutType.self) { data in
ListCategoryShortcutView(data: data)
.navigationDestination(for: Category.self) { data in
ListCategoryShortcutView(viewModel: ListCategoryShortcutViewModel(data: data))
}
.navigationDestination(for: NavigationLisence.self) { value in
LicenseView()
Expand Down
26 changes: 26 additions & 0 deletions HappyAnding/HappyAnding/Model/Comment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ struct Comments: Identifiable, Codable, Equatable {
let data = (try? JSONEncoder().encode(self)) ?? Data()
return (try? JSONSerialization.jsonObject(with: data, options: .mutableContainers) as? [String: Any]) ?? [:]
}

init() {
self.id = ""
self.comments = []
}

init(id: String, comments: [Comment]) {
self.id = id
self.comments = comments
}
}

struct Comment: Identifiable, Codable, Hashable {
Expand All @@ -25,6 +35,22 @@ struct Comment: Identifiable, Codable, Hashable {
var date: String //처음 작성한 날짜만 저장
var depth: Int //0이면 원댓글, 1이면 대댓글
var contents: String

init() {
self.user_nickname = ""
self.user_id = ""
self.date = ""
self.depth = 0
self.contents = ""
}

init(user_nickname: String, user_id: String, date: String, depth: Int, contents: String) {
self.user_nickname = user_nickname
self.user_id = user_id
self.date = date
self.depth = depth
self.contents = contents
}
}

extension Comments {
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
56 changes: 0 additions & 56 deletions HappyAnding/HappyAnding/Model/NavigationStackModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,61 +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

var shortcut: Shortcuts?
let shortcutID: String
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

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

var curation: Curation
var deletedShortcutCells: [ShortcutCellModel]
var isEdit: Bool
}

enum NavigationSearch: Hashable, Equatable {
case first
}
Expand All @@ -82,7 +27,6 @@ enum NavigationNicknameView: Hashable, Equatable {
case first
}


enum NavigationLisence: Hashable, Equatable {
case first
}
Expand Down
32 changes: 32 additions & 0 deletions HappyAnding/HappyAnding/Model/Shortcuts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,36 @@ struct Shortcuts: Identifiable, Codable, Equatable, Hashable {
let data = (try? JSONEncoder().encode(self)) ?? Data()
return (try? JSONSerialization.jsonObject(with: data, options: .mutableContainers) as? [String: Any]) ?? [:]
}

init() {
self.sfSymbol = ""
self.color = ""
self.title = ""
self.subtitle = ""
self.description = ""
self.category = []
self.requiredApp = []
self.numberOfLike = 0
self.numberOfDownload = 0
self.author = ""
self.shortcutRequirements = ""
self.downloadLink = []
self.curationIDs = []
}

init(sfSymbol: String, color: String, title: String, subtitle: String, description: String, category: [String], requiredApp: [String], numberOfLike: Int, numberOfDownload: Int, author: String, shortcutRequirements: String, downloadLink: [String], curationIDs: [String]) {
self.sfSymbol = sfSymbol
self.color = color
self.title = title
self.subtitle = subtitle
self.description = description
self.category = category
self.requiredApp = requiredApp
self.numberOfLike = numberOfLike
self.numberOfDownload = numberOfDownload
self.author = author
self.shortcutRequirements = shortcutRequirements
self.downloadLink = downloadLink
self.curationIDs = curationIDs
}
}
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("단축어") ? "가" : "이") 없어요"
}
}
Loading