Skip to content

Commit

Permalink
feat: 🎸 prefecture
Browse files Browse the repository at this point in the history
  • Loading branch information
tomokisun committed Dec 3, 2023
1 parent a23b432 commit 5733603
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@
}
}
},
"Pick your prefecture" : {
"localizations" : {
"ja" : {
"stringUnit" : {
"state" : "translated",
"value" : "都道府県を選択"
}
}
}
},
"Pick your school" : {
"localizations" : {
"ja" : {
Expand Down
100 changes: 100 additions & 0 deletions Packages/GodPackage/Sources/SchoolSettingFeature/Prefecture.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import AnalyticsClient
import ComposableArchitecture
import RoundedCorner
import Styleguide
import SwiftUI

@Reducer
public struct PrefectureLogic {
public init() {}

public struct State: Equatable {
var prefectures: [String] = []
public init() {}
}

public enum Action: Equatable {
case onTask
case onAppear
case prefectureButtonTapped(String)
case delegate(Delegate)

public enum Delegate: Equatable {
case nextScreen(prefecture: String)
}
}

@Dependency(\.analytics) var analytics

public var body: some Reducer<State, Action> {
Reduce<State, Action> { state, action in
switch action {
case .onTask:
return .none

case .onAppear:
analytics.logScreen(screenName: "Prefecture", of: self)
return .none

case let .prefectureButtonTapped(prefecture):
return .send(.delegate(.nextScreen(prefecture: prefecture)))

default:
return .none
}
}
}
}

public struct PrefectureView: View {
let store: StoreOf<PrefectureLogic>

public init(store: StoreOf<PrefectureLogic>) {
self.store = store
}

public var body: some View {
WithViewStore(store, observe: { $0 }) { viewStore in
ZStack(alignment: .center) {
Color.godService

List {
ForEach(viewStore.prefectures, id: \.self) { prefecture in
Button {
store.send(.prefectureButtonTapped(prefecture))
} label: {
Text(prefecture)
.font(.system(.body, design: .rounded, weight: .bold))
.frame(maxWidth: .infinity, alignment: .leading)
}
}
}
.listStyle(.plain)
.foregroundStyle(.primary)
.background(Color.white)
.multilineTextAlignment(.center)
.cornerRadius(12, corners: [.topLeft, .topRight])
.edgesIgnoringSafeArea(.bottom)
}
.task { await store.send(.onTask).finish() }
.onAppear { store.send(.onAppear) }
.navigationTitle(Text("Pick your prefecture", bundle: .module))
.navigationBarTitleDisplayMode(.inline)
.toolbarBackground(Color.godService, for: .navigationBar)
.toolbarBackground(.visible, for: .navigationBar)
.toolbarColorScheme(.dark, for: .navigationBar)
}
}
}

#Preview {
NavigationStack {
PrefectureView(
store: .init(
initialState: PrefectureLogic.State(),
reducer: { PrefectureLogic() }
)
)
}
.environment(\.locale, Locale(identifier: "ja-JP"))
}

0 comments on commit 5733603

Please sign in to comment.