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] MyPageView UI 구현 #530

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
Prev Previous commit
Next Next commit
[Feat] #524 - MyPageViewModel 적용
- 섹션 접힘 유무 UserDefaults 저장
- 섹션 최대 노출 셀 수 변경
  • Loading branch information
JMM00 committed Apr 20, 2024
commit 72a7d9a65ee5c26760b8b27266345f663cfd6327
12 changes: 12 additions & 0 deletions HappyAnding/HappyAnding.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
@@ -172,6 +172,7 @@
F9A86DA62A0B54ED00405E12 /* UserNameCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = F9A86DA52A0B54ED00405E12 /* UserNameCell.swift */; };
F9AC2BB62935201C00165820 /* CheckUpdateVersion.swift in Sources */ = {isa = PBXBuildFile; fileRef = F9AC2BB52935201C00165820 /* CheckUpdateVersion.swift */; };
F9AFF6E32A59153B00FFFFAD /* WriteShortcutViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F9AFF6E22A59153B00FFFFAD /* WriteShortcutViewModel.swift */; };
F9B99F262BCD73A10094F47B /* MyPageViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F9B99F252BCD73A10094F47B /* MyPageViewModel.swift */; };
F9BA11D329A389EA00176807 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = F9BA11D229A389EA00176807 /* GoogleService-Info.plist */; };
F9BA11D429A389EA00176807 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = F9BA11D229A389EA00176807 /* GoogleService-Info.plist */; };
F9CAEF832914855900224B0A /* Date+String.swift in Sources */ = {isa = PBXBuildFile; fileRef = F9CAEF822914855900224B0A /* Date+String.swift */; };
@@ -355,6 +356,7 @@
F9AC2BB52935201C00165820 /* CheckUpdateVersion.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckUpdateVersion.swift; sourceTree = "<group>"; };
F9AC2BB92935D34C00165820 /* Image+View.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Image+View.swift"; sourceTree = "<group>"; };
F9AFF6E22A59153B00FFFFAD /* WriteShortcutViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WriteShortcutViewModel.swift; sourceTree = "<group>"; };
F9B99F252BCD73A10094F47B /* MyPageViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyPageViewModel.swift; sourceTree = "<group>"; };
F9BA11D229A389EA00176807 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
F9CAEF822914855900224B0A /* Date+String.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Date+String.swift"; sourceTree = "<group>"; };
F9DB8EB82939853D00516CE1 /* ShareExtensionValidationTextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShareExtensionValidationTextField.swift; sourceTree = "<group>"; };
@@ -706,6 +708,7 @@
A0F822AA2910B8B900AF4448 /* ViewModel */ = {
isa = PBXGroup;
children = (
F9B99F242BCD738B0094F47B /* MyPageViewModels */,
8788E1A12A484518007C3852 /* ExploreShortcutViewModels */,
8788E1A32A484533007C3852 /* ReadShortcutViewModels */,
8788E19E2A483FDF007C3852 /* ExploreCurationViewModels */,
@@ -801,6 +804,14 @@
path = SettingViews;
sourceTree = "<group>";
};
F9B99F242BCD738B0094F47B /* MyPageViewModels */ = {
isa = PBXGroup;
children = (
F9B99F252BCD73A10094F47B /* MyPageViewModel.swift */,
);
path = MyPageViewModels;
sourceTree = "<group>";
};
F9DB8ECB293B30EC00516CE1 /* Recovered References */ = {
isa = PBXGroup;
children = (
@@ -1084,6 +1095,7 @@
F9136EB6293612310034AAB2 /* ShortcutsZipView.swift in Sources */,
87E99CB128FFF273009B691F /* WriteCurationSetView.swift in Sources */,
4D61A767291E1EE8000EF531 /* NavigationViewModel.swift in Sources */,
F9B99F262BCD73A10094F47B /* MyPageViewModel.swift in Sources */,
4D93D0752A61D0D10042CBA8 /* ReadShortcutViewModel.swift in Sources */,
F96D45BD29816578000C2441 /* StickyHeader.swift in Sources */,
87E99CEE29080D33009B691F /* User.swift in Sources */,
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
}
}
78 changes: 30 additions & 48 deletions HappyAnding/HappyAnding/Views/MyPageViews/MyPageView.swift
Original file line number Diff line number Diff line change
@@ -8,51 +8,29 @@
import SwiftUI

struct MyPageView: View {

@EnvironmentObject var shortcutsZipViewModel: ShortcutsZipViewModel

@AppStorage("useWithoutSignIn") var useWithoutSignIn: Bool = false

@State var isTappedUserGradeButton = false

@StateObject var viewModel: MyPageViewModel

var body: some View {
ScrollView {
ScrollView(showsIndicators: false) {
VStack(spacing: 12) {

//MARK: - 사용자 프로필
Button {
//프로필 설정 페이지 연걸
} label: {
HStack {
//TODO: 프로필 이미지 - 등급 시스템과 동일 추후 이미지 연결
Image("profile_ex")
.resizable()
.scaledToFit()
.frame(width: 96, height: 96)

VStack(spacing: 9) {
HStack {
//뱃지 영역 ExploreShortcutView 머지 후 Seal 이용하기
Image(systemName: "seal")
.resizable()
.scaledToFit()
.frame(width: 30)
Image(systemName: "seal")
.resizable()
.scaledToFit()
.frame(width: 30)
Image(systemName: "seal")
.resizable()
.scaledToFit()
.frame(width: 30)
Image(systemName: "seal")
.resizable()
.scaledToFit()
.frame(width: 30)
//TODO: 추가 예정 이미지 확정되면 넣기
}
.frame(maxWidth: .infinity, alignment: .leading)
Divider()
HStack {
Text(shortcutsZipViewModel.userInfo?.nickname ?? TextLiteral.defaultUser)
Text(viewModel.fetchUserInfo())
.frame(maxWidth: .infinity, alignment: .leading)
.foregroundStyle(SCZColor.Basic)
Image(systemName: "slider.horizontal.3")
@@ -69,18 +47,23 @@ struct MyPageView: View {
}
.padding(.horizontal, 16)

MyPageSection(type: .myShortcut, shortcuts: $shortcutsZipViewModel.shortcutsMadeByUser)
Divider()
.padding(.horizontal, 16)
.foregroundStyle(SCZColor.CharcoalGray.opacity08)
MyPageSection(type: .myDownloadShortcut, shortcuts: $shortcutsZipViewModel.shortcutsUserDownloaded)
Divider()
.padding(.horizontal, 16)
.foregroundStyle(SCZColor.CharcoalGray.opacity08)
MyPageSection(type: .myLovingShortcut, shortcuts: $shortcutsZipViewModel.shortcutsUserLiked)
Divider()
.padding(.horizontal, 16)
.foregroundStyle(SCZColor.CharcoalGray.opacity08)
MyPageSection(type: .myShortcut, shortcuts: $viewModel.myShortcuts, isFolded: .constant(false))

MyPageSection(type: .myDownloadShortcut, shortcuts: $viewModel.myDownloadShortcuts, isFolded: $viewModel.isMyDownloadShortcutFolded)

if viewModel.isMyDownloadShortcutFolded {
Divider()
.padding(.horizontal, 16)
.foregroundStyle(SCZColor.CharcoalGray.opacity08)
}

MyPageSection(type: .myLovingShortcut, shortcuts: $viewModel.myLovingShortcuts, isFolded: $viewModel.isMyLovingShortcutFolded)

if viewModel.isMyLovingShortcutFolded {
Divider()
.padding(.horizontal, 16)
.foregroundStyle(SCZColor.CharcoalGray.opacity08)
}
}
.padding(.bottom, 30)
.padding(.top, 12)
@@ -138,8 +121,7 @@ struct MyPageView: View {
struct MyPageSection: View {
let type: SectionType
@Binding var shortcuts: [Shortcuts]
@State var isFolded = false

@Binding var isFolded: Bool
var body: some View {

VStack(alignment: .leading, spacing: 0) {
@@ -171,9 +153,9 @@ struct MyPageSection: View {
}
}
.padding(.horizontal, 16)

let maxNum = shortcuts.count > 3 ? 2 : 3
if type == .myShortcut || !isFolded {
ScrollView(.horizontal, showsIndicators: false ) {
ScrollView(.horizontal, showsIndicators: false) {
HStack(spacing: 8) {
Rectangle()
.frame(width: 16)
@@ -189,17 +171,17 @@ struct MyPageSection: View {
.roundedBorder(cornerRadius: 16, color: .white, isNormalBlend: true, opacity: 0.12)
}

ForEach(shortcuts.prefix(5), id: \.self) { shortcut in
ForEach(shortcuts.prefix(maxNum), id: \.self) { shortcut in
OrderedCell(type: .myShortcut, index: 0, shortcut: shortcut)
}
if shortcuts.count > 5 {
if shortcuts.count > maxNum {
ExpandedCell(type: type, shortcuts: shortcuts)
}
} else {
ForEach(shortcuts.prefix(4), id: \.self) { shortcut in
ForEach(shortcuts.prefix(maxNum), id: \.self) { shortcut in
UnorderedCell(shortcut: shortcut)
}
if shortcuts.count > 4 {
if shortcuts.count > maxNum {
ExpandedCell(type: type, shortcuts: shortcuts)
}
}
Original file line number Diff line number Diff line change
@@ -137,7 +137,7 @@ struct ShortcutTabView: View {

@ViewBuilder
private func thirdTab() -> some View {
MyPageView()
MyPageView(viewModel: MyPageViewModel())
.modifierNavigation()
.navigationBarBackground ({ Color.shortcutsZipBackground })
.id(thirdTabID)