Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactor] Home 리팩토링 #80

Open
wants to merge 12 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Soomsil-USaint/Application/AppView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct AppView: View {
}
case .loggedIn:
if let store = store.scope(state: \.loggedIn, action: \.home) {
HomeView(store: store, viewModel: DefaultSaintHomeViewModel(), isLoggedIn: $isLoggedIn)
HomeView(store: store)
}
}
}
Expand Down
42 changes: 40 additions & 2 deletions Soomsil-USaint/Application/Feature/Home/Core/HomeReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,29 @@ struct HomeReducer {
struct State {
@Shared(.appStorage("isFirst")) var isFirst = true
@Shared(.appStorage("permission")) var permission = false

var studentInfo: StudentInfo = StudentInfo(name: "", major: "", schoolYear: "")
var totalReportCard: TotalReportCard = TotalReportCard(gpa: 0.0, earnedCredit: 0.0, graduateCredit: 0.0)
}

enum Action {
enum Action: BindableAction {
case binding(BindingAction<State>)
case onAppear
case initStudentReponse(Result<StudentInfo, Error>)
case initTotalReportCardResponse(Result<TotalReportCard, Error>)
case checkPushAuthorizationResponse(Result<Bool, Error>)
case sendTestPushResponse(Result<Void, Error>)
case settingPressed
case semesterListPressed
}

@Dependency(\.localNotificationClient) var localNotificationClient

@Dependency(\.studentClient) var studentClient
@Dependency(\.gradeClient) var gradeClient


var body: some Reducer<State, Action> {
BindingReducer()
Reduce { state, action in
switch action {
case .onAppear:
Expand All @@ -41,7 +53,25 @@ struct HomeReducer {
return await localNotificationClient.getPushAuthorizationStatus()
}
}))
await send(.initStudentReponse(Result {
return try await studentClient.getStudentInfo()
}))
await send(.initTotalReportCardResponse(Result {
return try await gradeClient.getTotalReportCard()
}))
}
case .initStudentReponse(.success(let studentInfo)):
state.studentInfo = studentInfo
return .none
case .initStudentReponse(.failure(let error)):
debugPrint(error)
return .none
case .initTotalReportCardResponse(.success(let totalReportCard)):
state.totalReportCard = totalReportCard
return .none
case .initTotalReportCardResponse(.failure(let error)):
debugPrint(error)
return .none
case .checkPushAuthorizationResponse(.success(let granted)):
state.$permission.withLock { $0 = granted }
return .run { send in
Expand All @@ -54,6 +84,14 @@ struct HomeReducer {
return .none
case .sendTestPushResponse:
return .none
case .settingPressed:
debugPrint("== SettingView로 이동 ==")
return .none
case .semesterListPressed:
debugPrint("== SemesterList로 이동 ==")
return .none
case .binding(_):
return .none
}
}
}
Expand Down
Loading