Skip to content

Commit

Permalink
Merge pull request #114 from TeamHY2/Fix/#112-WeeklyStudy_Star
Browse files Browse the repository at this point in the history
[Fix/#112/#111] 주간 열람실 이용횟수 관련 피드백을 반영합니다.
  • Loading branch information
Seokki-Kwon authored Nov 28, 2024
2 parents fb095ac + 94cc714 commit 0dd0717
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 19 deletions.
8 changes: 4 additions & 4 deletions HongikYeolgong2.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1534,7 +1534,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 10;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"HongikYeolgong2/Resources/Preview Content\"";
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = P4D4ZQC4YF;
Expand All @@ -1556,7 +1556,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.1.0;
MARKETING_VERSION = 1.1.1;
PRODUCT_BUNDLE_IDENTIFIER = com.teamHY2.HongikYeolgong2;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -1581,7 +1581,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 10;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"HongikYeolgong2/Resources/Preview Content\"";
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = P4D4ZQC4YF;
Expand All @@ -1603,7 +1603,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.1.0;
MARKETING_VERSION = 1.1.1;
PRODUCT_BUNDLE_IDENTIFIER = com.teamHY2.HongikYeolgong2;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation

struct WeeklyStudyRecord {
let monthOfDay: String
let studyCount: Int
var studyCount: Int
let isUpcomming: Bool

var imageName: String {
Expand Down
19 changes: 18 additions & 1 deletion HongikYeolgong2/Domain/Interactors/WeeklyStudyInteractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ import SwiftUI
protocol WeeklyStudyInteractor {
func getWeekyStudy(studyRecords: LoadableSubject<[WeeklyStudyRecord]>)
func getWiseSaying(wiseSaying: LoadableSubject<WiseSaying>)
func addStarCount(studyRecords: LoadableSubject<[WeeklyStudyRecord]>)
}

final class WeeklyStudyInteractorImpl: WeeklyStudyInteractor {
private let appState: Store<AppState>
private let cancleBag = CancelBag()
private let studySessionRepository: StudySessionRepository

init(appState: Store<AppState>,
init(appState: Store<AppState>,
studySessionRepository: StudySessionRepository) {
self.appState = appState
self.studySessionRepository = studySessionRepository
Expand All @@ -37,4 +38,20 @@ final class WeeklyStudyInteractorImpl: WeeklyStudyInteractor {
.sinkToLoadble(wiseSaying)
.store(in: cancleBag)
}

func addStarCount(studyRecords: LoadableSubject<[WeeklyStudyRecord]>) {
guard var newStudyRecords = studyRecords.wrappedValue.value else {
return
}
let dayOffset = (Date().getDayOffset() + 6) % 7
newStudyRecords = newStudyRecords.enumerated().map {
if $0.offset == dayOffset {
var newElement = $0.element
newElement.studyCount += 1
return newElement
}
return $0.element
}
studyRecords.wrappedValue.setSuccess(value: newStudyRecords)
}
}
19 changes: 14 additions & 5 deletions HongikYeolgong2/Presentation/Home/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ struct HomeView: View {
get: { appState.value.studySession.startTime },
set: { studySessionInteractor.setStartTime($0) }
),
onTimeSelected: { studySessionInteractor.startStudy() }
onTimeSelected: startStudy
)
}
.systemOverlay(isPresented: $shouldShowAddTimeModal) {
Expand All @@ -85,7 +85,7 @@ struct HomeView: View {
title: "열람실을 다 이용하셨나요?",
confirmButtonText: "",
cancleButtonText: "더 이용하기",
confirmAction: { studySessionInteractor.endStudy()})
confirmAction: endStudy )
}
.padding(.horizontal, 32.adjustToScreenWidth)
.modifier(IOSBackground())
Expand All @@ -97,7 +97,7 @@ struct HomeView: View {
studySession = $0
}
.onReceive(studySessionEnded) { _ in
studySessionInteractor.endStudy()
endStudy()
}
.onReceive(studySessionUploaded) { _ in
weeklyStudyInteractor.getWeekyStudy(studyRecords: $studyRecords)
Expand All @@ -114,12 +114,10 @@ struct HomeView: View {
extension HomeView {
func endButtonTapped() {
shouldShowEndUseModal.toggle()
Amplitude.instance.track(eventType: "StudyEndButton")
}

func startButtonTapped() {
shouldShowTimePicker.toggle()
Amplitude.instance.track(eventType: "StudyStartButton")
}

func seatButtonTapped() {
Expand All @@ -131,6 +129,17 @@ extension HomeView {
Amplitude.instance.track(eventType: "StudyExtendButton")
}

func startStudy() {
studySessionInteractor.startStudy()
weeklyStudyInteractor.addStarCount(studyRecords: $studyRecords)
Amplitude.instance.track(eventType: "StudyStartButton")
}

func endStudy() {
studySessionInteractor.endStudy()
Amplitude.instance.track(eventType: "StudyEndButton")
}

func retryAction() {
weeklyStudyInteractor.getWeekyStudy(studyRecords: $studyRecords)
weeklyStudyInteractor.getWiseSaying(wiseSaying: $wiseSaying)
Expand Down
6 changes: 6 additions & 0 deletions HongikYeolgong2/Util/Extensions/Date+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,10 @@ extension Date {
dateFormatter.dateFormat = "yyyy"
return dateFormatter.string(from: self)
}

func getDayOffset() -> Int {
let calendar = Calendar.current
let components = calendar.dateComponents([.weekday], from: self)
return components.weekday! - 1
}
}
23 changes: 15 additions & 8 deletions HongikYeolgong2/Util/Extensions/String+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,21 @@ extension String {
}()

/// 문자열 형식의 날짜를 Date 객체로 변환합니다.
/// - Returns: Date
func toDate() -> Date? {
let dateFormatter = Self.dateFormatter
guard let date = dateFormatter.date(from: self) else {
return nil
}
return date
}
/// - Returns: Date
func toDate() -> Date? {
let dateFormatter = Self.dateFormatter
let currentYear = Calendar.current.component(.year, from: Date())

dateFormatter.dateFormat = "M/dd"
guard let date = dateFormatter.date(from: self) else {
return nil
}

var components = Calendar.current.dateComponents([.year, .month, .day], from: date)
components.year = currentYear

return Calendar.current.date(from: components)
}

func toDayofDate() -> String {
guard let date = self.toDate() else {
Expand Down

0 comments on commit 0dd0717

Please sign in to comment.