-
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.
- 섹션 접힘 유무 UserDefaults 저장 - 섹션 최대 노출 셀 수 변경
- Loading branch information
Showing
4 changed files
with
93 additions
and
49 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
50 changes: 50 additions & 0 deletions
50
HappyAnding/HappyAnding/ViewModel/MyPageViewModels/MyPageViewModel.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,50 @@ | ||
// | ||
// MyPageViewModel.swift | ||
// HappyAnding | ||
// | ||
// Created by JeonJimin on 4/15/24. | ||
// | ||
|
||
import Foundation | ||
import Combine | ||
|
||
final class MyPageViewModel: ObservableObject { | ||
private let shortcutsZipViewModel = ShortcutsZipViewModel.share | ||
private var cancellables = Set<AnyCancellable>() | ||
|
||
@Published var myShortcuts: [Shortcuts] = [] | ||
@Published var myDownloadShortcuts: [Shortcuts] = [] | ||
@Published var myLovingShortcuts: [Shortcuts] = [] | ||
|
||
@Published var isMyDownloadShortcutFolded = false { | ||
didSet { | ||
UserDefaults.standard.set(isMyDownloadShortcutFolded, forKey: "isMyDownloadShortcutFolded") | ||
} | ||
} | ||
@Published var isMyLovingShortcutFolded = false { | ||
didSet { | ||
UserDefaults.standard.set(isMyLovingShortcutFolded, forKey: "isMyLovingShortcutFolded") | ||
} | ||
} | ||
|
||
init() { | ||
shortcutsZipViewModel.$shortcutsMadeByUser | ||
.sink { [weak self] in self?.myShortcuts = $0 } | ||
.store(in: &cancellables) | ||
|
||
shortcutsZipViewModel.$shortcutsUserDownloaded | ||
.sink { [weak self] in self?.myDownloadShortcuts = $0 } | ||
.store(in: &cancellables) | ||
|
||
shortcutsZipViewModel.$shortcutsUserLiked | ||
.sink { [weak self] in self?.myLovingShortcuts = $0 } | ||
.store(in: &cancellables) | ||
|
||
self.isMyDownloadShortcutFolded = UserDefaults.standard.bool(forKey: "isMyDownloadShortcutFolded") | ||
self.isMyLovingShortcutFolded = UserDefaults.standard.bool(forKey: "isMyLovingShortcutFolded") | ||
} | ||
|
||
func fetchUserInfo() -> String { | ||
shortcutsZipViewModel.userInfo?.nickname ?? TextLiteral.defaultUser | ||
} | ||
} |
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