Files
e-party-iOS/yana/Features/LoginFeature.swift
2025-07-07 14:19:07 +08:00

84 lines
2.6 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import Foundation
import ComposableArchitecture
struct LoginResponse: Codable, Equatable {
let status: String
let message: String?
let token: String?
}
@Reducer
struct LoginFeature {
@ObservableState
struct State: Equatable {
var account: String = ""
var password: String = ""
var isLoading = false
var error: String?
#if DEBUG
init() {
self.account = "3184"
self.password = "a0d5da073d14731cc7a01ecaa17b9174"
}
#endif
}
enum Action: Equatable {
case updateAccount(String)
case updatePassword(String)
case login
case loginResponse(TaskResult<LoginResponse>)
}
var body: some ReducerOf<Self> {
// Reduce { state, action in
// switch action {
// case let .updateAccount(account):
// state.account = account
// return .none
//
// case let .updatePassword(password):
// state.password = password
// return .none
//
// case .login:
// state.isLoading = true
// state.error = nil
//
// let loginBody = [
// "account": state.account,
// "password": state.password
// ]
//
// return .run { send in
// do {
// let response: LoginResponse = try await APIClientManager.shared.post(
// path: APIConstants.Endpoints.login,
// body: loginBody,
// headers: APIConstants.defaultHeaders
// )
// await send(.loginResponse(.success(response)))
// } catch {
// await send(.loginResponse(.failure(error)))
// }
// }
//
// case let .loginResponse(.success(response)):
// state.isLoading = false
// if response.status == "success" {
// // TODO: token
// } else {
// state.error = response.message ?? ""
// }
// return .none
//
// case let .loginResponse(.failure(error)):
// state.isLoading = false
// state.error = error.localizedDescription
// return .none
// }
// }
}
}