-
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.
[Feat] #470 - WriteCurationViewModel 생성
- 변수 위치 수정 - NavigationStack 변수 타입 변경 -> WriteCurationViewModel.Self todo: - CheckBoxShortcutCell 합치기 - 좋아요&작성한 단축어 정렬 확인하기
- Loading branch information
Showing
7 changed files
with
103 additions
and
81 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
67 changes: 67 additions & 0 deletions
67
HappyAnding/HappyAnding/ViewModel/WriteCurationViewModel.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,67 @@ | ||
// | ||
// 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]() | ||
//모음집 편집 시 전달받는 기존 모음집 정보 | ||
@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 | ||
} | ||
} | ||
|
||
func addCuration() { | ||
shortcutsZipViewModel.addCuration(curation: curation, isEdit: isEdit, deletedShortcutCells: deletedShortcutCells) | ||
|
||
self.isWriting.toggle() | ||
if #available(iOS 16.1, *) { | ||
writeCurationNavigation.navigationPath = .init() | ||
} | ||
} | ||
} |
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