Skip to content

Commit df609d8

Browse files
committed
feat: 비회원 모드 역 조회 기능 개선 #16
- TrainStationView에서 비회원일 때 즐겨찾기 버튼 숨김 처리 - TrainStationFeature에서 비회원일 때 API 실패 시 기본 주요 역 데이터로 폴백 - StationRowModel에 makeDefaultMajorStations() 메소드 추가 - 비회원도 주요 역(강남, 홍대입구, 신촌 등) 선택 가능
1 parent 32d4ec3 commit df609d8

File tree

6 files changed

+78
-15
lines changed

6 files changed

+78
-15
lines changed

Projects/Presentation/Auth/Sources/Coordinator/Reducer/AuthCoordinator.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,10 @@ extension AuthCoordinator {
8686
action: IndexedRouterActionOf<AuthScreen>
8787
) -> Effect<Action> {
8888
switch action {
89-
case .routeAction(id: _, action: .login(.delegate(.presntGuestLookAround)))
90-
return .send(.inner(.pushOnBoarding))
89+
case .routeAction(id: _, action: .login(.delegate(.presentGuestLookAround))):
90+
return .routeWithDelaysIfUnsupported(state.routes, action: \.router) {
91+
$0.push(.onBoarding(.init()))
92+
}
9193

9294
case .routeAction(id: _, action: .login(.delegate(.presentOnBoarding))):
9395
return .send(.inner(.pushOnBoarding))

Projects/Presentation/Auth/Sources/Main/Reducer/LoginFeature.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public struct LoginFeature {
7373
case presentPrivacyWeb
7474
case presentOnBoarding
7575
case presentMain
76-
case presntGuestLookAround
76+
case presentGuestLookAround
7777

7878
}
7979

@@ -221,7 +221,7 @@ extension LoginFeature {
221221
case .presentMain:
222222
return .none
223223

224-
case .presntGuestLookAround:
224+
case .presentGuestLookAround:
225225
// 비회원으로 시작하기
226226
state.$userSession.withLock { userSession in
227227
userSession.isGuest = true
@@ -247,6 +247,10 @@ extension LoginFeature {
247247
state.$selectedMapTypeStorage.withLock {
248248
$0 = loginEntity.mapType ?? .appleMap
249249
}
250+
251+
state.$userSession.withLock { userSession in
252+
userSession.isGuest = false
253+
}
250254

251255
if loginEntity.isNewUser {
252256
return .send(.delegate(.presentTermsAgreement))

Projects/Presentation/Auth/Sources/Main/View/LoginView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ extension LoginView {
8787
.foregroundStyle(.gray800)
8888
.underline(true, color: .gray800.opacity(0.5))
8989
.onTapGesture {
90-
store.send(.delegate(.presntGuestLookAround))
90+
store.send(.delegate(.presentGuestLookAround))
9191
}
9292

9393

Projects/Presentation/Home/Sources/TrainStation/Model/StationRowModel.swift

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,43 @@ extension StationRowModel {
184184
return IdentifiedArray(uniqueElements: rows)
185185
}
186186

187+
// 비회원용 기본 주요 역 데이터
188+
static func makeDefaultMajorStations() -> IdentifiedArrayOf<StationRowModel> {
189+
let defaultStations = [
190+
("강남", 1, Station.gangnam, ["2호선", "신분당선"]),
191+
("홍대입구", 2, Station.hongdaeEntrance, ["2호선", "6호선", "공항철도"]),
192+
("신촌", 3, Station.sinchon, ["2호선"]),
193+
("이태원", 4, Station.itaewon, ["6호선"]),
194+
("명동", 5, Station.myeongdong, ["4호선"]),
195+
("건대입구", 6, Station.konkukUniversityEntrance, ["2호선", "7호선"]),
196+
("잠실", 7, Station.jamsil, ["2호선", "8호선"]),
197+
("종각", 8, Station.jonggak, ["1호선"]),
198+
("고속터미널", 9, Station.expressBusTerminal, ["3호선", "7호선", "9호선"]),
199+
("노원", 10, Station.nowon, ["4호선", "7호선"])
200+
]
201+
202+
let rows = defaultStations.map { (name, id, station, badges) in
203+
let entity = StationEntity(
204+
id: id,
205+
favoriteID: nil,
206+
station: station,
207+
name: name,
208+
badges: badges,
209+
latitude: nil,
210+
longitude: nil,
211+
isFavorite: false
212+
)
213+
214+
return StationRowModel(
215+
stationEntity: entity,
216+
distanceText: nil,
217+
rowType: "station"
218+
)
219+
}
220+
221+
return IdentifiedArray(uniqueElements: rows)
222+
}
223+
187224
static func applyFavoriteState(
188225
favoriteRows: IdentifiedArrayOf<StationRowModel>,
189226
nearbyRows: inout IdentifiedArrayOf<StationRowModel>,

Projects/Presentation/Home/Sources/TrainStation/Reducer/TrainStationFeature.swift

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public struct TrainStationFeature {
4040
var majorRows: IdentifiedArrayOf<StationRowModel> = []
4141
var isLoading: Bool = false
4242
var errorMessage: String?
43+
@Shared(.inMemory("UserSession")) var userSession: UserSession = .empty
4344

4445
public init(
4546
selectedStation: Station = .seoul,
@@ -126,6 +127,13 @@ extension TrainStationFeature {
126127
switch action {
127128
case .onAppear:
128129
state.isLoading = true
130+
131+
// 비회원인 경우 즐겨찾기 섹션은 표시하지 않음
132+
if state.userSession.isGuest {
133+
state.shouldShowFavoriteSection = false
134+
return .send(.async(.fetchStations))
135+
}
136+
129137
return .merge(
130138
.send(.async(.checkAccessToken)),
131139
.send(.async(.fetchStations))
@@ -137,7 +145,9 @@ extension TrainStationFeature {
137145
state.selectedStationID = row.stationID
138146
return .send(.delegate(.stationSelected(row)))
139147
case .favoriteButtonTapped(let row):
140-
guard state.shouldShowFavoriteSection else { return .none }
148+
// 비회원이거나 즐겨찾기 섹션이 비활성화된 경우 즐겨찾기 기능 사용 불가
149+
guard state.shouldShowFavoriteSection && !state.userSession.isGuest else { return .none }
150+
141151
if row.isFavorite {
142152
guard let favoriteID = row.favoriteID else { return .none }
143153
return .send(.async(.deleteFavoriteStation(favoriteID: favoriteID, stationID: row.stationID)))
@@ -251,8 +261,15 @@ extension TrainStationFeature {
251261
state.isLoading = false
252262
return .none
253263
case .fetchStationsFailed(let message):
254-
state.errorMessage = message
255264
state.isLoading = false
265+
266+
// 비회원인 경우 기본 주요 역 데이터로 폴백
267+
if state.userSession.isGuest {
268+
state.majorRows = StationRowModel.makeDefaultMajorStations()
269+
state.errorMessage = nil
270+
} else {
271+
state.errorMessage = message
272+
}
256273
return .none
257274
case .addFavoriteStationResponse:
258275
return .send(.async(.fetchStations))

Projects/Presentation/Home/Sources/TrainStation/View/TrainStationView.swift

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -249,15 +249,18 @@ extension TrainStationView {
249249
}
250250
.buttonStyle(.plain)
251251

252-
Button {
253-
store.send(.view(.favoriteButtonTapped(row)))
254-
} label: {
255-
Image(systemName: row.isFavorite ? "star.fill" : "star")
256-
.font(.system(size: 18, weight: .semibold))
257-
.foregroundStyle(row.isFavorite ? .orange800 : .gray550)
258-
.frame(width: 20, height: 20)
252+
// 비회원이 아닌 경우에만 즐겨찾기 버튼 표시
253+
if store.shouldShowFavoriteSection {
254+
Button {
255+
store.send(.view(.favoriteButtonTapped(row)))
256+
} label: {
257+
Image(systemName: row.isFavorite ? "star.fill" : "star")
258+
.font(.system(size: 18, weight: .semibold))
259+
.foregroundStyle(row.isFavorite ? .orange800 : .gray550)
260+
.frame(width: 20, height: 20)
261+
}
262+
.buttonStyle(.plain)
259263
}
260-
.buttonStyle(.plain)
261264
}
262265
.padding(.leading, 20)
263266
.padding(.trailing, 24)

0 commit comments

Comments
 (0)