-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ [feat] 대시보드에 랜덤하게 방문할 수 있는 NPC와 고정적으로 방문하는 NPC를 보여주도록 추가
- Loading branch information
Showing
8 changed files
with
330 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
...sing-Wiki/Projects/App/Sources/Presentation/Dashboard/ViewModels/NpcsSectionReactor.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// | ||
// NpcsSectionReactor.swift | ||
// ACNH-wiki | ||
// | ||
// Created by Ari on 12/6/24. | ||
// | ||
|
||
import Foundation | ||
import ReactorKit | ||
import RxSwift | ||
import RxCocoa | ||
|
||
final class NpcsSectionReactor: Reactor, ObservableObject { | ||
enum Action { | ||
case fetch | ||
case npcLongPress(index: Int) | ||
} | ||
|
||
enum Mutation { | ||
case transition(route: DashboardCoordinator.Route) | ||
case setNpc(_ npcs: [NPC]) | ||
} | ||
|
||
struct State { | ||
var npcs: [NPC] = [] | ||
} | ||
|
||
@Published var initialState: State | ||
private var coordinator: DashboardCoordinator? | ||
private let mode: Mode | ||
|
||
init(state: State, mode: Mode, coordinator: DashboardCoordinator?) { | ||
self.initialState = state | ||
self.mode = mode | ||
self.coordinator = coordinator | ||
} | ||
|
||
func mutate(action: Action) -> Observable<Mutation> { | ||
switch action { | ||
case .fetch: | ||
return mode.npcs | ||
.map { Mutation.setNpc($0) } | ||
.asObservable() | ||
|
||
case .npcLongPress(let index): | ||
guard let npc = currentState.npcs[safe: index] else { | ||
return Observable.empty() | ||
} | ||
return Observable.just(Mutation.transition(route: .npcDetail(npc: npc))) | ||
} | ||
} | ||
|
||
func reduce(state: State, mutation: Mutation) -> State { | ||
var newState = state | ||
switch mutation { | ||
case let .transition(route): | ||
coordinator?.transition(for: route) | ||
|
||
case let .setNpc(npcs): | ||
newState.npcs = npcs | ||
objectWillChange.send() | ||
} | ||
return newState | ||
} | ||
} | ||
|
||
extension NpcsSectionReactor { | ||
enum Mode { | ||
case fixedVisit | ||
case randomVisit | ||
|
||
var npcs: Driver<[NPC]> { | ||
switch self { | ||
case .fixedVisit: | ||
return Items.shared.fixedVisitNpcs | ||
case .randomVisit: | ||
return Items.shared.randomVisitNpcs | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.