Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ struct CategoryManageFeature {
}
case .tapDeleteUserCategory(let item):
if item.isUserCategory {
state.alert = deleteAlertState(for: item)
state.alert = Self.deleteAlertState(for: item)
}
case .tapDoneButton:
break
Expand Down Expand Up @@ -204,7 +204,7 @@ private struct CategoryManageSheetFeature: Reducer {
}

private extension CategoryManageFeature {
func deleteAlertState(for item: TodoCategoryItem) -> AlertState<Action.Alert> {
static func deleteAlertState(for item: TodoCategoryItem) -> AlertState<Action.Alert> {
AlertState {
TextState(String(localized: "todo_manage_delete_category_title"))
} actions: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ struct TodoDetailFeature {
case .onAppear:
return fetchTodoEffect(todoId: state.todoId)
case .fetchFailed:
state.alert = alertState()
state.alert = Self.alertState()
case .setSheet(let sheet):
state.sheet = sheet
case .setFullScreenCover(let cover):
Expand Down Expand Up @@ -209,7 +209,7 @@ private extension TodoDetailFeature {
}
}

func alertState() -> AlertState<Never> {
static func alertState() -> AlertState<Never> {
AlertState {
TextState(String(localized: "common_error_title"))
} actions: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ struct HomeView: View {
get: { coordinator.viewModel.state.showSearchView },
set: { coordinator.viewModel.send(.setPresentation(.searchView, $0)) }
)) {
SearchView(viewModel: coordinator.makeSearchViewModel())
SearchView(store: coordinator.makeSearchStore())
}
.alert(
coordinator.viewModel.state.alertTitle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import Combine
import ComposableArchitecture
import Foundation
import DevLogCore
import DevLogDomain
Expand Down Expand Up @@ -90,12 +91,17 @@ final class HomeViewCoordinator {
)
}

func makeSearchViewModel() -> SearchViewModel {
SearchViewModel(
fetchWebPagesUseCase: container.resolve(FetchWebPagesUseCase.self),
fetchTodosUseCase: container.resolve(FetchTodosUseCase.self),
fetchRecentSearchQueriesUseCase: container.resolve(FetchRecentSearchQueriesUseCase.self),
updateRecentSearchQueriesUseCase: container.resolve(UpdateRecentSearchQueriesUseCase.self)
)
func makeSearchStore() -> StoreOf<SearchFeature> {
Store(
initialState: SearchFeature.State(
recentQueries: container.resolve(FetchRecentSearchQueriesUseCase.self).execute()
)
) {
SearchFeature()
} withDependencies: {
$0.searchFetchWebPagesUseCase = self.container.resolve(FetchWebPagesUseCase.self)
$0.searchFetchTodosUseCase = self.container.resolve(FetchTodosUseCase.self)
$0.searchUpdateRecentQueriesUseCase = self.container.resolve(UpdateRecentSearchQueriesUseCase.self)
}
}
}
49 changes: 29 additions & 20 deletions Application/DevLogPresentation/Sources/Login/LoginFeature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@ struct LoginFeature {
@ObservableState
struct State: Equatable {
@Presents var alert: AlertState<Never>?
var isLoading = false
var loading = LoadingFeature.State()

var isLoading: Bool {
loading.isLoading
}
}

enum Action {
case alert(PresentationAction<Never>)
case tapSignInButton(AuthProvider)
case signInFailed(AlertType)
case signInCancelled
case loading(LoadingFeature.Action)
}

enum AlertType: Equatable {
Expand All @@ -32,28 +36,19 @@ struct LoginFeature {
@Dependency(\.signInUseCase) var signInUseCase

var body: some ReducerOf<Self> {
Scope(state: \.loading, action: \.loading) {
LoadingFeature()
}
Reduce { state, action in
switch action {
case .alert:
break
case .tapSignInButton(let provider):
state.isLoading = true
return .run { [signInUseCase] send in
do {
try await signInUseCase.execute(provider)
} catch {
if error.isSocialLoginCancelled {
await send(.signInCancelled)
return
}
await send(.signInFailed(alertType(for: error)))
}
}
case .signInCancelled:
state.isLoading = false
return signInEffect(provider)
case .signInFailed(let alertType):
state.isLoading = false
state.alert = alertState(for: alertType)
state.alert = Self.alertState(for: alertType)
case .loading:
break
}
return .none
}
Expand All @@ -79,7 +74,21 @@ private enum SignInUseCaseKey: DependencyKey {
}

private extension LoginFeature {
func alertState(for alertType: AlertType) -> AlertState<Never> {
func signInEffect(_ provider: AuthProvider) -> Effect<Action> {
.run { [signInUseCase] send in
await send(.loading(.begin(target: .default, mode: .immediate)))
do {
try await signInUseCase.execute(provider)
// 유스케이스 완료가 화면 전환 완료를 의미하지 않으므로 LoginView가 교체될 때까지 로딩을 유지한다.
} catch {
await send(.loading(.end(target: .default, mode: .immediate)))
if error.isSocialLoginCancelled { return }
await send(.signInFailed(Self.alertType(for: error)))
}
}
}
Comment thread
opficdev marked this conversation as resolved.

static func alertState(for alertType: AlertType) -> AlertState<Never> {
let title: String
let message: String

Expand All @@ -103,7 +112,7 @@ private extension LoginFeature {
}
}

func alertType(for error: Error) -> AlertType {
static func alertType(for error: Error) -> AlertType {
if case AuthError.emailNotFound = error {
return .emailUnavailable
}
Expand Down
Loading