Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conform ViewAction Protocol of TCA #1005

Merged
merged 3 commits into from
Sep 11, 2024
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 @@ -18,7 +18,7 @@ public struct ContributorReducer: Sendable {
}
}

public enum Action: Sendable, BindableAction {
public enum Action: Sendable, BindableAction, ViewAction {
case binding(BindingAction<State>)
case onAppear
case response(Result<[Contributor], any Error>)
Expand Down
7 changes: 4 additions & 3 deletions app-ios/Sources/ContributorFeature/ContributorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Theme
import shared
import CommonComponents

@ViewAction(for: ContributorReducer.self)
public struct ContributorView: View {
private enum ViewType: String, CaseIterable {
case swift
Expand All @@ -27,7 +28,7 @@ public struct ContributorView: View {

@State private var selectedTab: ViewType = .swift
@Namespace var namespace
@Bindable var store: StoreOf<ContributorReducer>
@Bindable public var store: StoreOf<ContributorReducer>

public init(store: StoreOf<ContributorReducer>) {
self.store = store
Expand All @@ -43,15 +44,15 @@ public struct ContributorView: View {

case .kmpPresenter:
KmpPresenterContributorView {
store.send(.view(.contributorButtonTapped($0)))
send(.contributorButtonTapped($0))
}
.tag(ViewType.kmpPresenter)
case .fullKmp:
KmpContributorComposeViewControllerWrapper { urlString in
guard let url = URL(string: urlString) else {
return
}
store.send(.view(.contributorButtonTapped(url)))
send(.contributorButtonTapped(url))
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion app-ios/Sources/SponsorFeature/SponsorReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public struct SponsorReducer : Sendable {
public init() { }
}

public enum Action : Sendable, BindableAction {
public enum Action: Sendable, BindableAction, ViewAction {
case binding(BindingAction<State>)
case response(Result<[Sponsor], any Error>)
case view(View)
Expand Down
7 changes: 4 additions & 3 deletions app-ios/Sources/SponsorFeature/SponsorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import Theme
import Model
import CommonComponents

@ViewAction(for: SponsorReducer.self)
public struct SponsorView: View {
@Bindable private var store: StoreOf<SponsorReducer>
@Bindable public var store: StoreOf<SponsorReducer>

public init(store: StoreOf<SponsorReducer>) {
self.store = store
Expand Down Expand Up @@ -39,7 +40,7 @@ public struct SponsorView: View {
}
.background(AssetColors.Surface.surface.swiftUIColor)
.onAppear {
store.send(.view(.onAppear))
send(.onAppear)
}
.navigationBarTitleDisplayMode(.large)
.navigationTitle(String(localized: "Sponsor", bundle: .module))
Expand All @@ -60,7 +61,7 @@ public struct SponsorView: View {
ZStack {
Color.white.clipShape(RoundedRectangle(cornerRadius: 12))
Button {
store.send(.view(.sponsorTapped(item.link)))
send(.sponsorTapped(item.link))
} label: {
AsyncImage(url: item.logo) {
$0.image?
Expand Down
10 changes: 7 additions & 3 deletions app-ios/Sources/StaffFeature/StaffReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,21 @@ public struct StaffReducer : Sendable {
public init() { }
}

public enum Action : Sendable {
case onAppear
public enum Action: Sendable, ViewAction {
case view(View)
case response(Result<[Model.Staff], any Error>)

public enum View: Sendable {
case onAppear
}
}

public var body: some ReducerOf<Self> {
Reduce { state, action in
enum CancelID { case connection }

switch action {
case .onAppear:
case .view(.onAppear):
return .run { send in
do {
for try await staffs in try staffsData.streamStaffs() {
Expand Down
5 changes: 3 additions & 2 deletions app-ios/Sources/StaffFeature/StaffView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import Theme
import CommonComponents
import Model

@ViewAction(for: StaffReducer.self)
public struct StaffView: View {
private let store: StoreOf<StaffReducer>
public let store: StoreOf<StaffReducer>
@State private var selectedStaffData: Staff?

public init(store: StoreOf<StaffReducer>) {
Expand All @@ -28,7 +29,7 @@ public struct StaffView: View {
}
.background(AssetColors.Surface.surface.swiftUIColor)
.onAppear {
store.send(.onAppear)
send(.onAppear)
}
.navigationBarTitleDisplayMode(.large)
.navigationTitle(String(localized: "Staff", bundle: .module))
Expand Down
2 changes: 1 addition & 1 deletion app-ios/Tests/StaffFeatureTests/StaffFeatureTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ final class StaffFeatureTests: XCTestCase {
}
}
}
await store.send(.onAppear)
await store.send(.view(.onAppear))
await store.receive(\.response.success) {
$0.list = [.init(id: 0, name: "testValue", icon: .init(string: "https://avatars.githubusercontent.com/u/10727543?s=200&v=4")!, github: .init(string: "https://2024.droidkaigi.jp/")!)]
}
Expand Down
Loading