Skip to content

Commit

Permalink
[WEAV-122] Widget Service Add, Profile Widget 생성 API 연결, 뷰 정리
Browse files Browse the repository at this point in the history
  • Loading branch information
jisu15-kim committed Nov 14, 2024
1 parent 7e33230 commit 4fba3a7
Show file tree
Hide file tree
Showing 15 changed files with 112 additions and 15 deletions.
11 changes: 11 additions & 0 deletions Projects/Core/CommonKit/Sources/AppCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public final class AppCoordinator: ObservableObject {
}
}
}
startRefreshMyUserInfo()
}

@MainActor
Expand Down Expand Up @@ -108,4 +109,14 @@ public final class AppCoordinator: ObservableObject {
AuthState.change(.login)
}
}

// 20초마다 한번씩 refreshMyUserInfo() 를 호출
private func startRefreshMyUserInfo() {
Task {
while true {
try await Task.sleep(for: .seconds(20))
try await refreshMyUserInfo()
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "pencil.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "pencil@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "pencil@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "plus_circle_filled.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "plus_circle_filled@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "plus_circle_filled@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,41 @@
import SwiftUI
import CoreKit

public enum ProfileWidgetIconType {
case add
case edit

var image: Image {
switch self {
case .add: DesignCore.Images.plusCircleFilled.image
case .edit: DesignCore.Images.pencil1.image
}
}
}

public struct ProfileWidgetView: View {

public let title: String
public let bodyText: String
public let titleColor: Color
public let bodyColor: Color
public let gradientColors: [Color]
public var iconType: ProfileWidgetIconType?

public init(
title: String,
bodyText: String,
titleColor: Color,
bodyColor: Color,
gradientColors: [Color]
gradientColors: [Color],
iconType: ProfileWidgetIconType? = nil
) {
self.title = title
self.bodyText = bodyText
self.titleColor = titleColor
self.bodyColor = bodyColor
self.gradientColors = gradientColors
self.iconType = iconType
}

public var body: some View {
Expand All @@ -47,7 +62,11 @@ public struct ProfileWidgetView: View {
.pretendard(weight: ._600, size: 22)
.foregroundStyle(titleColor)
Spacer()
Image(systemName: "plus.circle")
if let iconType {
iconType.image
.resizable()
.frame(width: 22, height: 22)
}
}
Spacer()
ScrollView {
Expand Down
4 changes: 2 additions & 2 deletions Projects/Features/Home/Sources/HomeMain/HomeMainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ public struct HomeMainView: View {
Text(tab.title)
.typography(.en_medium_20)
.padding(.vertical, 12)

.foregroundColor(isSelected ? DesignCore.Colors.grey500 : DesignCore.Colors.grey500.opacity(0.2))
}
.padding(.top, 8)
}
}
}
Expand Down Expand Up @@ -82,7 +82,7 @@ public struct HomeMainView: View {
}
.ignoresSafeArea(.keyboard)
.textureBackground()
.setNavigation(showLeftBackButton: false) {}
.toolbar(.hidden, for: .navigationBar)
.setLoading(state.isLoading)
}
}
Expand Down
7 changes: 6 additions & 1 deletion Projects/Features/Home/Sources/Profile/ProfileIntent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ extension ProfileIntent {
protocol Intentable {
// content
func onTapNextButton()
func fetchUserInfo(_ userInfo: UserInfo)

// default
func onAppear()
Expand All @@ -46,7 +47,11 @@ extension ProfileIntent {
extension ProfileIntent: ProfileIntent.Intentable {
// default
func onAppear() {
model?.setUserInfo(input.userInfo)
fetchUserInfo(input.userInfo)
}

func fetchUserInfo(_ userInfo: UserInfo) {
model?.setUserInfo(userInfo)
}

func task() async {}
Expand Down
20 changes: 14 additions & 6 deletions Projects/Features/Home/Sources/Profile/ProfileView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,20 @@ public struct ProfileView: View {
RoundedRectangle(cornerRadius: 24)
.fill(.white)
ProfileWidgetView(
title: widget.widgetType.title,
title: widget.widgetType.title + widget.widgetType.emoji,
bodyText: widget.content,
titleColor: widget.widgetType.titleColor,
bodyColor: widget.widgetType.bodyColor,
gradientColors: widget.widgetType.gradationColors
gradientColors: widget.widgetType.gradationColors,
iconType: .edit
)
.padding(.all, 4)
}
.shadow(.default)
.onTapGesture {

}
.frame(minHeight: widgetSize)
}

ZStack {
Expand All @@ -150,10 +152,11 @@ public struct ProfileView: View {
Image(systemName: "plus")
.resizable()
.frame(width: 24, height: 24)
Text("프로필 위젯 추가하기")
Text("프로필 위젯\n추가하기")
.typography(.semibold_14)
}
.foregroundStyle(DesignCore.Colors.grey200)
.frame(minHeight: widgetSize)
}
.shadow(.default)
.onTapGesture {
Expand All @@ -164,11 +167,19 @@ public struct ProfileView: View {
}
.padding(.horizontal, 18)
.padding(.top, 36)
.padding(.bottom, 20)
}
} else {
ProgressView()
}
}
.onChange(of: isPresentWidgetSelectionView) {
if !isPresentWidgetSelectionView {
if let userInfo = AppCoordinator.shared.userInfo {
intent.fetchUserInfo(userInfo)
}
}
}
.sheet(
isPresented: $isPresentWidgetSelectionView,
content: {
Expand All @@ -186,9 +197,6 @@ public struct ProfileView: View {
}
.ignoresSafeArea(.all)
.textureBackground()
.setPopNavigation {
AppCoordinator.shared.pop()
}
.setLoading(state.isLoading)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,20 @@ public struct WidgetSelectionView: View {
.padding(.top, 20)
ScrollView {
LazyVGrid(columns: columns, spacing: 16) {
ForEach(WidgetType.allCases, id: \.self) { widget in
let totalWidgets = WidgetType.allCases
let userWidgets = AppCoordinator.shared.userInfo?.profileWidgets
.map { $0.widgetType } ?? []
let availableWidgets = totalWidgets
.filter { !userWidgets.contains($0) }

ForEach(availableWidgets, id: \.self) { widget in
ProfileWidgetView(
title: widget.title,
title: widget.title + widget.emoji,
bodyText: widget.exampleText,
titleColor: widget.titleColor,
bodyColor: widget.bodyColor,
gradientColors: widget.gradationColors
gradientColors: widget.gradationColors,
iconType: .add
)
.onTapGesture {
selectedWidget = widget
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ extension WidgetWritingIntent: WidgetWritingIntent.Intentable {
model?.setLoading(status: false)
model?.modalDismiss()
} catch {
print(error)
// TODO: 에러처리
model?.setLoading(status: false)
}
}
}
Expand Down

0 comments on commit 4fba3a7

Please sign in to comment.