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 4 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
8 changes: 4 additions & 4 deletions HappyAnding/HappyAnding.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@
A31F1844292A637300AF4A82 /* Date+String.swift in Sources */ = {isa = PBXBuildFile; fileRef = F9CAEF822914855900224B0A /* Date+String.swift */; };
A31F1846292A638700AF4A82 /* (null) in Sources */ = {isa = PBXBuildFile; };
A31F1848292A64D700AF4A82 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 87E99C7128F94EA8009B691F /* Assets.xcassets */; };
A33F74AE2908D8C800B8D0D0 /* CheckBoxShortcutCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A33F74AD2908D8C800B8D0D0 /* CheckBoxShortcutCell.swift */; };
A3439AF529395A100043E273 /* UserAuth.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87E606B729114FB200C3DA13 /* UserAuth.swift */; };
A3439AF629395A3A0043E273 /* CustomTextEditor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87276C372933F6AB00C92F4C /* CustomTextEditor.swift */; };
A3439AFB2939B0E80043E273 /* UserDefaults+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3439AFA2939B0E80043E273 /* UserDefaults+Extension.swift */; };
Expand Down Expand Up @@ -124,6 +123,7 @@
F94B435F2907B19A00987819 /* FirebaseAuth in Frameworks */ = {isa = PBXBuildFile; productRef = F94B435E2907B19A00987819 /* FirebaseAuth */; };
F94B43612907B19A00987819 /* FirebaseFirestore in Frameworks */ = {isa = PBXBuildFile; productRef = F94B43602907B19A00987819 /* FirebaseFirestore */; };
F94B43632907B19A00987819 /* FirebaseFirestoreCombine-Community in Frameworks */ = {isa = PBXBuildFile; productRef = F94B43622907B19A00987819 /* FirebaseFirestoreCombine-Community */; };
F95F26542A45C89400B534EB /* WriteCurationViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F95F26532A45C89400B534EB /* WriteCurationViewModel.swift */; };
F96D45B72980301F000C2441 /* SubtitleTextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F96D45B62980301F000C2441 /* SubtitleTextView.swift */; };
F96D45BB29804057000C2441 /* EnvironmentValues+Alerter.swift in Sources */ = {isa = PBXBuildFile; fileRef = F96D45BA29804057000C2441 /* EnvironmentValues+Alerter.swift */; };
F96D45BD29816578000C2441 /* StickyHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = F96D45BC29816578000C2441 /* StickyHeader.swift */; };
Expand Down Expand Up @@ -250,7 +250,6 @@
A0DD085629276608008177BB /* URL+DeepLink.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "URL+DeepLink.swift"; sourceTree = "<group>"; };
A0F822AB2910B8F100AF4448 /* ShortcutsZipViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShortcutsZipViewModel.swift; sourceTree = "<group>"; };
A0F822B629164D2300AF4448 /* ListCategoryShortcutView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListCategoryShortcutView.swift; sourceTree = "<group>"; };
A33F74AD2908D8C800B8D0D0 /* CheckBoxShortcutCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckBoxShortcutCell.swift; sourceTree = "<group>"; };
A3439AFA2939B0E80043E273 /* UserDefaults+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UserDefaults+Extension.swift"; sourceTree = "<group>"; };
A34BF82729AF3D55009BC946 /* AnnouncementCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnnouncementCell.swift; sourceTree = "<group>"; };
A34BF82C29AFC34F009BC946 /* AboutShortcutGradeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AboutShortcutGradeView.swift; sourceTree = "<group>"; };
Expand All @@ -277,6 +276,7 @@
F91F09DC29AE012600E04FA0 /* ShortcutGrade.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShortcutGrade.swift; sourceTree = "<group>"; };
F91F09DE29AE0B5E00E04FA0 /* GradeAlertView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GradeAlertView.swift; sourceTree = "<group>"; };
F94B432D2907088400987819 /* UserCurationListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserCurationListView.swift; sourceTree = "<group>"; };
F95F26532A45C89400B534EB /* WriteCurationViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WriteCurationViewModel.swift; sourceTree = "<group>"; };
F96D45B62980301F000C2441 /* SubtitleTextView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubtitleTextView.swift; sourceTree = "<group>"; };
F96D45BA29804057000C2441 /* EnvironmentValues+Alerter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "EnvironmentValues+Alerter.swift"; sourceTree = "<group>"; };
F96D45BC29816578000C2441 /* StickyHeader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StickyHeader.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -471,7 +471,6 @@
children = (
87E99CB028FFF273009B691F /* WriteCurationSetView.swift */,
87E99CB428FFF282009B691F /* WriteCurationInfoView.swift */,
A33F74AD2908D8C800B8D0D0 /* CheckBoxShortcutCell.swift */,
);
path = WriteCurationViews;
sourceTree = "<group>";
Expand Down Expand Up @@ -596,6 +595,7 @@
A0F822AB2910B8F100AF4448 /* ShortcutsZipViewModel.swift */,
4D61A766291E1EE8000EF531 /* NavigationViewModel.swift */,
F9AC2BB52935201C00165820 /* CheckUpdateVersion.swift */,
F95F26532A45C89400B534EB /* WriteCurationViewModel.swift */,
);
path = ViewModel;
sourceTree = "<group>";
Expand Down Expand Up @@ -863,6 +863,7 @@
87E99CD929042536009B691F /* SectionType.swift in Sources */,
872A7D8F2918393B004A05B8 /* PrivacyPolicyView.swift in Sources */,
A38115BA292B447D0043E8B8 /* ShortcutCardCell.swift in Sources */,
F95F26542A45C89400B534EB /* WriteCurationViewModel.swift in Sources */,
8792479B291BDF820040D5C3 /* SearchView.swift in Sources */,
A3FF018E291ACFA500384211 /* WithdrawalView.swift in Sources */,
4D778A34290A53BA00C15AC4 /* UIApplication+Keyboard.swift in Sources */,
Expand Down Expand Up @@ -899,7 +900,6 @@
F99569182901DC4D0060AAEF /* UIFont+Extension.swift in Sources */,
F91A72C32999160E00CA135A /* Alerter.swift in Sources */,
87E99CAD28FFF261009B691F /* ReadShortcutView.swift in Sources */,
A33F74AE2908D8C800B8D0D0 /* CheckBoxShortcutCell.swift in Sources */,
87E606B22910649B00C3DA13 /* SignInWithAppleView.swift in Sources */,
F91F09DF29AE0B5E00E04FA0 /* GradeAlertView.swift in Sources */,
87E99CEC29080C30009B691F /* Curation.swift in Sources */,
Expand Down
4 changes: 2 additions & 2 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)
default:
EmptyView()
}
Expand Down
93 changes: 93 additions & 0 deletions HappyAnding/HappyAnding/ViewModel/WriteCurationViewModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
//
// WriteCurationViewModel.swift
// HappyAnding
//
// Created by JeonJimin on 2023/06/23.
//

import SwiftUI

final class WriteCurationViewModel: ObservableObject, Hashable {

static func == (lhs: WriteCurationViewModel, rhs: WriteCurationViewModel) -> Bool {
return false
}
func hash(into hasher: inout Hasher) {
hasher.combine(curation)
}

private var shortcutsZipViewModel = ShortcutsZipViewModel.share

//WriteCurationSet
@Published var isWriting = false
@Published var isEdit = false

//좋아요 + 내가 작성한 단축어 목록
@Published var shortcutCells = [ShortcutCellModel]()
//CheckboxShortcutCell 선택 여부 저장
@Published var isShortcutsTapped: [Bool] = []

//모음집 편집 시 전달받는 기존 모음집 정보
@Published var curation = Curation(title: "", subtitle: "", isAdmin: false, background: "", author: "", shortcuts: [ShortcutCellModel]())

@Published var isTappedQuestionMark = false
//기존 선택 -> 편집 시 선택 해제 되어 기존 모음집 정보에서 삭제해야할 단축어 배열
@Published var deletedShortcutCells = [ShortcutCellModel]()


//WriteCurationInfo
@Published var writeCurationNavigation = WriteCurationNavigation()
@Published var isValidTitle = false
@Published var isValidDescription = false

var isIncomplete: Bool {
!(isValidTitle && isValidDescription)
}

init() { }

init(data: Curation) {
self.curation = data
}

func fetchMakeCuration() {
shortcutCells = shortcutsZipViewModel.fetchShortcutMakeCuration().sorted { $0.title < $1.title }
if isEdit {
deletedShortcutCells = curation.shortcuts
}

//isShortcutsTapped 초기화
isShortcutsTapped = [Bool](repeating: false, count: shortcutCells.count)
for shortcut in curation.shortcuts {
if let index = shortcutCells.firstIndex(of: shortcut) {
isShortcutsTapped[index] = true
}
}
}

func addCuration() {
shortcutsZipViewModel.addCuration(curation: curation, isEdit: isEdit, deletedShortcutCells: deletedShortcutCells)

self.isWriting.toggle()
if #available(iOS 16.1, *) {
writeCurationNavigation.navigationPath = .init()
}
}

func checkboxCellTapGesture(index: Int) {
if isShortcutsTapped[index] {
isShortcutsTapped[index] = false
// TODO: 현재는 name을 기준으로 검색중, id로 검색해서 삭제해야함 / Shortcuts 자체를 배열에 저장해야함

if let firstIndex = curation.shortcuts.firstIndex(of: shortcutCells[index]) {
curation.shortcuts.remove(at: firstIndex)
}
}
else {
if curation.shortcuts.count < 10 {
curation.shortcuts.append(shortcutCells[index])
isShortcutsTapped[index] = true
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,10 @@ struct UserCurationListView: View {

@ViewBuilder
private func writeCurationView() -> some View {
WriteCurationSetView(isWriting: $isWriting
, isEdit: false
)
.navigationDestination(for: WriteCurationInfoType.self) { data in
WriteCurationInfoView(data: data, isWriting: $isWriting)
}
WriteCurationSetView(viewModel: WriteCurationViewModel())
.navigationDestination(for: WriteCurationViewModel.self) { data in
WriteCurationInfoView(viewModel: data)
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,9 @@ extension ReadCurationView {

@ViewBuilder
private func editView() -> some View {
WriteCurationSetView(isWriting: $isWriting,
curation: shortcutsZipViewModel.userCurations[index]
,isEdit: true
)
.navigationDestination(for: WriteCurationInfoType.self) { data in
WriteCurationInfoView(data: data, isWriting: $isWriting)
WriteCurationSetView(viewModel: WriteCurationViewModel(data: data.curation))
.navigationDestination(for: WriteCurationViewModel.self) { data in
WriteCurationInfoView(viewModel: data)
}
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,10 @@
import SwiftUI

struct WriteCurationInfoView: View {

@EnvironmentObject var shortcutsZipViewModel: ShortcutsZipViewModel
@EnvironmentObject var writeCurationNavigation: WriteCurationNavigation
@StateObject var viewModel: WriteCurationViewModel

@FocusState var isDescriptionFieldFocused: Bool

@State var data: WriteCurationInfoType
@Binding var isWriting: Bool

@State var isValidTitle = false
@State var isValidDescription = false

private var isIncomplete: Bool {
!(isValidTitle && isValidDescription)
}

var body: some View {
VStack(spacing: 24) {
ProgressView(value: 2, total: 2)
Expand All @@ -34,8 +22,8 @@ struct WriteCurationInfoView: View {
placeholder: TextLiteral.writeCurationInfoViewNamePlaceholder,
lengthLimit: 20,
isDownloadLinkTextField: false,
content: $data.curation.title,
isValid: $isValidTitle)
content: $viewModel.curation.title,
isValid: $viewModel.isValidTitle)
.padding(.top, 12)
.onSubmit {
isDescriptionFieldFocused = true
Expand All @@ -49,9 +37,8 @@ struct WriteCurationInfoView: View {
lengthLimit: 40,
isDownloadLinkTextField: false,
inputHeight: 72,
content: Binding(get: {data.curation.subtitle},
set: {data.curation.subtitle = $0}),
isValid: $isValidDescription)
content: $viewModel.curation.subtitle,
isValid: $viewModel.isValidDescription)
.focused($isDescriptionFieldFocused)

Spacer()
Expand All @@ -60,23 +47,17 @@ struct WriteCurationInfoView: View {
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
Button {

shortcutsZipViewModel.addCuration(curation: data.curation, isEdit: data.isEdit, deletedShortcutCells: data.deletedShortcutCells)

self.isWriting.toggle()
if #available(iOS 16.1, *) {
writeCurationNavigation.navigationPath = .init()
}
viewModel.addCuration()
} label: {
Text(TextLiteral.upload)
.shortcutsZipHeadline()
.foregroundColor(isIncomplete ? .shortcutsZipPrimary.opacity(0.3) : .shortcutsZipPrimary)
.foregroundColor(viewModel.isIncomplete ? .shortcutsZipPrimary.opacity(0.3) : .shortcutsZipPrimary)
}
.disabled(isIncomplete)
.disabled(viewModel.isIncomplete)
}
}
.background(Color.shortcutsZipBackground)
.navigationBarTitle(data.isEdit ? TextLiteral.writeCurationInfoViewEdit : TextLiteral.wrietCurationInfoViewPost)
.navigationBarTitle(viewModel.isEdit ? TextLiteral.writeCurationInfoViewEdit : TextLiteral.wrietCurationInfoViewPost)
.onAppear(perform : UIApplication.shared.hideKeyboard)
}
}
Loading