From 8c38aac01511ff795391e61eb41244e691b02912 Mon Sep 17 00:00:00 2001 From: Hee Ju Jang <01kathyy@gmail.com> Date: Tue, 26 Mar 2024 16:06:27 +0900 Subject: [PATCH 01/15] [FEAT] HomeVM class --- HANE24.xcodeproj/project.pbxproj | 4 + HANE24/Model/JSONs.swift | 28 +++++++ HANE24/Model/Structs.swift | 5 ++ HANE24/View/Home/HomeView.swift | 2 +- HANE24/ViewModel/HaneVM.swift | 4 +- HANE24/ViewModel/HomeVM.swift | 103 ++++++++++++++++++++++++++ HANE24/ViewModel/NetworkManager.swift | 2 +- 7 files changed, 144 insertions(+), 4 deletions(-) create mode 100644 HANE24/ViewModel/HomeVM.swift diff --git a/HANE24.xcodeproj/project.pbxproj b/HANE24.xcodeproj/project.pbxproj index 842aa55..6d4b90e 100644 --- a/HANE24.xcodeproj/project.pbxproj +++ b/HANE24.xcodeproj/project.pbxproj @@ -37,6 +37,7 @@ 0ED6E3FC2B354DFC0026E69D /* HANE24WidgetConstant.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ED6E3FA2B354DFC0026E69D /* HANE24WidgetConstant.swift */; }; 0ED6E3FF2B354E670026E69D /* AccumulationTimeStruct.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ED6E3FE2B354E670026E69D /* AccumulationTimeStruct.swift */; }; 0ED6E4002B354E670026E69D /* AccumulationTimeStruct.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ED6E3FE2B354E670026E69D /* AccumulationTimeStruct.swift */; }; + 0EE06CBD2BB2819500B4988C /* HomeVM.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EE06CBC2BB2819500B4988C /* HomeVM.swift */; }; 0EE58193299CC24000EE3351 /* MoreView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EE58192299CC24000EE3351 /* MoreView.swift */; }; 0EE58198299CC74C00EE3351 /* ReissuanceView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EE58197299CC74C00EE3351 /* ReissuanceView.swift */; }; 0EEB0E2429AE2AF700FEB700 /* CardProgressView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EEB0E2329AE2AF700FEB700 /* CardProgressView.swift */; }; @@ -121,6 +122,7 @@ 0ED6E3FE2B354E670026E69D /* AccumulationTimeStruct.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccumulationTimeStruct.swift; sourceTree = ""; }; 0ED6E4032B3559B80026E69D /* 24HANE.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = 24HANE.entitlements; sourceTree = ""; }; 0ED6E4042B3559DF0026E69D /* HANE24WidgetExtension.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = HANE24WidgetExtension.entitlements; sourceTree = ""; }; + 0EE06CBC2BB2819500B4988C /* HomeVM.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeVM.swift; sourceTree = ""; }; 0EE58192299CC24000EE3351 /* MoreView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoreView.swift; sourceTree = ""; }; 0EE58197299CC74C00EE3351 /* ReissuanceView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReissuanceView.swift; sourceTree = ""; }; 0EEB0E2329AE2AF700FEB700 /* CardProgressView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardProgressView.swift; sourceTree = ""; }; @@ -317,6 +319,7 @@ children = ( 9AF730FA299F53C700AF2E53 /* HaneVM.swift */, 0E3ED8A72BB13727001B0BAE /* NetworkManager.swift */, + 0EE06CBC2BB2819500B4988C /* HomeVM.swift */, 0E6B608E29AC850D009D8BC4 /* NetworkMonitoringManager.swift */, ); path = ViewModel; @@ -528,6 +531,7 @@ 0EFDFD47299F5AF500A911F7 /* DarkMode.swift in Sources */, 0E17EFAA299B5C0A0089BCD8 /* PopulationView.swift in Sources */, 0E165510299A5A82001E5EED /* HomeView.swift in Sources */, + 0EE06CBD2BB2819500B4988C /* HomeVM.swift in Sources */, 0EEB0E2629AE303100FEB700 /* AlertView.swift in Sources */, 9AF730F1299D58F100AF2E53 /* AccTimeCardForCalendarView.swift in Sources */, 2B1326112B2821E600301A8B /* ThisMonthAccTimeCardView.swift in Sources */, diff --git a/HANE24/Model/JSONs.swift b/HANE24/Model/JSONs.swift index a62a4dd..8b144df 100644 --- a/HANE24/Model/JSONs.swift +++ b/HANE24/Model/JSONs.swift @@ -25,11 +25,21 @@ struct PerMonth: Codable { struct InfoMessage: Codable { let title: String let content: String + + init() { + self.title = "" + self.content = "" + } } struct InfoMessages: Codable { let fundInfoNotice: InfoMessage let tagLatencyNotice: InfoMessage + + init() { + self.fundInfoNotice = InfoMessage() + self.tagLatencyNotice = InfoMessage() + } } struct MainInfo: Codable { @@ -41,6 +51,16 @@ struct MainInfo: Codable { let gaepo: Int /// v3 let infoMessages: InfoMessages + + init() { + self.login = "" + self.profileImage = "" + self.isAdmin = false + self.inoutState = "" + self.tagAt = "" + self.gaepo = 0 + self.infoMessages = InfoMessages() + } } struct AccumulationTimes: Codable { @@ -50,6 +70,14 @@ struct AccumulationTimes: Codable { let sixMonthAccumulationTime: [Double] /// v3 let monthlyAcceptedAccumulationTime: Int64 + + init() { + self.todayAccumulationTime = 0 + self.monthAccumulationTime = 0 + self.sixWeekAccumulationTime = [] + self.sixMonthAccumulationTime = [] + self.monthlyAcceptedAccumulationTime = 0 + } } struct ReissueState: Codable { diff --git a/HANE24/Model/Structs.swift b/HANE24/Model/Structs.swift index 346e13f..51be008 100644 --- a/HANE24/Model/Structs.swift +++ b/HANE24/Model/Structs.swift @@ -34,4 +34,9 @@ struct MoreItem: Identifiable { struct Notice { var title: String var content: String + + init(title: String = "", content: String = "") { + self.title = title + self.content = content + } } diff --git a/HANE24/View/Home/HomeView.swift b/HANE24/View/Home/HomeView.swift index 5c264aa..2cd7794 100644 --- a/HANE24/View/Home/HomeView.swift +++ b/HANE24/View/Home/HomeView.swift @@ -84,7 +84,7 @@ struct HomeView: View { @Binding var isNoticedFundInfo: Bool @Binding var isNoticedTagLatencyInfo: Bool - var body: some View { + var body: some Vi ew { NavigationView { ZStack { if hane.isInCluster { diff --git a/HANE24/ViewModel/HaneVM.swift b/HANE24/ViewModel/HaneVM.swift index 6b08f3d..9d10975 100644 --- a/HANE24/ViewModel/HaneVM.swift +++ b/HANE24/ViewModel/HaneVM.swift @@ -80,8 +80,8 @@ class Hane: ObservableObject { self.loginID = "" self.clusterPopulation = 0 - self.fundInfoNotice = Notice(title: "", content: "") - self.tagLatencyNotice = Notice(title: "", content: "") + self.fundInfoNotice = Notice() + self.tagLatencyNotice = Notice() self.inOutLog = InOutLog(inTimeStamp: nil, outTimeStamp: nil, durationSecond: nil) self.perMonth = PerMonth(login: "", profileImage: "", inOutLogs: [], totalAccumulationTime: 0, acceptedAccumulationTime: 0) diff --git a/HANE24/ViewModel/HomeVM.swift b/HANE24/ViewModel/HomeVM.swift new file mode 100644 index 0000000..518ca4b --- /dev/null +++ b/HANE24/ViewModel/HomeVM.swift @@ -0,0 +1,103 @@ +// +// HomeVM.swift +// 24HANE +// +// Created by Katherine JANG on 3/26/24. +// + +import Foundation + +class HomeVM: ObservableObject { + @Published var isInCluster: Bool + @Published var profileImage: String + @Published var userID: String + @Published var clusterPopulation: Int + + @Published var fundInfoNotice: Notice + @Published var tagLatencyNotice: Notice + + /// 누적시간데이터 + @Published var dailyAccumulationTime: Int64 = 0 + @Published var monthlyAccumulationTime: Int64 = 0 + @Published var sixWeekAccumulationTime: [Double] = Array(repeating: 0, count: 6) + @Published var sixMonthAccumulationTime: [Double] = Array(repeating: 0, count: 6) + + @Published var accumulationTime: AccumulationTimes + + var mainInfo: MainInfo + + var accumulationTimes: AccumulationTimes + + var timer: Timer? + var lastTag: Date? + + init() { + self.isInCluster = false + self.profileImage = "" + self.userID = "" + self.clusterPopulation = 0 + + self.fundInfoNotice = Notice() + self.tagLatencyNotice = Notice() + + self.mainInfo = MainInfo() + + self.accumulationTimes = AccumulationTimes() + + self.lastTag = Date() + + self.accumulationTime = AccumulationTimes() + + self.timer = Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { [weak self] _ in + guard let self = self else { return } + guard self.isInCluster else { return } + self.dailyAccumulationTime = self.accumulationTimes.todayAccumulationTime + if let lastTag = self.lastTag { + self.dailyAccumulationTime += (Date.now.millisecondsSince1970 - lastTag.millisecondsSince1970) / 1000 + } + } + } + + @MainActor + func updateUserInfo() async throws { + try await requestMainInfo() + + self.userID = mainInfo.login + self.profileImage = mainInfo.profileImage + self.isInCluster = mainInfo.inoutState == "IN" ? true : false + self.clusterPopulation = mainInfo.gaepo + } + + @MainActor + func updateNotice() async throws { + self.fundInfoNotice = Notice( + title: mainInfo.infoMessages.fundInfoNotice.title, + content: mainInfo.infoMessages.fundInfoNotice.content + ) + self.tagLatencyNotice = Notice( + title: mainInfo.infoMessages.tagLatencyNotice.title, + content: mainInfo.infoMessages.tagLatencyNotice.content + ) + } + + @MainActor + func updateAccumulationTime() async throws { + + } + +//TODO: 요청한 데이터가 nil일 경우 에러 핸들링 + func requestMainInfo() async throws { + guard let mainInfo = try await NetworkManager.shared.getRequest("/v3/tag-log/maininfo", type: MainInfo.self) else { + throw MyError.tokenExpired("") + } + self.mainInfo = mainInfo + } + + func requestAccumulationTime() async throws { + guard let accTimes = try await NetworkManager.shared.getRequest("/v3/tag-log/accumulationTimes", type: AccumulationTimes.self) else { + throw MyError.tokenExpired("") + } + self.accumulationTime = accTimes + } + +} diff --git a/HANE24/ViewModel/NetworkManager.swift b/HANE24/ViewModel/NetworkManager.swift index c526dea..57f1d5d 100644 --- a/HANE24/ViewModel/NetworkManager.swift +++ b/HANE24/ViewModel/NetworkManager.swift @@ -19,7 +19,7 @@ protocol NetworkProtocol { class NetworkManager: NetworkProtocol { - let shared = NetworkManager() + static let shared = NetworkManager() var session: URLSession var apiRoot: String From b88b75b305f9b7dff5369ef63430d0bb6dbc57e2 Mon Sep 17 00:00:00 2001 From: Hee Ju Jang <01kathyy@gmail.com> Date: Tue, 26 Mar 2024 18:39:53 +0900 Subject: [PATCH 02/15] =?UTF-8?q?[REFACTOR]=20=ED=97=A4=EB=8D=94=EB=B7=B0,?= =?UTF-8?q?=20=EC=83=88=EB=A1=9C=EA=B3=A0=EC=B9=A8=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HANE24.xcodeproj/project.pbxproj | 8 +++ HANE24/View/Home/HeaderView.swift | 64 +++++++++++++++++ HANE24/View/Home/HomeView.swift | 78 +-------------------- HANE24/View/Home/TodayAccTimeCardView.swift | 2 +- HANE24/View/PullToRefresh.swift | 41 +++++++++++ 5 files changed, 116 insertions(+), 77 deletions(-) create mode 100644 HANE24/View/Home/HeaderView.swift create mode 100644 HANE24/View/PullToRefresh.swift diff --git a/HANE24.xcodeproj/project.pbxproj b/HANE24.xcodeproj/project.pbxproj index 842aa55..d3b7549 100644 --- a/HANE24.xcodeproj/project.pbxproj +++ b/HANE24.xcodeproj/project.pbxproj @@ -37,6 +37,8 @@ 0ED6E3FC2B354DFC0026E69D /* HANE24WidgetConstant.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ED6E3FA2B354DFC0026E69D /* HANE24WidgetConstant.swift */; }; 0ED6E3FF2B354E670026E69D /* AccumulationTimeStruct.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ED6E3FE2B354E670026E69D /* AccumulationTimeStruct.swift */; }; 0ED6E4002B354E670026E69D /* AccumulationTimeStruct.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ED6E3FE2B354E670026E69D /* AccumulationTimeStruct.swift */; }; + 0EE06CBF2BB2AD4C00B4988C /* HeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EE06CBE2BB2AD4C00B4988C /* HeaderView.swift */; }; + 0EE06CC12BB2B2EB00B4988C /* PullToRefresh.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EE06CC02BB2B2EB00B4988C /* PullToRefresh.swift */; }; 0EE58193299CC24000EE3351 /* MoreView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EE58192299CC24000EE3351 /* MoreView.swift */; }; 0EE58198299CC74C00EE3351 /* ReissuanceView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EE58197299CC74C00EE3351 /* ReissuanceView.swift */; }; 0EEB0E2429AE2AF700FEB700 /* CardProgressView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EEB0E2329AE2AF700FEB700 /* CardProgressView.swift */; }; @@ -121,6 +123,8 @@ 0ED6E3FE2B354E670026E69D /* AccumulationTimeStruct.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccumulationTimeStruct.swift; sourceTree = ""; }; 0ED6E4032B3559B80026E69D /* 24HANE.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = 24HANE.entitlements; sourceTree = ""; }; 0ED6E4042B3559DF0026E69D /* HANE24WidgetExtension.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = HANE24WidgetExtension.entitlements; sourceTree = ""; }; + 0EE06CBE2BB2AD4C00B4988C /* HeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HeaderView.swift; sourceTree = ""; }; + 0EE06CC02BB2B2EB00B4988C /* PullToRefresh.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PullToRefresh.swift; sourceTree = ""; }; 0EE58192299CC24000EE3351 /* MoreView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoreView.swift; sourceTree = ""; }; 0EE58197299CC74C00EE3351 /* ReissuanceView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReissuanceView.swift; sourceTree = ""; }; 0EEB0E2329AE2AF700FEB700 /* CardProgressView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardProgressView.swift; sourceTree = ""; }; @@ -246,6 +250,7 @@ 9A1A4BED299ADE650076D650 /* TodayAccTimeCardView.swift */, 0E165507299A3C20001E5EED /* ChartView.swift */, 0E16550B299A3DF6001E5EED /* ChartDetailView.swift */, + 0EE06CBE2BB2AD4C00B4988C /* HeaderView.swift */, 0E17EFA9299B5C0A0089BCD8 /* PopulationView.swift */, 2B1326102B2821E600301A8B /* ThisMonthAccTimeCardView.swift */, 2B1326122B285B1D00301A8B /* NoticeView.swift */, @@ -284,6 +289,7 @@ 0E16550D299A5887001E5EED /* MainView.swift */, 0EFAF5BD29A4D97800125948 /* LoadingView.swift */, 0E3B32A829A3815B001D10BF /* SignInWebView.swift */, + 0EE06CC02BB2B2EB00B4988C /* PullToRefresh.swift */, 0EFAF5B729A492A500125948 /* SignInView.swift */, 0EE5818F299CC01D00EE3351 /* Home */, 0EE58190299CC02A00EE3351 /* Calendar */, @@ -542,8 +548,10 @@ 2B1326132B285B1D00301A8B /* NoticeView.swift in Sources */, 0E1654F5299A285B001E5EED /* ContentView.swift in Sources */, 9AF730EF299D3A4900AF2E53 /* CalendarGridView.swift in Sources */, + 0EE06CC12BB2B2EB00B4988C /* PullToRefresh.swift in Sources */, 0E3ED8A82BB13727001B0BAE /* NetworkManager.swift in Sources */, 0E9868252B2B6C0B00E127DC /* CalendarHeaderView.swift in Sources */, + 0EE06CBF2BB2AD4C00B4988C /* HeaderView.swift in Sources */, 0EBBF14E29B08D580076AAB9 /* ErrorView.swift in Sources */, 0E9868272B2B76BE00E127DC /* CalendarBodyView.swift in Sources */, 9AF730ED299CC54F00AF2E53 /* DateExtensions.swift in Sources */, diff --git a/HANE24/View/Home/HeaderView.swift b/HANE24/View/Home/HeaderView.swift new file mode 100644 index 0000000..6db3491 --- /dev/null +++ b/HANE24/View/Home/HeaderView.swift @@ -0,0 +1,64 @@ +// +// HeaderView.swift +// 24HANE +// +// Created by Katherine JANG on 3/26/24. +// + +import SwiftUI + +struct HeaderView: View { + @Environment(\.colorScheme) var colorScheme + @EnvironmentObject var hane: Hane + + var body: some View { + VStack(alignment: .center, spacing: 20) { + HStack(alignment: .center) { + if hane.profileImage != "" { + AsyncImage(url: URL(string: hane.profileImage)) { image in + image + .resizable() + .scaledToFill() + .frame(width: 28, height: 28) + .clipShape(Circle()) + .padding(.trailing, 3) + } placeholder: { + Image(systemName: "person.circle") + .resizable() + .frame(width: 28, height: 28) + .padding(.trailing, 3) + .foregroundColor(.iconColor) + } + } else { + Image(systemName: "person.circle") + .resizable() + .frame(width: 28, height: 28) + .padding(.trailing, 3) + .foregroundColor(.iconColor) + } + + Text(hane.loginID) + .font(.system(size: 20, weight: .semibold, design: .rounded)) + .foregroundColor(!hane.isInCluster && colorScheme == .light ? .black : .white) + + if hane.isInCluster { + Circle() + .foregroundColor(.green) + .frame(width: 8, height: 8) + .padding(.bottom, 10) + .padding(.leading, 0) + } + + Spacer() + } + .padding(.top, 20) + .frame(height: 30) + .padding(.horizontal, 30) + } + + } +} + +#Preview { + HeaderView() +} diff --git a/HANE24/View/Home/HomeView.swift b/HANE24/View/Home/HomeView.swift index 5c264aa..93ae67e 100644 --- a/HANE24/View/Home/HomeView.swift +++ b/HANE24/View/Home/HomeView.swift @@ -36,39 +36,6 @@ func getMonthlyPeriod() -> [String] { return monthlyPeriod } -struct PullToRefresh: View { - var coordinateSpaceName: String - var onRefresh: () -> Void - - @State var needRefresh: Bool = false - - var body: some View { - GeometryReader { geo in - if (geo.frame(in: .named(coordinateSpaceName))).midY > 50 { - Spacer() - .onAppear { - needRefresh = true - } - } else if geo.frame(in: .named(coordinateSpaceName)).midY < 10 { - Spacer() - .onAppear { - if needRefresh { - needRefresh = false - onRefresh() - } - } - } - HStack { - Spacer() - if needRefresh { - ProgressView() - } - Spacer() - } - } .padding(.top, -50) - } -} - struct HomeView: View { init(fundInfo: Binding, tagLatencyInfo: Binding) { UIPageControl.appearance().currentPageIndicatorTintColor = UIColor(Color.gradientPurple) @@ -97,48 +64,7 @@ struct HomeView: View { .edgesIgnoringSafeArea(colorScheme == .dark ? .all : .top) } VStack(alignment: .center, spacing: 20) { - HStack(alignment: .center) { - if hane.profileImage != "" { - AsyncImage(url: URL(string: hane.profileImage)) { image in - image - .resizable() - .scaledToFill() - .frame(width: 28, height: 28) - .clipShape(Circle()) - .padding(.trailing, 3) - } placeholder: { - Image(systemName: "person.circle") - .resizable() - .frame(width: 28, height: 28) - .padding(.trailing, 3) - .foregroundColor(.iconColor) - } - } else { - Image(systemName: "person.circle") - .resizable() - .frame(width: 28, height: 28) - .padding(.trailing, 3) - .foregroundColor(.iconColor) - } - - Text(hane.loginID) - .font(.system(size: 20, weight: .semibold, design: .rounded)) - .foregroundColor(!hane.isInCluster && colorScheme == .light ? .black : .white) - - if hane.isInCluster { - Circle() - .foregroundColor(.green) - .frame(width: 8, height: 8) - .padding(.bottom, 10) - .padding(.leading, 0) - } - - Spacer() - } - .padding(.top, 20) - .frame(height: 30) - .padding(.horizontal, 30) - + HeaderView() ScrollView { PullToRefresh(coordinateSpaceName: "pullToRefresh") { Task { @@ -149,7 +75,7 @@ struct HomeView: View { VStack(spacing: 22.5) { TodayAccTimeCardView(isNoticed: $isNoticedTagLatencyInfo) .padding(.horizontal, 30) - + ThisMonthAccTimeCardView(isNoticed: $isNoticedFundInfo) .padding(.horizontal, 30) diff --git a/HANE24/View/Home/TodayAccTimeCardView.swift b/HANE24/View/Home/TodayAccTimeCardView.swift index 39f7364..e39199d 100644 --- a/HANE24/View/Home/TodayAccTimeCardView.swift +++ b/HANE24/View/Home/TodayAccTimeCardView.swift @@ -155,7 +155,7 @@ struct TodayAccTimeCardView: View { .gradientPurple.opacity(0.1), .gradientWhtie.opacity(0.1), .gradientBlue.opacity(0.1) - ] + ] ), center: .center, startAngle: .zero, diff --git a/HANE24/View/PullToRefresh.swift b/HANE24/View/PullToRefresh.swift new file mode 100644 index 0000000..392b374 --- /dev/null +++ b/HANE24/View/PullToRefresh.swift @@ -0,0 +1,41 @@ +// +// PullToRefresh.swift +// 24HANE +// +// Created by Katherine JANG on 3/26/24. +// + +import SwiftUI + +struct PullToRefresh: View { + var coordinateSpaceName: String + var onRefresh: () -> Void + + @State var needRefresh: Bool = false + + var body: some View { + GeometryReader { geo in + if (geo.frame(in: .named(coordinateSpaceName))).midY > 50 { + Spacer() + .onAppear { + needRefresh = true + } + } else if geo.frame(in: .named(coordinateSpaceName)).midY < 10 { + Spacer() + .onAppear { + if needRefresh { + needRefresh = false + onRefresh() + } + } + } + HStack { + Spacer() + if needRefresh { + ProgressView() + } + Spacer() + } + } .padding(.top, -50) + } +} From 0b0af18a26aa5897b0f374ffb09e5aa11821da09 Mon Sep 17 00:00:00 2001 From: Hee Ju Jang <01kathyy@gmail.com> Date: Wed, 27 Mar 2024 14:14:40 +0900 Subject: [PATCH 03/15] feat: notice modifier --- HANE24.xcodeproj/project.pbxproj | 4 ++ HANE24/View/Home/HomeView.swift | 94 ++++++++++++++------------- HANE24/View/Home/NoticeModifier.swift | 30 +++++++++ HANE24/View/Home/NoticeView.swift | 4 +- Podfile.lock | 2 +- 5 files changed, 86 insertions(+), 48 deletions(-) create mode 100644 HANE24/View/Home/NoticeModifier.swift diff --git a/HANE24.xcodeproj/project.pbxproj b/HANE24.xcodeproj/project.pbxproj index d3b7549..5597e74 100644 --- a/HANE24.xcodeproj/project.pbxproj +++ b/HANE24.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 0E0FE5F12BB3DDA30050498E /* NoticeModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0FE5F02BB3DDA30050498E /* NoticeModifier.swift */; }; 0E1654F3299A285B001E5EED /* HANE24App.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E1654F2299A285B001E5EED /* HANE24App.swift */; }; 0E1654F5299A285B001E5EED /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E1654F4299A285B001E5EED /* ContentView.swift */; }; 0E1654F7299A285E001E5EED /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 0E1654F6299A285E001E5EED /* Assets.xcassets */; }; @@ -93,6 +94,7 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 0E0FE5F02BB3DDA30050498E /* NoticeModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoticeModifier.swift; sourceTree = ""; }; 0E1654EF299A285B001E5EED /* 24HANE.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = 24HANE.app; sourceTree = BUILT_PRODUCTS_DIR; }; 0E1654F2299A285B001E5EED /* HANE24App.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HANE24App.swift; sourceTree = ""; }; 0E1654F4299A285B001E5EED /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; @@ -254,6 +256,7 @@ 0E17EFA9299B5C0A0089BCD8 /* PopulationView.swift */, 2B1326102B2821E600301A8B /* ThisMonthAccTimeCardView.swift */, 2B1326122B285B1D00301A8B /* NoticeView.swift */, + 0E0FE5F02BB3DDA30050498E /* NoticeModifier.swift */, ); path = Home; sourceTree = ""; @@ -561,6 +564,7 @@ 9AF730F6299E074800AF2E53 /* Structs.swift in Sources */, 0E3B32A929A3815B001D10BF /* SignInWebView.swift in Sources */, 0EE58198299CC74C00EE3351 /* ReissuanceView.swift in Sources */, + 0E0FE5F12BB3DDA30050498E /* NoticeModifier.swift in Sources */, 0E16550A299A3D8A001E5EED /* ColorExtension.swift in Sources */, 0E16550C299A3DF6001E5EED /* ChartDetailView.swift in Sources */, 9AF730FB299F53C700AF2E53 /* HaneVM.swift in Sources */, diff --git a/HANE24/View/Home/HomeView.swift b/HANE24/View/Home/HomeView.swift index 93ae67e..6610b22 100644 --- a/HANE24/View/Home/HomeView.swift +++ b/HANE24/View/Home/HomeView.swift @@ -50,56 +50,60 @@ struct HomeView: View { @Binding var isNoticedFundInfo: Bool @Binding var isNoticedTagLatencyInfo: Bool + + @State var showAlert: Bool = false var body: some View { - NavigationView { - ZStack { - if hane.isInCluster { - Image("Background") - .resizable() - .edgesIgnoringSafeArea(.top) - .opacity(0.7) - } else { - Theme.backgroundColor(forScheme: colorScheme) - .edgesIgnoringSafeArea(colorScheme == .dark ? .all : .top) - } - VStack(alignment: .center, spacing: 20) { - HeaderView() - ScrollView { - PullToRefresh(coordinateSpaceName: "pullToRefresh") { - Task { - try await hane.refresh() - } - } + ZStack { + if hane.isInCluster { + Image("Background") + .resizable() + .edgesIgnoringSafeArea(.top) + .opacity(0.7) + } else { + Theme.backgroundColor(forScheme: colorScheme) + .edgesIgnoringSafeArea(colorScheme == .dark ? .all : .top) + } + VStack(alignment: .center, spacing: 20) { + HeaderView() + ScrollView { + PullToRefresh(coordinateSpaceName: "pullToRefresh") { + Task { + try await hane.refresh() + } + } - VStack(spacing: 22.5) { - TodayAccTimeCardView(isNoticed: $isNoticedTagLatencyInfo) - .padding(.horizontal, 30) - - ThisMonthAccTimeCardView(isNoticed: $isNoticedFundInfo) - .padding(.horizontal, 30) + VStack(spacing: 22.5) { + TodayAccTimeCardView(isNoticed: $isNoticedTagLatencyInfo) + .padding(.horizontal, 30) + .onTapGesture { + self.showAlert = true + } + + ThisMonthAccTimeCardView(isNoticed: $isNoticedFundInfo) + .padding(.horizontal, 30) - TabView { - ChartView(item: ChartItem(id: "주", title: "최근 주간 그래프", period: getWeeklyPeriod(), data: hane.sixWeekAccumulationTime)) - .padding(.horizontal, 10) - ChartView(item: ChartItem(id: "개월", title: "최근 월간 그래프", period: getMonthlyPeriod(), data: hane.sixMonthAccumulationTime)) - .padding(.horizontal, 10) - } - .padding(.horizontal, 20) - .tabViewStyle(.page) - .frame(height: 289) - - PopulationView() - .padding(.horizontal, 30) - } - .padding(.bottom, 30) - .padding(.top, 10) - } .coordinateSpace(name: "pullToRefresh") - } - } - } - .navigationTitle("알림") + TabView { + ChartView(item: ChartItem(id: "주", title: "최근 주간 그래프", period: getWeeklyPeriod(), data: hane.sixWeekAccumulationTime)) + .padding(.horizontal, 10) + ChartView(item: ChartItem(id: "개월", title: "최근 월간 그래프", period: getMonthlyPeriod(), data: hane.sixMonthAccumulationTime)) + .padding(.horizontal, 10) + } + .padding(.horizontal, 20) + .tabViewStyle(.page) + .frame(height: 289) + PopulationView() + .padding(.horizontal, 30) + } + .padding(.bottom, 30) + .padding(.top, 10) + } .coordinateSpace(name: "pullToRefresh") + } + } + .noticeAlert(isPresented: $showAlert) { + NoticeView(showNotice: $showAlert, notice: Notice(title: "g", content: "")) + } } } diff --git a/HANE24/View/Home/NoticeModifier.swift b/HANE24/View/Home/NoticeModifier.swift new file mode 100644 index 0000000..ee6bdb3 --- /dev/null +++ b/HANE24/View/Home/NoticeModifier.swift @@ -0,0 +1,30 @@ +// +// NoticeModifier.swift +// 24HANE +// +// Created by Katherine JANG on 3/27/24. +// + +import SwiftUI + +public struct NoticeModifier: ViewModifier { + @Binding var isPresent: Bool + + let notice: NoticeView + + public func body(content: Content) -> some View { + content + .fullScreenCover(isPresented: $isPresent) { + notice + } + .transaction { transaction in + transaction.disablesAnimations = true + } + } +} + +extension View { + public func noticeAlert(isPresented: Binding, noticeAlert: @escaping () -> NoticeView) -> some View { + return modifier(NoticeModifier(isPresent: isPresented, notice: noticeAlert())) + } +} diff --git a/HANE24/View/Home/NoticeView.swift b/HANE24/View/Home/NoticeView.swift index 402e9d7..3cceafa 100644 --- a/HANE24/View/Home/NoticeView.swift +++ b/HANE24/View/Home/NoticeView.swift @@ -7,10 +7,10 @@ import SwiftUI -struct NoticeView: View { +public struct NoticeView: View { @Binding var showNotice: Bool var notice: Notice - var body: some View { + public var body: some View { ZStack { Color.black.opacity(0.4) .ignoresSafeArea(.all) diff --git a/Podfile.lock b/Podfile.lock index e71e163..d606c34 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -11,6 +11,6 @@ SPEC REPOS: SPEC CHECKSUMS: SwiftLint: c1de071d9d08c8aba837545f6254315bc900e211 -PODFILE CHECKSUM: 68dbe72762bbebaea8bf8e8f527b8e90a20daf32 +PODFILE CHECKSUM: 88f9b39c53325d9e15337ef2888bc9a9dde656e7 COCOAPODS: 1.14.3 From cf59a619616d09ed6d41e60255e3fecef45ff737 Mon Sep 17 00:00:00 2001 From: Hee Ju Jang <01kathyy@gmail.com> Date: Wed, 27 Mar 2024 14:22:29 +0900 Subject: [PATCH 04/15] remove: unused codes --- HANE24/View/Home/HomeView.swift | 5 ----- 1 file changed, 5 deletions(-) diff --git a/HANE24/View/Home/HomeView.swift b/HANE24/View/Home/HomeView.swift index 6610b22..a038f0c 100644 --- a/HANE24/View/Home/HomeView.swift +++ b/HANE24/View/Home/HomeView.swift @@ -50,8 +50,6 @@ struct HomeView: View { @Binding var isNoticedFundInfo: Bool @Binding var isNoticedTagLatencyInfo: Bool - - @State var showAlert: Bool = false var body: some View { ZStack { @@ -101,9 +99,6 @@ struct HomeView: View { } .coordinateSpace(name: "pullToRefresh") } } - .noticeAlert(isPresented: $showAlert) { - NoticeView(showNotice: $showAlert, notice: Notice(title: "g", content: "")) - } } } From c0d589d0034dcb3c7c27b48fb4672bb6986868ee Mon Sep 17 00:00:00 2001 From: Hee Ju Jang <01kathyy@gmail.com> Date: Wed, 27 Mar 2024 14:22:45 +0900 Subject: [PATCH 05/15] remove: unused codes --- HANE24/View/Home/HomeView.swift | 3 --- 1 file changed, 3 deletions(-) diff --git a/HANE24/View/Home/HomeView.swift b/HANE24/View/Home/HomeView.swift index a038f0c..3cf2c90 100644 --- a/HANE24/View/Home/HomeView.swift +++ b/HANE24/View/Home/HomeView.swift @@ -74,9 +74,6 @@ struct HomeView: View { VStack(spacing: 22.5) { TodayAccTimeCardView(isNoticed: $isNoticedTagLatencyInfo) .padding(.horizontal, 30) - .onTapGesture { - self.showAlert = true - } ThisMonthAccTimeCardView(isNoticed: $isNoticedFundInfo) .padding(.horizontal, 30) From 5a5db4ce3f76e5544c3fda9c13287465b5abfa8c Mon Sep 17 00:00:00 2001 From: Hee Ju Jang <01kathyy@gmail.com> Date: Wed, 27 Mar 2024 14:57:53 +0900 Subject: [PATCH 06/15] refactor: split circular progress bar --- HANE24.xcodeproj/project.pbxproj | 6 ++ HANE24/View/Home/CircularProgressBar.swift | 76 +++++++++++++++++++++ HANE24/View/Home/TodayAccTimeCardView.swift | 56 +-------------- 3 files changed, 83 insertions(+), 55 deletions(-) create mode 100644 HANE24/View/Home/CircularProgressBar.swift diff --git a/HANE24.xcodeproj/project.pbxproj b/HANE24.xcodeproj/project.pbxproj index 5597e74..42a4965 100644 --- a/HANE24.xcodeproj/project.pbxproj +++ b/HANE24.xcodeproj/project.pbxproj @@ -8,6 +8,8 @@ /* Begin PBXBuildFile section */ 0E0FE5F12BB3DDA30050498E /* NoticeModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0FE5F02BB3DDA30050498E /* NoticeModifier.swift */; }; + 0E0FE5F32BB3E6110050498E /* CircularProgressBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0FE5F22BB3E6110050498E /* CircularProgressBar.swift */; }; + 0E0FE5F42BB3E6180050498E /* CircularProgressBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0FE5F22BB3E6110050498E /* CircularProgressBar.swift */; }; 0E1654F3299A285B001E5EED /* HANE24App.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E1654F2299A285B001E5EED /* HANE24App.swift */; }; 0E1654F5299A285B001E5EED /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E1654F4299A285B001E5EED /* ContentView.swift */; }; 0E1654F7299A285E001E5EED /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 0E1654F6299A285E001E5EED /* Assets.xcassets */; }; @@ -95,6 +97,7 @@ /* Begin PBXFileReference section */ 0E0FE5F02BB3DDA30050498E /* NoticeModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoticeModifier.swift; sourceTree = ""; }; + 0E0FE5F22BB3E6110050498E /* CircularProgressBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CircularProgressBar.swift; sourceTree = ""; }; 0E1654EF299A285B001E5EED /* 24HANE.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = 24HANE.app; sourceTree = BUILT_PRODUCTS_DIR; }; 0E1654F2299A285B001E5EED /* HANE24App.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HANE24App.swift; sourceTree = ""; }; 0E1654F4299A285B001E5EED /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; @@ -250,6 +253,7 @@ children = ( 0E16550F299A5A82001E5EED /* HomeView.swift */, 9A1A4BED299ADE650076D650 /* TodayAccTimeCardView.swift */, + 0E0FE5F22BB3E6110050498E /* CircularProgressBar.swift */, 0E165507299A3C20001E5EED /* ChartView.swift */, 0E16550B299A3DF6001E5EED /* ChartDetailView.swift */, 0EE06CBE2BB2AD4C00B4988C /* HeaderView.swift */, @@ -572,6 +576,7 @@ 0E1654F3299A285B001E5EED /* HANE24App.swift in Sources */, 0EEB0E2429AE2AF700FEB700 /* CardProgressView.swift in Sources */, 9AF730F3299D599300AF2E53 /* TagLogView.swift in Sources */, + 0E0FE5F32BB3E6110050498E /* CircularProgressBar.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -582,6 +587,7 @@ 0ED6E4002B354E670026E69D /* AccumulationTimeStruct.swift in Sources */, 0ED6E3F92B354DD00026E69D /* UserDefaultsExtension.swift in Sources */, 0ED6E3E82B354D320026E69D /* HANE24WidgetBundle.swift in Sources */, + 0E0FE5F42BB3E6180050498E /* CircularProgressBar.swift in Sources */, 0ED6E3EA2B354D320026E69D /* HANE24Widget.swift in Sources */, 0ED6E3F52B354DBD0026E69D /* DateExtensions.swift in Sources */, 0ED6E3F62B354DC00026E69D /* ColorExtension.swift in Sources */, diff --git a/HANE24/View/Home/CircularProgressBar.swift b/HANE24/View/Home/CircularProgressBar.swift new file mode 100644 index 0000000..1e74d57 --- /dev/null +++ b/HANE24/View/Home/CircularProgressBar.swift @@ -0,0 +1,76 @@ +// +// CircularProgressBar.swift +// 24HANE +// +// Created by Katherine JANG on 3/27/24. +// + +import SwiftUI + +struct CircularProgressBar: View { + + var drawingStroke: Binding + var percentage: Int + + init(drawingStroke: Binding, objectiveTime: Double, progressiveTime: Double) { + self.percentage = Int(progressiveTime / objectiveTime * 3600) * 100 + self.drawingStroke = drawingStroke + } + + var body: some View { + ZStack { + HStack(spacing: 0) { + Text("\(percentage)") + .font(.system(size: 32, weight: .medium, design: .default)) + .foregroundColor(.black) + Text("%") + .font(.system(size: 14, weight: .medium, design: .default)) + .foregroundColor(.black) + .padding(.top, 10) + } + Circle() + .stroke( + AngularGradient( + gradient: Gradient( + colors: [ + .gradientBlue, + .gradientWhtie, + .gradientPurple, + .gradientPurple, + .gradientWhtie, + .gradientBlue + ] + ), + center: .center, + startAngle: .zero, + endAngle: .degrees(360) + ).opacity(0.1), + style: StrokeStyle(lineWidth: 8, lineCap: .round) + ) + .overlay { + Circle() + .trim(from: 0, to: drawingStroke.wrappedValue ? CGFloat(percentage / 100) : 0) + .stroke( + AngularGradient( + gradient: Gradient(colors: [ + .gradientBlue.opacity(0.35), + .gradientWhtie, + .gradientPurple, + .gradientPurple, + .gradientWhtie, + .gradientBlue.opacity(0.35) + ]), + center: .center, + startAngle: .degrees(0), + endAngle: .degrees(360) + ), + style: StrokeStyle(lineWidth: 8, lineCap: .round)) + .rotationEffect(.degrees(270)) + } + } + } +} + +#Preview { + CircularProgressBar(drawingStroke: .constant(false), objectiveTime: 12345, progressiveTime: 1234) +} diff --git a/HANE24/View/Home/TodayAccTimeCardView.swift b/HANE24/View/Home/TodayAccTimeCardView.swift index e39199d..79421f3 100644 --- a/HANE24/View/Home/TodayAccTimeCardView.swift +++ b/HANE24/View/Home/TodayAccTimeCardView.swift @@ -118,7 +118,7 @@ struct TodayAccTimeCardView: View { .padding(.leading, 10) .padding(.trailing, 14) /// Progress Circle - progressCircle + CircularProgressBar(drawingStroke: $drawingStroke, objectiveTime: options[dailySelectionOption], progressiveTime: Double(hane.dailyAccumulationTime)) .frame(width: 112, height: 112) .padding(.top, 11) .padding(.bottom, 18) @@ -131,60 +131,6 @@ struct TodayAccTimeCardView: View { } .frame(height: isFold ? 80 : 260, alignment: .top) } - - var progressCircle: some View { - - ZStack { - HStack(spacing: 0) { - Text("\(Int(Double(hane.dailyAccumulationTime) / Double(options[dailySelectionOption] * 3600) * 100))") - .font(.system(size: 32, weight: .medium, design: .default)) - .foregroundColor(.black) - Text("%") - .font(.system(size: 14, weight: .medium, design: .default)) - .foregroundColor(.black) - .padding(.top, 10) - } - Circle() - .stroke( - AngularGradient( - gradient: Gradient( - colors: [ - .gradientBlue.opacity(0.1), - .gradientWhtie.opacity(0.1), - .gradientPurple.opacity(0.1), - .gradientPurple.opacity(0.1), - .gradientWhtie.opacity(0.1), - .gradientBlue.opacity(0.1) - ] - ), - center: .center, - startAngle: .zero, - endAngle: .degrees(360) - ), - style: StrokeStyle(lineWidth: 8, lineCap: .round) - ) - .overlay { - Circle() - .trim(from: 0, to: drawingStroke ? (Double(hane.dailyAccumulationTime) / Double(options[dailySelectionOption] * 3600)) : 0) - .stroke( - AngularGradient( - gradient: Gradient(colors: [ - .gradientBlue.opacity(0.35), - .gradientWhtie, - .gradientPurple, - .gradientPurple, - .gradientWhtie, - .gradientBlue.opacity(0.35) - ]), - center: .center, - startAngle: .degrees(0), - endAngle: .degrees(360) - ), - style: StrokeStyle(lineWidth: 8, lineCap: .round)) - .rotationEffect(.degrees(270)) - } - } - } } extension View { From 7833790435db369ff64595c0c37ce94dc78da49b Mon Sep 17 00:00:00 2001 From: Hee Ju Jang <01kathyy@gmail.com> Date: Wed, 27 Mar 2024 15:44:27 +0900 Subject: [PATCH 07/15] refactor: hane to homeManager --- HANE24/View/Home/HomeView.swift | 84 ++++++++++--------- HANE24/View/Home/PopulationView.swift | 5 +- .../View/Home/ThisMonthAccTimeCardView.swift | 8 +- HANE24/View/Home/TodayAccTimeCardView.swift | 9 +- HANE24/ViewModel/HaneVM.swift | 22 +---- HANE24/ViewModel/HomeVM.swift | 2 +- 6 files changed, 59 insertions(+), 71 deletions(-) diff --git a/HANE24/View/Home/HomeView.swift b/HANE24/View/Home/HomeView.swift index 2cd7794..a1fafad 100644 --- a/HANE24/View/Home/HomeView.swift +++ b/HANE24/View/Home/HomeView.swift @@ -7,35 +7,6 @@ import SwiftUI -func getWeeklyPeriod() -> [String] { - var weeklyPeriod: [String] = [] - var date = Date() - let formatter = DateFormatter() - formatter.locale = Locale(identifier: "ko_KR") - formatter.dateFormat = "M.dd(EEE)" - for _ in 0..<6 { - let startDay = formatter.string(from: date.startOfWeek!) - let endDay = formatter.string(from: date.endOfWeek!) - let period = startDay + " - " + endDay - weeklyPeriod.append(period) - date = Calendar.current.date(byAdding: .weekOfYear, value: -1, to: date)! - } - return weeklyPeriod -} - -func getMonthlyPeriod() -> [String] { - var monthlyPeriod: [String] = [] - var date = Date() - let formatter = DateFormatter() - formatter.dateFormat = "YYYY.M" - for _ in 0..<6 { - let period = formatter.string(from: date) - monthlyPeriod.append(period) - date = Calendar.current.date(byAdding: .month, value: -1, to: date)! - } - return monthlyPeriod -} - struct PullToRefresh: View { var coordinateSpaceName: String var onRefresh: () -> Void @@ -71,8 +42,8 @@ struct PullToRefresh: View { struct HomeView: View { init(fundInfo: Binding, tagLatencyInfo: Binding) { - UIPageControl.appearance().currentPageIndicatorTintColor = UIColor(Color.gradientPurple) - UIPageControl.appearance().pageIndicatorTintColor = UIColor.gray.withAlphaComponent(0.2) +// UIPageControl.appearance().currentPageIndicatorTintColor = UIColor(Color.gradientPurple) +// UIPageControl.appearance().pageIndicatorTintColor = UIColor.gray.withAlphaComponent(0.2) self._isNoticedFundInfo = fundInfo self._isNoticedTagLatencyInfo = tagLatencyInfo @@ -80,14 +51,16 @@ struct HomeView: View { @State var test: Bool = true @Environment(\.colorScheme) var colorScheme @EnvironmentObject var hane: Hane + + @StateObject var homeManager = HomeVM() @Binding var isNoticedFundInfo: Bool @Binding var isNoticedTagLatencyInfo: Bool - var body: some Vi ew { + var body: some View { NavigationView { ZStack { - if hane.isInCluster { + if homeManager.isInCluster { Image("Background") .resizable() .edgesIgnoringSafeArea(.top) @@ -98,7 +71,7 @@ struct HomeView: View { } VStack(alignment: .center, spacing: 20) { HStack(alignment: .center) { - if hane.profileImage != "" { + if homeManager.profileImage != "" { AsyncImage(url: URL(string: hane.profileImage)) { image in image .resizable() @@ -121,11 +94,11 @@ struct HomeView: View { .foregroundColor(.iconColor) } - Text(hane.loginID) + Text(homeManager.userID) .font(.system(size: 20, weight: .semibold, design: .rounded)) .foregroundColor(!hane.isInCluster && colorScheme == .light ? .black : .white) - if hane.isInCluster { + if homeManager.isInCluster { Circle() .foregroundColor(.green) .frame(width: 8, height: 8) @@ -147,23 +120,23 @@ struct HomeView: View { } VStack(spacing: 22.5) { - TodayAccTimeCardView(isNoticed: $isNoticedTagLatencyInfo) + TodayAccTimeCardView(homeManager: homeManager, isNoticed: $isNoticedTagLatencyInfo) .padding(.horizontal, 30) - ThisMonthAccTimeCardView(isNoticed: $isNoticedFundInfo) + ThisMonthAccTimeCardView(homeManager: homeManager, isNoticed: $isNoticedFundInfo) .padding(.horizontal, 30) TabView { - ChartView(item: ChartItem(id: "주", title: "최근 주간 그래프", period: getWeeklyPeriod(), data: hane.sixWeekAccumulationTime)) + ChartView(item: ChartItem(id: "주", title: "최근 주간 그래프", period: getWeeklyPeriod(), data: homeManager.sixWeekAccumulationTime)) .padding(.horizontal, 10) - ChartView(item: ChartItem(id: "개월", title: "최근 월간 그래프", period: getMonthlyPeriod(), data: hane.sixMonthAccumulationTime)) + ChartView(item: ChartItem(id: "개월", title: "최근 월간 그래프", period: getMonthlyPeriod(), data: homeManager.sixMonthAccumulationTime)) .padding(.horizontal, 10) } .padding(.horizontal, 20) .tabViewStyle(.page) .frame(height: 289) - PopulationView() + PopulationView(population: homeManager.clusterPopulation) .padding(.horizontal, 30) } .padding(.bottom, 30) @@ -175,6 +148,35 @@ struct HomeView: View { .navigationTitle("알림") } + + private func getWeeklyPeriod() -> [String] { + var weeklyPeriod: [String] = [] + var date = Date() + let formatter = DateFormatter() + formatter.locale = Locale(identifier: "ko_KR") + formatter.dateFormat = "M.dd(EEE)" + for _ in 0..<6 { + let startDay = formatter.string(from: date.startOfWeek!) + let endDay = formatter.string(from: date.endOfWeek!) + let period = startDay + " - " + endDay + weeklyPeriod.append(period) + date = Calendar.current.date(byAdding: .weekOfYear, value: -1, to: date)! + } + return weeklyPeriod + } + + private func getMonthlyPeriod() -> [String] { + var monthlyPeriod: [String] = [] + var date = Date() + let formatter = DateFormatter() + formatter.dateFormat = "YYYY.M" + for _ in 0..<6 { + let period = formatter.string(from: date) + monthlyPeriod.append(period) + date = Calendar.current.date(byAdding: .month, value: -1, to: date)! + } + return monthlyPeriod + } } #Preview { diff --git a/HANE24/View/Home/PopulationView.swift b/HANE24/View/Home/PopulationView.swift index faf7161..581428c 100644 --- a/HANE24/View/Home/PopulationView.swift +++ b/HANE24/View/Home/PopulationView.swift @@ -8,7 +8,8 @@ import SwiftUI struct PopulationView: View { - @EnvironmentObject var hane: Hane + var population: Int + var body: some View { VStack(alignment: .leading, spacing: 8) { Text("실시간 현황") @@ -25,7 +26,7 @@ struct PopulationView: View { .padding(.horizontal, 20) .foregroundColor(.black) Spacer() - Text("\(hane.clusterPopulation)") + Text("\(population)") .font(.system(size: 20, weight: .bold)) .foregroundColor(.black) .padding(.leading, 20) diff --git a/HANE24/View/Home/ThisMonthAccTimeCardView.swift b/HANE24/View/Home/ThisMonthAccTimeCardView.swift index eefd3ea..d03ad4b 100644 --- a/HANE24/View/Home/ThisMonthAccTimeCardView.swift +++ b/HANE24/View/Home/ThisMonthAccTimeCardView.swift @@ -9,6 +9,7 @@ import SwiftUI struct ThisMonthAccTimeCardView: View { @EnvironmentObject var hane: Hane + @ObservedObject var homeManager: HomeVM @Binding var isNoticed: Bool @@ -37,11 +38,11 @@ struct ThisMonthAccTimeCardView: View { LoadingAnimation() } else { HStack(alignment: .bottom, spacing: 0) { - Text("\(hane.monthlyAccumulationTime / 3600)") + Text("\(homeManager.monthlyAccumulationTime / 3600)") .font(.system(size: 20, weight: .bold)) Text("시간 ") .font(.system(size: 16, weight: .bold)) - Text("\(hane.monthlyAccumulationTime % 3600 / 60)") + Text("\(homeManager.monthlyAccumulationTime % 3600 / 60)") .font(.system(size: 20, weight: .bold)) Text("분") .font(.system(size: 16, weight: .bold)) @@ -89,6 +90,7 @@ struct ThisMonthAccTimeCardView: View { if hane.loading { LoadingAnimation() } else { + //TODO: hane -> homeVM HStack(alignment: .bottom, spacing: 0) { Text("\(hane.thisMonthAcceptedAccumulationTime / 3600)") .font(.system(size: 20, weight: .bold)) @@ -124,6 +126,6 @@ struct ThisMonthAccTimeCardView: View { hane.loading = false hane.monthlyAccumulationTime = 34567 hane.thisMonthAcceptedAccumulationTime = 12345 - return ThisMonthAccTimeCardView(isNoticed: .constant(false)) + return ThisMonthAccTimeCardView(homeManager: HomeVM(), isNoticed: .constant(false)) .environmentObject(hane) } diff --git a/HANE24/View/Home/TodayAccTimeCardView.swift b/HANE24/View/Home/TodayAccTimeCardView.swift index 39f7364..fd05dad 100644 --- a/HANE24/View/Home/TodayAccTimeCardView.swift +++ b/HANE24/View/Home/TodayAccTimeCardView.swift @@ -8,6 +8,7 @@ import SwiftUI struct TodayAccTimeCardView: View { + @ObservedObject var homeManager: HomeVM @EnvironmentObject var hane: Hane @AppStorage("DailySelectionOption") private var dailySelectionOption = UserDefaults.standard.integer(forKey: "DailySelectionOption") @@ -58,11 +59,11 @@ struct TodayAccTimeCardView: View { LoadingAnimation() } else { HStack(alignment: .bottom, spacing: 0) { - Text("\(hane.dailyAccumulationTime / 3600)") + Text("\(homeManager.dailyAccumulationTime / 3600)") .font(.system(size: 20, weight: .bold)) Text("시간 ") .font(.system(size: 16, weight: .bold)) - Text("\(hane.dailyAccumulationTime % 3600 / 60)") + Text("\(homeManager.dailyAccumulationTime % 3600 / 60)") .font(.system(size: 20, weight: .bold)) Text("분") .font(.system(size: 16, weight: .bold)) @@ -136,7 +137,7 @@ struct TodayAccTimeCardView: View { ZStack { HStack(spacing: 0) { - Text("\(Int(Double(hane.dailyAccumulationTime) / Double(options[dailySelectionOption] * 3600) * 100))") + Text("\(Int(Double(homeManager.dailyAccumulationTime) / Double(options[dailySelectionOption] * 3600) * 100))") .font(.system(size: 32, weight: .medium, design: .default)) .foregroundColor(.black) Text("%") @@ -218,6 +219,6 @@ extension View { let hane = Hane() hane.dailyAccumulationTime = 12280 hane.loading = false - return TodayAccTimeCardView(isNoticed: .constant(false)) + return TodayAccTimeCardView(homeManager: HomeVM(), isNoticed: .constant(false)) .environmentObject(hane) } diff --git a/HANE24/ViewModel/HaneVM.swift b/HANE24/ViewModel/HaneVM.swift index 9d10975..8eb6af5 100644 --- a/HANE24/ViewModel/HaneVM.swift +++ b/HANE24/ViewModel/HaneVM.swift @@ -85,26 +85,8 @@ class Hane: ObservableObject { self.inOutLog = InOutLog(inTimeStamp: nil, outTimeStamp: nil, durationSecond: nil) self.perMonth = PerMonth(login: "", profileImage: "", inOutLogs: [], totalAccumulationTime: 0, acceptedAccumulationTime: 0) - self.mainInfo = MainInfo( - login: "", - profileImage: "", - isAdmin: false, - inoutState: "", - tagAt: nil, - gaepo: 0, - infoMessages: - InfoMessages( - fundInfoNotice: InfoMessage(title: "", content: ""), - tagLatencyNotice: InfoMessage(title: "", content: "") - ) - ) - self.accumulationTimes = AccumulationTimes( - todayAccumulationTime: 0, - monthAccumulationTime: 0, - sixWeekAccumulationTime: Array(repeating: 0, count: 6), - sixMonthAccumulationTime: Array(repeating: 0, count: 6), - monthlyAcceptedAccumulationTime: 0 - ) + self.mainInfo = MainInfo() + self.accumulationTimes = AccumulationTimes() self.APIroot = "https://" + (Bundle.main.infoDictionary?["API_URL"] as? String ?? "wrong") self.reissueState = .none diff --git a/HANE24/ViewModel/HomeVM.swift b/HANE24/ViewModel/HomeVM.swift index 518ca4b..1540aef 100644 --- a/HANE24/ViewModel/HomeVM.swift +++ b/HANE24/ViewModel/HomeVM.swift @@ -93,11 +93,11 @@ class HomeVM: ObservableObject { self.mainInfo = mainInfo } + @MainActor func requestAccumulationTime() async throws { guard let accTimes = try await NetworkManager.shared.getRequest("/v3/tag-log/accumulationTimes", type: AccumulationTimes.self) else { throw MyError.tokenExpired("") } self.accumulationTime = accTimes } - } From d5a15f9e4a13384f7925c9650021ce0e36658116 Mon Sep 17 00:00:00 2001 From: Hee Ju Jang <01kathyy@gmail.com> Date: Wed, 3 Apr 2024 22:03:49 +0900 Subject: [PATCH 08/15] tmp --- HANE24.xcworkspace/contents.xcworkspacedata | 3 +++ 1 file changed, 3 insertions(+) diff --git a/HANE24.xcworkspace/contents.xcworkspacedata b/HANE24.xcworkspace/contents.xcworkspacedata index 03d59d0..73fa4a9 100644 --- a/HANE24.xcworkspace/contents.xcworkspacedata +++ b/HANE24.xcworkspace/contents.xcworkspacedata @@ -1,6 +1,9 @@ + + From 60f6e0349c3aeb2406bde1db0ba81c67f9d31212 Mon Sep 17 00:00:00 2001 From: Hee Ju Jang <01kathyy@gmail.com> Date: Wed, 3 Apr 2024 22:06:30 +0900 Subject: [PATCH 09/15] FEAT: annotation --- HANE24/View/Home/NoticeModifier.swift | 1 + HANE24/View/Home/NoticeView.swift | 2 ++ 2 files changed, 3 insertions(+) diff --git a/HANE24/View/Home/NoticeModifier.swift b/HANE24/View/Home/NoticeModifier.swift index ee6bdb3..f2a48b1 100644 --- a/HANE24/View/Home/NoticeModifier.swift +++ b/HANE24/View/Home/NoticeModifier.swift @@ -7,6 +7,7 @@ import SwiftUI +//MARK: unused in V3 public struct NoticeModifier: ViewModifier { @Binding var isPresent: Bool diff --git a/HANE24/View/Home/NoticeView.swift b/HANE24/View/Home/NoticeView.swift index 3cceafa..15a745b 100644 --- a/HANE24/View/Home/NoticeView.swift +++ b/HANE24/View/Home/NoticeView.swift @@ -7,6 +7,8 @@ import SwiftUI +//MARK: unused in V3 + public struct NoticeView: View { @Binding var showNotice: Bool var notice: Notice From a4a7f9ce011a99b72d0ad5352c0ca2bb5d2fed2a Mon Sep 17 00:00:00 2001 From: Hee Ju Jang <01kathyy@gmail.com> Date: Wed, 3 Apr 2024 23:17:01 +0900 Subject: [PATCH 10/15] FIX: home VM --- HANE24.xcworkspace/contents.xcworkspacedata | 3 +++ HANE24/ViewModel/HomeVM.swift | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/HANE24.xcworkspace/contents.xcworkspacedata b/HANE24.xcworkspace/contents.xcworkspacedata index 03d59d0..73fa4a9 100644 --- a/HANE24.xcworkspace/contents.xcworkspacedata +++ b/HANE24.xcworkspace/contents.xcworkspacedata @@ -1,6 +1,9 @@ + + diff --git a/HANE24/ViewModel/HomeVM.swift b/HANE24/ViewModel/HomeVM.swift index 1540aef..b4ca4c7 100644 --- a/HANE24/ViewModel/HomeVM.swift +++ b/HANE24/ViewModel/HomeVM.swift @@ -38,7 +38,7 @@ class HomeVM: ObservableObject { self.clusterPopulation = 0 self.fundInfoNotice = Notice() - self.tagLatencyNotice = Notice() + self.tagLatencyNotice = Notice( ) self.mainInfo = MainInfo() From 365d978fa55df7b2fe18e9c1c151606c1e9a7594 Mon Sep 17 00:00:00 2001 From: Hee Ju Jang <01kathyy@gmail.com> Date: Sun, 21 Apr 2024 19:55:11 +0900 Subject: [PATCH 11/15] FIX: homeVM --- HANE24/ViewModel/HomeVM.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/HANE24/ViewModel/HomeVM.swift b/HANE24/ViewModel/HomeVM.swift index b4ca4c7..1bd1bae 100644 --- a/HANE24/ViewModel/HomeVM.swift +++ b/HANE24/ViewModel/HomeVM.swift @@ -24,12 +24,15 @@ class HomeVM: ObservableObject { @Published var accumulationTime: AccumulationTimes + @Published var isLoading: Bool + var mainInfo: MainInfo var accumulationTimes: AccumulationTimes var timer: Timer? var lastTag: Date? + init() { self.isInCluster = false @@ -40,6 +43,8 @@ class HomeVM: ObservableObject { self.fundInfoNotice = Notice() self.tagLatencyNotice = Notice( ) + self.isLoading = false + self.mainInfo = MainInfo() self.accumulationTimes = AccumulationTimes() From 81899e1936111fc5b11c2a7c639bde3df5a9bbb7 Mon Sep 17 00:00:00 2001 From: Hee Ju Jang <01kathyy@gmail.com> Date: Wed, 24 Apr 2024 15:51:09 +0900 Subject: [PATCH 12/15] seperate homeVM logic --- HANE24/View/Home/HeaderView.swift | 16 +- HANE24/View/Home/HomeView.swift | 194 +++++++----------- HANE24/View/Home/PopulationView.swift | 8 +- .../View/Home/ThisMonthAccTimeCardView.swift | 4 +- HANE24/ViewModel/HomeVM.swift | 87 ++++---- 5 files changed, 127 insertions(+), 182 deletions(-) diff --git a/HANE24/View/Home/HeaderView.swift b/HANE24/View/Home/HeaderView.swift index 6db3491..9affd3e 100644 --- a/HANE24/View/Home/HeaderView.swift +++ b/HANE24/View/Home/HeaderView.swift @@ -9,13 +9,13 @@ import SwiftUI struct HeaderView: View { @Environment(\.colorScheme) var colorScheme - @EnvironmentObject var hane: Hane + @ObservedObject var homeManager: HomeVM var body: some View { VStack(alignment: .center, spacing: 20) { HStack(alignment: .center) { - if hane.profileImage != "" { - AsyncImage(url: URL(string: hane.profileImage)) { image in + if homeManager.mainInfo.profileImage != "" { + AsyncImage(url: URL(string: homeManager.mainInfo.profileImage)) { image in image .resizable() .scaledToFill() @@ -37,11 +37,11 @@ struct HeaderView: View { .foregroundColor(.iconColor) } - Text(hane.loginID) + Text(homeManager.mainInfo.login) .font(.system(size: 20, weight: .semibold, design: .rounded)) - .foregroundColor(!hane.isInCluster && colorScheme == .light ? .black : .white) + .foregroundColor(!homeManager.isInCluster && colorScheme == .light ? .black : .white) - if hane.isInCluster { + if homeManager.isInCluster { Circle() .foregroundColor(.green) .frame(width: 8, height: 8) @@ -60,5 +60,7 @@ struct HeaderView: View { } #Preview { - HeaderView() + @StateObject var homeVM = HomeVM() + + return HeaderView(homeManager: homeVM) } diff --git a/HANE24/View/Home/HomeView.swift b/HANE24/View/Home/HomeView.swift index d43ca42..19d6993 100644 --- a/HANE24/View/Home/HomeView.swift +++ b/HANE24/View/Home/HomeView.swift @@ -9,140 +9,100 @@ import SwiftUI struct HomeView: View { init(fundInfo: Binding, tagLatencyInfo: Binding) { -// UIPageControl.appearance().currentPageIndicatorTintColor = UIColor(Color.gradientPurple) -// UIPageControl.appearance().pageIndicatorTintColor = UIColor.gray.withAlphaComponent(0.2) - + // UIPageControl.appearance().currentPageIndicatorTintColor = UIColor(Color.gradientPurple) + // UIPageControl.appearance().pageIndicatorTintColor = UIColor.gray.withAlphaComponent(0.2) + self._isNoticedFundInfo = fundInfo self._isNoticedTagLatencyInfo = tagLatencyInfo } @State var test: Bool = true @Environment(\.colorScheme) var colorScheme @EnvironmentObject var hane: Hane - - @StateObject var homeManager = HomeVM() - + + @StateObject var homeManager = HomeVM() + @Binding var isNoticedFundInfo: Bool @Binding var isNoticedTagLatencyInfo: Bool - + var body: some View { - ZStack { - if homeManager.isInCluster { - Image("Background") - .resizable() - .edgesIgnoringSafeArea(.top) - .opacity(0.7) - } else { - Theme.backgroundColor(forScheme: colorScheme) - .edgesIgnoringSafeArea(colorScheme == .dark ? .all : .top) - } - VStack(alignment: .center, spacing: 20) { - HStack(alignment: .center) { - if homeManager.profileImage != "" { - AsyncImage(url: URL(string: hane.profileImage)) { image in - image - .resizable() - .scaledToFill() - .frame(width: 28, height: 28) - .clipShape(Circle()) - .padding(.trailing, 3) - } placeholder: { - Image(systemName: "person.circle") - .resizable() - .frame(width: 28, height: 28) - .padding(.trailing, 3) - .foregroundColor(.iconColor) - } - } else { - Image(systemName: "person.circle") - .resizable() - .frame(width: 28, height: 28) - .padding(.trailing, 3) - .foregroundColor(.iconColor) - } - - Text(homeManager.userID) - .font(.system(size: 20, weight: .semibold, design: .rounded)) - .foregroundColor(!hane.isInCluster && colorScheme == .light ? .black : .white) - - if homeManager.isInCluster { - Circle() - .foregroundColor(.green) - .frame(width: 8, height: 8) - .padding(.bottom, 10) - .padding(.leading, 0) + ZStack { + if homeManager.isInCluster { + Image("Background") + .resizable() + .edgesIgnoringSafeArea(.top) + .opacity(0.7) + } else { + Theme.backgroundColor(forScheme: colorScheme) + .edgesIgnoringSafeArea(colorScheme == .dark ? .all : .top) + } + VStack(alignment: .center, spacing: 20) { + HeaderView(homeManager: homeManager) + ScrollView { + PullToRefresh(coordinateSpaceName: "pullToRefresh") { + Task { + try await homeManager.refresh() } - - Spacer() } - .padding(.top, 20) - .frame(height: 30) - .padding(.horizontal, 30) - - ScrollView { - PullToRefresh(coordinateSpaceName: "pullToRefresh") { - Task { - try await hane.refresh() - } - } - - VStack(spacing: 22.5) { - TodayAccTimeCardView(homeManager: homeManager, isNoticed: $isNoticedTagLatencyInfo) - .padding(.horizontal, 30) - - ThisMonthAccTimeCardView(homeManager: homeManager, isNoticed: $isNoticedFundInfo) - .padding(.horizontal, 30) - - TabView { - ChartView(item: ChartItem(id: "주", title: "최근 주간 그래프", period: getWeeklyPeriod(), data: homeManager.sixWeekAccumulationTime)) - .padding(.horizontal, 10) - ChartView(item: ChartItem(id: "개월", title: "최근 월간 그래프", period: getMonthlyPeriod(), data: homeManager.sixMonthAccumulationTime)) - .padding(.horizontal, 10) - } - .padding(.horizontal, 20) - .tabViewStyle(.page) - .frame(height: 289) - - PopulationView(population: homeManager.clusterPopulation) - .padding(.horizontal, 30) + + VStack(spacing: 22.5) { + TodayAccTimeCardView(homeManager: homeManager, isNoticed: $isNoticedTagLatencyInfo) + .padding(.horizontal, 30) + + ThisMonthAccTimeCardView(homeManager: homeManager, isNoticed: $isNoticedFundInfo) + .padding(.horizontal, 30) + + TabView { + ChartView(item: ChartItem(id: "주", title: "최근 주간 그래프", period: getWeeklyPeriod(), data: homeManager.accumulationTimes.sixWeekAccumulationTime)) + .padding(.horizontal, 10) + ChartView(item: ChartItem(id: "개월", title: "최근 월간 그래프", period: getMonthlyPeriod(), data: homeManager.accumulationTimes.sixMonthAccumulationTime)) + .padding(.horizontal, 10) } - .padding(.bottom, 30) - .padding(.top, 10) - } .coordinateSpace(name: "pullToRefresh") - } + .padding(.horizontal, 20) + .tabViewStyle(.page) + .frame(height: 289) + + PopulationView(population: homeManager.mainInfo.gaepo) + .padding(.horizontal, 30) + } + .padding(.bottom, 30) + .padding(.top, 10) + } .coordinateSpace(name: "pullToRefresh") } - } + } } - - private func getWeeklyPeriod() -> [String] { - var weeklyPeriod: [String] = [] - var date = Date() - let formatter = DateFormatter() - formatter.locale = Locale(identifier: "ko_KR") - formatter.dateFormat = "M.dd(EEE)" - for _ in 0..<6 { - let startDay = formatter.string(from: date.startOfWeek!) - let endDay = formatter.string(from: date.endOfWeek!) - let period = startDay + " - " + endDay - weeklyPeriod.append(period) - date = Calendar.current.date(byAdding: .weekOfYear, value: -1, to: date)! - } - return weeklyPeriod - } +} - private func getMonthlyPeriod() -> [String] { - var monthlyPeriod: [String] = [] - var date = Date() - let formatter = DateFormatter() - formatter.dateFormat = "YYYY.M" - for _ in 0..<6 { - let period = formatter.string(from: date) - monthlyPeriod.append(period) - date = Calendar.current.date(byAdding: .month, value: -1, to: date)! - } - return monthlyPeriod - } +private func getWeeklyPeriod() -> [String] { + var weeklyPeriod: [String] = [] + var date = Date() + let formatter = DateFormatter() + formatter.locale = Locale(identifier: "ko_KR") + formatter.dateFormat = "M.dd(EEE)" + for _ in 0..<6 { + let startDay = formatter.string(from: date.startOfWeek!) + let endDay = formatter.string(from: date.endOfWeek!) + let period = startDay + " - " + endDay + weeklyPeriod.append(period) + date = Calendar.current.date(byAdding: .weekOfYear, value: -1, to: date)! + } + return weeklyPeriod } +private func getMonthlyPeriod() -> [String] { + var monthlyPeriod: [String] = [] + var date = Date() + let formatter = DateFormatter() + formatter.dateFormat = "YYYY.M" + for _ in 0..<6 { + let period = formatter.string(from: date) + monthlyPeriod.append(period) + date = Calendar.current.date(byAdding: .month, value: -1, to: date)! + } + return monthlyPeriod +} + + + #Preview { HomeView(fundInfo: .constant(false), tagLatencyInfo: .constant(false)) .environmentObject(Hane()) diff --git a/HANE24/View/Home/PopulationView.swift b/HANE24/View/Home/PopulationView.swift index 581428c..a1ecf64 100644 --- a/HANE24/View/Home/PopulationView.swift +++ b/HANE24/View/Home/PopulationView.swift @@ -40,7 +40,7 @@ struct PopulationView: View { } } -#Preview { - PopulationView() - .environmentObject(Hane()) -} +//#Preview { +// PopulationView() +// .environmentObject(Hane()) +//} diff --git a/HANE24/View/Home/ThisMonthAccTimeCardView.swift b/HANE24/View/Home/ThisMonthAccTimeCardView.swift index d03ad4b..fd5a427 100644 --- a/HANE24/View/Home/ThisMonthAccTimeCardView.swift +++ b/HANE24/View/Home/ThisMonthAccTimeCardView.swift @@ -38,11 +38,11 @@ struct ThisMonthAccTimeCardView: View { LoadingAnimation() } else { HStack(alignment: .bottom, spacing: 0) { - Text("\(homeManager.monthlyAccumulationTime / 3600)") + Text("\(homeManager.accumulationTimes.monthAccumulationTime / 3600)") .font(.system(size: 20, weight: .bold)) Text("시간 ") .font(.system(size: 16, weight: .bold)) - Text("\(homeManager.monthlyAccumulationTime % 3600 / 60)") + Text("\(homeManager.accumulationTimes.monthAccumulationTime % 3600 / 60)") .font(.system(size: 20, weight: .bold)) Text("분") .font(.system(size: 16, weight: .bold)) diff --git a/HANE24/ViewModel/HomeVM.swift b/HANE24/ViewModel/HomeVM.swift index 1bd1bae..f301ae7 100644 --- a/HANE24/ViewModel/HomeVM.swift +++ b/HANE24/ViewModel/HomeVM.swift @@ -8,27 +8,27 @@ import Foundation class HomeVM: ObservableObject { - @Published var isInCluster: Bool - @Published var profileImage: String - @Published var userID: String - @Published var clusterPopulation: Int + @Published var isInCluster: Bool +// @Published var profileImage: String +// @Published var userID: String +// @Published var clusterPopulation: Int - @Published var fundInfoNotice: Notice - @Published var tagLatencyNotice: Notice + @Published var fundInfoNotice: InfoMessage + @Published var tagLatencyNotice: InfoMessage /// 누적시간데이터 @Published var dailyAccumulationTime: Int64 = 0 - @Published var monthlyAccumulationTime: Int64 = 0 - @Published var sixWeekAccumulationTime: [Double] = Array(repeating: 0, count: 6) - @Published var sixMonthAccumulationTime: [Double] = Array(repeating: 0, count: 6) +// @Published var monthlyAccumulationTime: Int64 = 0 +// @Published var sixWeekAccumulationTime: [Double] = Array(repeating: 0, count: 6) +// @Published var sixMonthAccumulationTime: [Double] = Array(repeating: 0, count: 6) - @Published var accumulationTime: AccumulationTimes + @Published var accumulationTimes: AccumulationTimes @Published var isLoading: Bool - var mainInfo: MainInfo + @Published var mainInfo: MainInfo - var accumulationTimes: AccumulationTimes +// var accumulationTimes: AccumulationTimes var timer: Timer? var lastTag: Date? @@ -36,12 +36,12 @@ class HomeVM: ObservableObject { init() { self.isInCluster = false - self.profileImage = "" - self.userID = "" - self.clusterPopulation = 0 +// self.profileImage = "" +// self.userID = "" +// self.clusterPopulation = 0 - self.fundInfoNotice = Notice() - self.tagLatencyNotice = Notice( ) + self.fundInfoNotice = InfoMessage() + self.tagLatencyNotice = InfoMessage( ) self.isLoading = false @@ -51,7 +51,8 @@ class HomeVM: ObservableObject { self.lastTag = Date() - self.accumulationTime = AccumulationTimes() +// self.accumulationTime = AccumulationTimes() +// self.userInfo = MainInfo() self.timer = Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { [weak self] _ in guard let self = self else { return } @@ -62,47 +63,29 @@ class HomeVM: ObservableObject { } } } - - @MainActor - func updateUserInfo() async throws { - try await requestMainInfo() - - self.userID = mainInfo.login - self.profileImage = mainInfo.profileImage - self.isInCluster = mainInfo.inoutState == "IN" ? true : false - self.clusterPopulation = mainInfo.gaepo - } - - @MainActor - func updateNotice() async throws { - self.fundInfoNotice = Notice( - title: mainInfo.infoMessages.fundInfoNotice.title, - content: mainInfo.infoMessages.fundInfoNotice.content - ) - self.tagLatencyNotice = Notice( - title: mainInfo.infoMessages.tagLatencyNotice.title, - content: mainInfo.infoMessages.tagLatencyNotice.content - ) - } - + @MainActor - func updateAccumulationTime() async throws { - + func updateAccumulationTimes() async throws { + guard let accTimes = try await NetworkManager.shared.getRequest("/v3/tag-log/accumulationTimes", type: AccumulationTimes.self) else { + throw MyError.tokenExpired("") + } + self.accumulationTimes = accTimes + self.dailyAccumulationTime = accTimes.todayAccumulationTime } //TODO: 요청한 데이터가 nil일 경우 에러 핸들링 - func requestMainInfo() async throws { + func updateMainInfo() async throws { guard let mainInfo = try await NetworkManager.shared.getRequest("/v3/tag-log/maininfo", type: MainInfo.self) else { throw MyError.tokenExpired("") } self.mainInfo = mainInfo + self.isInCluster = mainInfo.inoutState == "IN" + self.fundInfoNotice = mainInfo.infoMessages.fundInfoNotice + self.tagLatencyNotice = mainInfo.infoMessages.tagLatencyNotice } - - @MainActor - func requestAccumulationTime() async throws { - guard let accTimes = try await NetworkManager.shared.getRequest("/v3/tag-log/accumulationTimes", type: AccumulationTimes.self) else { - throw MyError.tokenExpired("") - } - self.accumulationTime = accTimes - } + + func refresh() async throws { + try await self.updateMainInfo() + try await self.updateAccumulationTimes() + } } From 14f5afc4a891b4d445aa70a9f39a1b3e46759350 Mon Sep 17 00:00:00 2001 From: Hee Ju Jang <01kathyy@gmail.com> Date: Fri, 3 May 2024 16:33:15 +0900 Subject: [PATCH 13/15] refactor Home & homeView --- HANE24.xcworkspace/contents.xcworkspacedata | 3 -- HANE24/Model/JSONs.swift | 12 +++--- HANE24/Model/Structs.swift | 2 +- HANE24/Utils/DateExtensions.swift | 2 +- HANE24/View/Home/CircularProgressBar.swift | 6 +-- HANE24/View/Home/HeaderView.swift | 6 +-- HANE24/View/Home/HomeView.swift | 41 ++++++++++--------- HANE24/View/Home/NoticeModifier.swift | 4 +- HANE24/View/Home/PopulationView.swift | 5 --- .../View/Home/ThisMonthAccTimeCardView.swift | 2 +- HANE24/View/MainView.swift | 4 +- HANE24/ViewModel/HomeVM.swift | 39 +++++++++--------- HANE24/ViewModel/NetworkManager.swift | 8 ++-- HANE24TEST/HANE24Test.swift | 2 +- HANE24Widget/HANE24Widget.swift | 4 +- HANE24Widget/HANE24WidgetConstant.swift | 1 - 16 files changed, 68 insertions(+), 73 deletions(-) diff --git a/HANE24.xcworkspace/contents.xcworkspacedata b/HANE24.xcworkspace/contents.xcworkspacedata index 73fa4a9..03d59d0 100644 --- a/HANE24.xcworkspace/contents.xcworkspacedata +++ b/HANE24.xcworkspace/contents.xcworkspacedata @@ -1,9 +1,6 @@ - - diff --git a/HANE24/Model/JSONs.swift b/HANE24/Model/JSONs.swift index 8b144df..c349a9a 100644 --- a/HANE24/Model/JSONs.swift +++ b/HANE24/Model/JSONs.swift @@ -25,7 +25,7 @@ struct PerMonth: Codable { struct InfoMessage: Codable { let title: String let content: String - + init() { self.title = "" self.content = "" @@ -35,7 +35,7 @@ struct InfoMessage: Codable { struct InfoMessages: Codable { let fundInfoNotice: InfoMessage let tagLatencyNotice: InfoMessage - + init() { self.fundInfoNotice = InfoMessage() self.tagLatencyNotice = InfoMessage() @@ -51,7 +51,7 @@ struct MainInfo: Codable { let gaepo: Int /// v3 let infoMessages: InfoMessages - + init() { self.login = "" self.profileImage = "" @@ -70,12 +70,12 @@ struct AccumulationTimes: Codable { let sixMonthAccumulationTime: [Double] /// v3 let monthlyAcceptedAccumulationTime: Int64 - + init() { self.todayAccumulationTime = 0 self.monthAccumulationTime = 0 - self.sixWeekAccumulationTime = [] - self.sixMonthAccumulationTime = [] + self.sixWeekAccumulationTime = Array(repeating: 0, count: 6) + self.sixMonthAccumulationTime = Array(repeating: 0, count: 6) self.monthlyAcceptedAccumulationTime = 0 } } diff --git a/HANE24/Model/Structs.swift b/HANE24/Model/Structs.swift index 51be008..72b1e4b 100644 --- a/HANE24/Model/Structs.swift +++ b/HANE24/Model/Structs.swift @@ -34,7 +34,7 @@ struct MoreItem: Identifiable { struct Notice { var title: String var content: String - + init(title: String = "", content: String = "") { self.title = title self.content = content diff --git a/HANE24/Utils/DateExtensions.swift b/HANE24/Utils/DateExtensions.swift index 5dc372e..350202d 100644 --- a/HANE24/Utils/DateExtensions.swift +++ b/HANE24/Utils/DateExtensions.swift @@ -164,7 +164,7 @@ extension Date { var daysOfMonth: [Date?] { var days: [Date?] = [] var day = self.firstDay - + for _ in 1.. var percentage: Int - + init(drawingStroke: Binding, objectiveTime: Double, progressiveTime: Double) { self.percentage = Int(progressiveTime / objectiveTime * 3600) * 100 self.drawingStroke = drawingStroke } - + var body: some View { ZStack { HStack(spacing: 0) { diff --git a/HANE24/View/Home/HeaderView.swift b/HANE24/View/Home/HeaderView.swift index 9affd3e..cd8f3df 100644 --- a/HANE24/View/Home/HeaderView.swift +++ b/HANE24/View/Home/HeaderView.swift @@ -10,7 +10,7 @@ import SwiftUI struct HeaderView: View { @Environment(\.colorScheme) var colorScheme @ObservedObject var homeManager: HomeVM - + var body: some View { VStack(alignment: .center, spacing: 20) { HStack(alignment: .center) { @@ -36,11 +36,11 @@ struct HeaderView: View { .padding(.trailing, 3) .foregroundColor(.iconColor) } - + Text(homeManager.mainInfo.login) .font(.system(size: 20, weight: .semibold, design: .rounded)) .foregroundColor(!homeManager.isInCluster && colorScheme == .light ? .black : .white) - + if homeManager.isInCluster { Circle() .foregroundColor(.green) diff --git a/HANE24/View/Home/HomeView.swift b/HANE24/View/Home/HomeView.swift index 19d6993..7ab70fb 100644 --- a/HANE24/View/Home/HomeView.swift +++ b/HANE24/View/Home/HomeView.swift @@ -8,22 +8,24 @@ import SwiftUI struct HomeView: View { - init(fundInfo: Binding, tagLatencyInfo: Binding) { - // UIPageControl.appearance().currentPageIndicatorTintColor = UIColor(Color.gradientPurple) - // UIPageControl.appearance().pageIndicatorTintColor = UIColor.gray.withAlphaComponent(0.2) - - self._isNoticedFundInfo = fundInfo - self._isNoticedTagLatencyInfo = tagLatencyInfo - } +// init(homeManageR: HomeVM, fundInfo: Binding, tagLatencyInfo: Binding) { +// // UIPageControl.appearance().currentPageIndicatorTintColor = UIColor(Color.gradientPurple) +// // UIPageControl.appearance().pageIndicatorTintColor = UIColor.gray.withAlphaComponent(0.2) +// +// self._isNoticedFundInfo = fundInfo +// self._isNoticedTagLatencyInfo = tagLatencyInfo +// self._ +// } + @State var test: Bool = true @Environment(\.colorScheme) var colorScheme @EnvironmentObject var hane: Hane - - @StateObject var homeManager = HomeVM() - + + @ObservedObject var homeManager: HomeVM + @Binding var isNoticedFundInfo: Bool @Binding var isNoticedTagLatencyInfo: Bool - + var body: some View { ZStack { if homeManager.isInCluster { @@ -43,14 +45,14 @@ struct HomeView: View { try await homeManager.refresh() } } - + VStack(spacing: 22.5) { TodayAccTimeCardView(homeManager: homeManager, isNoticed: $isNoticedTagLatencyInfo) .padding(.horizontal, 30) - + ThisMonthAccTimeCardView(homeManager: homeManager, isNoticed: $isNoticedFundInfo) .padding(.horizontal, 30) - + TabView { ChartView(item: ChartItem(id: "주", title: "최근 주간 그래프", period: getWeeklyPeriod(), data: homeManager.accumulationTimes.sixWeekAccumulationTime)) .padding(.horizontal, 10) @@ -60,7 +62,6 @@ struct HomeView: View { .padding(.horizontal, 20) .tabViewStyle(.page) .frame(height: 289) - PopulationView(population: homeManager.mainInfo.gaepo) .padding(.horizontal, 30) } @@ -102,8 +103,8 @@ private func getMonthlyPeriod() -> [String] { } - -#Preview { - HomeView(fundInfo: .constant(false), tagLatencyInfo: .constant(false)) - .environmentObject(Hane()) -} +// +//#Preview { +// HomeView(fundInfo: .constant(false), tagLatencyInfo: .constant(false)) +// .environmentObject(Hane()) +//} diff --git a/HANE24/View/Home/NoticeModifier.swift b/HANE24/View/Home/NoticeModifier.swift index f2a48b1..348f574 100644 --- a/HANE24/View/Home/NoticeModifier.swift +++ b/HANE24/View/Home/NoticeModifier.swift @@ -10,9 +10,9 @@ import SwiftUI //MARK: unused in V3 public struct NoticeModifier: ViewModifier { @Binding var isPresent: Bool - + let notice: NoticeView - + public func body(content: Content) -> some View { content .fullScreenCover(isPresented: $isPresent) { diff --git a/HANE24/View/Home/PopulationView.swift b/HANE24/View/Home/PopulationView.swift index a1ecf64..b2e077b 100644 --- a/HANE24/View/Home/PopulationView.swift +++ b/HANE24/View/Home/PopulationView.swift @@ -39,8 +39,3 @@ struct PopulationView: View { } } } - -//#Preview { -// PopulationView() -// .environmentObject(Hane()) -//} diff --git a/HANE24/View/Home/ThisMonthAccTimeCardView.swift b/HANE24/View/Home/ThisMonthAccTimeCardView.swift index fd5a427..c80828a 100644 --- a/HANE24/View/Home/ThisMonthAccTimeCardView.swift +++ b/HANE24/View/Home/ThisMonthAccTimeCardView.swift @@ -90,7 +90,7 @@ struct ThisMonthAccTimeCardView: View { if hane.loading { LoadingAnimation() } else { - //TODO: hane -> homeVM + // TODO: hane -> homeVM HStack(alignment: .bottom, spacing: 0) { Text("\(hane.thisMonthAcceptedAccumulationTime / 3600)") .font(.system(size: 20, weight: .bold)) diff --git a/HANE24/View/MainView.swift b/HANE24/View/MainView.swift index 34c0d0e..b0d5853 100644 --- a/HANE24/View/MainView.swift +++ b/HANE24/View/MainView.swift @@ -10,6 +10,7 @@ import SwiftUI struct MainView: View { @EnvironmentObject var hane: Hane @EnvironmentObject var calendar: CalendarVM + @StateObject var homeVM = HomeVM() @State var selection = 1 @Environment(\.colorScheme) var colorScheme @@ -20,7 +21,7 @@ struct MainView: View { var body: some View { ZStack { TabView(selection: $selection) { - HomeView(fundInfo: $isNoticedFundInfo, tagLatencyInfo: $isNoticedTagLatencyInfo) + HomeView(homeManager: homeVM, isNoticedFundInfo: $isNoticedFundInfo, isNoticedTagLatencyInfo: $isNoticedTagLatencyInfo) .tabItem({ Image(selection == 1 ? "selectedHome" : "home").renderingMode(.template) }) .tag(1) @@ -39,6 +40,7 @@ struct MainView: View { .task { do { try await hane.refresh() + try await homeVM.refresh() try await calendar.updateMonthlyLogs(date: .now) } catch { print("error on MainView \(error.localizedDescription)") diff --git a/HANE24/ViewModel/HomeVM.swift b/HANE24/ViewModel/HomeVM.swift index f301ae7..39bfbef 100644 --- a/HANE24/ViewModel/HomeVM.swift +++ b/HANE24/ViewModel/HomeVM.swift @@ -12,48 +12,47 @@ class HomeVM: ObservableObject { // @Published var profileImage: String // @Published var userID: String // @Published var clusterPopulation: Int - + @Published var fundInfoNotice: InfoMessage @Published var tagLatencyNotice: InfoMessage - + /// 누적시간데이터 @Published var dailyAccumulationTime: Int64 = 0 // @Published var monthlyAccumulationTime: Int64 = 0 // @Published var sixWeekAccumulationTime: [Double] = Array(repeating: 0, count: 6) // @Published var sixMonthAccumulationTime: [Double] = Array(repeating: 0, count: 6) - + @Published var accumulationTimes: AccumulationTimes - + @Published var isLoading: Bool - + @Published var mainInfo: MainInfo - + // var accumulationTimes: AccumulationTimes - + var timer: Timer? var lastTag: Date? - init() { self.isInCluster = false // self.profileImage = "" // self.userID = "" // self.clusterPopulation = 0 - - self.fundInfoNotice = InfoMessage() + + self.fundInfoNotice = InfoMessage() self.tagLatencyNotice = InfoMessage( ) - + self.isLoading = false - + self.mainInfo = MainInfo() - + self.accumulationTimes = AccumulationTimes() - + self.lastTag = Date() - + // self.accumulationTime = AccumulationTimes() // self.userInfo = MainInfo() - + self.timer = Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { [weak self] _ in guard let self = self else { return } guard self.isInCluster else { return } @@ -72,9 +71,10 @@ class HomeVM: ObservableObject { self.accumulationTimes = accTimes self.dailyAccumulationTime = accTimes.todayAccumulationTime } - -//TODO: 요청한 데이터가 nil일 경우 에러 핸들링 - func updateMainInfo() async throws { + + //TODO: 요청한 데이터가 nil일 경우 에러 핸들링 + @MainActor + func updateMainInfo() async throws { guard let mainInfo = try await NetworkManager.shared.getRequest("/v3/tag-log/maininfo", type: MainInfo.self) else { throw MyError.tokenExpired("") } @@ -84,6 +84,7 @@ class HomeVM: ObservableObject { self.tagLatencyNotice = mainInfo.infoMessages.tagLatencyNotice } + @MainActor func refresh() async throws { try await self.updateMainInfo() try await self.updateAccumulationTimes() diff --git a/HANE24/ViewModel/NetworkManager.swift b/HANE24/ViewModel/NetworkManager.swift index 734700f..3451c55 100644 --- a/HANE24/ViewModel/NetworkManager.swift +++ b/HANE24/ViewModel/NetworkManager.swift @@ -18,9 +18,9 @@ protocol NetworkProtocol { } class NetworkManager: NetworkProtocol { - + static let shared = NetworkManager() - + var session: URLSession var apiRoot: String @@ -39,7 +39,7 @@ class NetworkManager: NetworkProtocol { /// FIXME: token invalid 경우에 signIn 상태 변경 throw MyError.tokenExpired("get new token!") } - + var request = URLRequest(url: url) request.httpMethod = "GET" request.allHTTPHeaderFields = [ @@ -88,7 +88,7 @@ class NetworkManager: NetworkProtocol { throw MyError.tokenExpired("request Failed") } } - + func deleteRequest(_ urlPath: String) async throws { guard let url = URL(string: apiRoot + urlPath) else { return diff --git a/HANE24TEST/HANE24Test.swift b/HANE24TEST/HANE24Test.swift index 6f0fe23..aa8e7b2 100644 --- a/HANE24TEST/HANE24Test.swift +++ b/HANE24TEST/HANE24Test.swift @@ -164,5 +164,5 @@ final class HaneCalendarTest: XCTestCase { } // MARK: - Missing Data Test - + } diff --git a/HANE24Widget/HANE24Widget.swift b/HANE24Widget/HANE24Widget.swift index dcc5ee2..25e1780 100644 --- a/HANE24Widget/HANE24Widget.swift +++ b/HANE24Widget/HANE24Widget.swift @@ -95,7 +95,7 @@ struct HANE24WidgetEntryView: View { .foregroundStyle(colorScheme == .dark ? Color(hex: "#EAEAEA") : Color(hex: "#707070")) .allowsTightening(true) } - + HStack { Rectangle() .frame(width: 2, height: 32) @@ -109,7 +109,7 @@ struct HANE24WidgetEntryView: View { } } .padding(.top, 18) - + HStack { Rectangle() .frame(width: 2, height: 32) diff --git a/HANE24Widget/HANE24WidgetConstant.swift b/HANE24Widget/HANE24WidgetConstant.swift index 991afee..471b235 100644 --- a/HANE24Widget/HANE24WidgetConstant.swift +++ b/HANE24Widget/HANE24WidgetConstant.swift @@ -8,7 +8,6 @@ import Foundation import WidgetKit - struct HaneWidgetConstant { static var storageKey = "accessToken" static var appGroupName = "group.24HoursAreNotEnough" From e0a973dea2ca6f3203abd752dbe7ff7fc16462f3 Mon Sep 17 00:00:00 2001 From: Hee Ju Jang <01kathyy@gmail.com> Date: Fri, 3 May 2024 16:40:51 +0900 Subject: [PATCH 14/15] FIX: delete unused code --- HANE24/ViewModel/HomeVM.swift | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/HANE24/ViewModel/HomeVM.swift b/HANE24/ViewModel/HomeVM.swift index 39bfbef..0dc91df 100644 --- a/HANE24/ViewModel/HomeVM.swift +++ b/HANE24/ViewModel/HomeVM.swift @@ -9,35 +9,23 @@ import Foundation class HomeVM: ObservableObject { @Published var isInCluster: Bool -// @Published var profileImage: String -// @Published var userID: String -// @Published var clusterPopulation: Int @Published var fundInfoNotice: InfoMessage @Published var tagLatencyNotice: InfoMessage /// 누적시간데이터 @Published var dailyAccumulationTime: Int64 = 0 -// @Published var monthlyAccumulationTime: Int64 = 0 -// @Published var sixWeekAccumulationTime: [Double] = Array(repeating: 0, count: 6) -// @Published var sixMonthAccumulationTime: [Double] = Array(repeating: 0, count: 6) - @Published var accumulationTimes: AccumulationTimes @Published var isLoading: Bool @Published var mainInfo: MainInfo -// var accumulationTimes: AccumulationTimes - - var timer: Timer? + var timer: Timer? var lastTag: Date? init() { self.isInCluster = false -// self.profileImage = "" -// self.userID = "" -// self.clusterPopulation = 0 self.fundInfoNotice = InfoMessage() self.tagLatencyNotice = InfoMessage( ) @@ -50,9 +38,6 @@ class HomeVM: ObservableObject { self.lastTag = Date() -// self.accumulationTime = AccumulationTimes() -// self.userInfo = MainInfo() - self.timer = Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { [weak self] _ in guard let self = self else { return } guard self.isInCluster else { return } From 87596b71dd52ef409b2359f251c5278bba168090 Mon Sep 17 00:00:00 2001 From: Hee Ju Jang <01kathyy@gmail.com> Date: Sun, 19 May 2024 15:06:25 +0900 Subject: [PATCH 15/15] =?UTF-8?q?=20=ED=94=BC=EB=93=9C=EB=B0=B1=20?= =?UTF-8?q?=EA=B8=B0=EB=B0=98=20=EC=BD=94=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HANE24.xcodeproj/project.pbxproj | 16 ++++------ ...{HeaderView.swift => HomeHeaderView.swift} | 4 +-- HANE24/View/Home/HomeView.swift | 2 +- HANE24/View/Home/NoticeModifier.swift | 31 ------------------- HANE24/View/Home/NoticeView.swift | 6 ++-- 5 files changed, 11 insertions(+), 48 deletions(-) rename HANE24/View/Home/{HeaderView.swift => HomeHeaderView.swift} (95%) delete mode 100644 HANE24/View/Home/NoticeModifier.swift diff --git a/HANE24.xcodeproj/project.pbxproj b/HANE24.xcodeproj/project.pbxproj index 5327fd3..5cc2d0d 100644 --- a/HANE24.xcodeproj/project.pbxproj +++ b/HANE24.xcodeproj/project.pbxproj @@ -7,7 +7,6 @@ objects = { /* Begin PBXBuildFile section */ - 0E0FE5F12BB3DDA30050498E /* NoticeModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0FE5F02BB3DDA30050498E /* NoticeModifier.swift */; }; 0E0FE5F32BB3E6110050498E /* CircularProgressBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0FE5F22BB3E6110050498E /* CircularProgressBar.swift */; }; 0E0FE5F42BB3E6180050498E /* CircularProgressBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0FE5F22BB3E6110050498E /* CircularProgressBar.swift */; }; 0E1654F3299A285B001E5EED /* HANE24App.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E1654F2299A285B001E5EED /* HANE24App.swift */; }; @@ -40,9 +39,9 @@ 0ED6E3FC2B354DFC0026E69D /* HANE24WidgetConstant.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ED6E3FA2B354DFC0026E69D /* HANE24WidgetConstant.swift */; }; 0ED6E3FF2B354E670026E69D /* AccumulationTimeStruct.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ED6E3FE2B354E670026E69D /* AccumulationTimeStruct.swift */; }; 0ED6E4002B354E670026E69D /* AccumulationTimeStruct.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0ED6E3FE2B354E670026E69D /* AccumulationTimeStruct.swift */; }; - 0EE06CBF2BB2AD4C00B4988C /* HeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EE06CBE2BB2AD4C00B4988C /* HeaderView.swift */; }; - 0EE06CC12BB2B2EB00B4988C /* PullToRefresh.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EE06CC02BB2B2EB00B4988C /* PullToRefresh.swift */; }; 0EE06CBD2BB2819500B4988C /* HomeVM.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EE06CBC2BB2819500B4988C /* HomeVM.swift */; }; + 0EE06CBF2BB2AD4C00B4988C /* HomeHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EE06CBE2BB2AD4C00B4988C /* HomeHeaderView.swift */; }; + 0EE06CC12BB2B2EB00B4988C /* PullToRefresh.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EE06CC02BB2B2EB00B4988C /* PullToRefresh.swift */; }; 0EE58193299CC24000EE3351 /* MoreView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EE58192299CC24000EE3351 /* MoreView.swift */; }; 0EE58198299CC74C00EE3351 /* ReissuanceView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EE58197299CC74C00EE3351 /* ReissuanceView.swift */; }; 0EEB0E2429AE2AF700FEB700 /* CardProgressView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EEB0E2329AE2AF700FEB700 /* CardProgressView.swift */; }; @@ -98,7 +97,6 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ - 0E0FE5F02BB3DDA30050498E /* NoticeModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoticeModifier.swift; sourceTree = ""; }; 0E0FE5F22BB3E6110050498E /* CircularProgressBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CircularProgressBar.swift; sourceTree = ""; }; 0E1654EF299A285B001E5EED /* 24HANE.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = 24HANE.app; sourceTree = BUILT_PRODUCTS_DIR; }; 0E1654F2299A285B001E5EED /* HANE24App.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HANE24App.swift; sourceTree = ""; }; @@ -130,9 +128,9 @@ 0ED6E3FE2B354E670026E69D /* AccumulationTimeStruct.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccumulationTimeStruct.swift; sourceTree = ""; }; 0ED6E4032B3559B80026E69D /* 24HANE.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = 24HANE.entitlements; sourceTree = ""; }; 0ED6E4042B3559DF0026E69D /* HANE24WidgetExtension.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = HANE24WidgetExtension.entitlements; sourceTree = ""; }; - 0EE06CBE2BB2AD4C00B4988C /* HeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HeaderView.swift; sourceTree = ""; }; - 0EE06CC02BB2B2EB00B4988C /* PullToRefresh.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PullToRefresh.swift; sourceTree = ""; }; 0EE06CBC2BB2819500B4988C /* HomeVM.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeVM.swift; sourceTree = ""; }; + 0EE06CBE2BB2AD4C00B4988C /* HomeHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeHeaderView.swift; sourceTree = ""; }; + 0EE06CC02BB2B2EB00B4988C /* PullToRefresh.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PullToRefresh.swift; sourceTree = ""; }; 0EE58192299CC24000EE3351 /* MoreView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoreView.swift; sourceTree = ""; }; 0EE58197299CC74C00EE3351 /* ReissuanceView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReissuanceView.swift; sourceTree = ""; }; 0EEB0E2329AE2AF700FEB700 /* CardProgressView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardProgressView.swift; sourceTree = ""; }; @@ -260,11 +258,10 @@ 0E0FE5F22BB3E6110050498E /* CircularProgressBar.swift */, 0E165507299A3C20001E5EED /* ChartView.swift */, 0E16550B299A3DF6001E5EED /* ChartDetailView.swift */, - 0EE06CBE2BB2AD4C00B4988C /* HeaderView.swift */, + 0EE06CBE2BB2AD4C00B4988C /* HomeHeaderView.swift */, 0E17EFA9299B5C0A0089BCD8 /* PopulationView.swift */, 2B1326102B2821E600301A8B /* ThisMonthAccTimeCardView.swift */, 2B1326122B285B1D00301A8B /* NoticeView.swift */, - 0E0FE5F02BB3DDA30050498E /* NoticeModifier.swift */, ); path = Home; sourceTree = ""; @@ -566,7 +563,7 @@ 0EE06CC12BB2B2EB00B4988C /* PullToRefresh.swift in Sources */, 0E3ED8A82BB13727001B0BAE /* NetworkManager.swift in Sources */, 0E9868252B2B6C0B00E127DC /* CalendarHeaderView.swift in Sources */, - 0EE06CBF2BB2AD4C00B4988C /* HeaderView.swift in Sources */, + 0EE06CBF2BB2AD4C00B4988C /* HomeHeaderView.swift in Sources */, 0EBBF14E29B08D580076AAB9 /* ErrorView.swift in Sources */, 0E9868272B2B76BE00E127DC /* CalendarBodyView.swift in Sources */, 9AF730ED299CC54F00AF2E53 /* DateExtensions.swift in Sources */, @@ -576,7 +573,6 @@ 9AF730F6299E074800AF2E53 /* Structs.swift in Sources */, 0E3B32A929A3815B001D10BF /* SignInWebView.swift in Sources */, 0EE58198299CC74C00EE3351 /* ReissuanceView.swift in Sources */, - 0E0FE5F12BB3DDA30050498E /* NoticeModifier.swift in Sources */, 0E16550A299A3D8A001E5EED /* ColorExtension.swift in Sources */, 0E16550C299A3DF6001E5EED /* ChartDetailView.swift in Sources */, 9AF730FB299F53C700AF2E53 /* HaneVM.swift in Sources */, diff --git a/HANE24/View/Home/HeaderView.swift b/HANE24/View/Home/HomeHeaderView.swift similarity index 95% rename from HANE24/View/Home/HeaderView.swift rename to HANE24/View/Home/HomeHeaderView.swift index cd8f3df..ed9ae22 100644 --- a/HANE24/View/Home/HeaderView.swift +++ b/HANE24/View/Home/HomeHeaderView.swift @@ -7,7 +7,7 @@ import SwiftUI -struct HeaderView: View { +struct HomeHeaderView: View { @Environment(\.colorScheme) var colorScheme @ObservedObject var homeManager: HomeVM @@ -62,5 +62,5 @@ struct HeaderView: View { #Preview { @StateObject var homeVM = HomeVM() - return HeaderView(homeManager: homeVM) + return HomeHeaderView(homeManager: homeVM) } diff --git a/HANE24/View/Home/HomeView.swift b/HANE24/View/Home/HomeView.swift index 7ab70fb..d079f64 100644 --- a/HANE24/View/Home/HomeView.swift +++ b/HANE24/View/Home/HomeView.swift @@ -38,7 +38,7 @@ struct HomeView: View { .edgesIgnoringSafeArea(colorScheme == .dark ? .all : .top) } VStack(alignment: .center, spacing: 20) { - HeaderView(homeManager: homeManager) + HomeHeaderView(homeManager: homeManager) ScrollView { PullToRefresh(coordinateSpaceName: "pullToRefresh") { Task { diff --git a/HANE24/View/Home/NoticeModifier.swift b/HANE24/View/Home/NoticeModifier.swift deleted file mode 100644 index 348f574..0000000 --- a/HANE24/View/Home/NoticeModifier.swift +++ /dev/null @@ -1,31 +0,0 @@ -// -// NoticeModifier.swift -// 24HANE -// -// Created by Katherine JANG on 3/27/24. -// - -import SwiftUI - -//MARK: unused in V3 -public struct NoticeModifier: ViewModifier { - @Binding var isPresent: Bool - - let notice: NoticeView - - public func body(content: Content) -> some View { - content - .fullScreenCover(isPresented: $isPresent) { - notice - } - .transaction { transaction in - transaction.disablesAnimations = true - } - } -} - -extension View { - public func noticeAlert(isPresented: Binding, noticeAlert: @escaping () -> NoticeView) -> some View { - return modifier(NoticeModifier(isPresent: isPresented, notice: noticeAlert())) - } -} diff --git a/HANE24/View/Home/NoticeView.swift b/HANE24/View/Home/NoticeView.swift index 15a745b..3f925d1 100644 --- a/HANE24/View/Home/NoticeView.swift +++ b/HANE24/View/Home/NoticeView.swift @@ -7,12 +7,10 @@ import SwiftUI -//MARK: unused in V3 - public struct NoticeView: View { @Binding var showNotice: Bool - var notice: Notice - public var body: some View { + var notice: Notice + public var body: some View { ZStack { Color.black.opacity(0.4) .ignoresSafeArea(.all)