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

Fix sponsor view bugs #977

Merged
merged 3 commits into from
Sep 6, 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
4 changes: 3 additions & 1 deletion app-ios/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@ let package = Package(
dependencies: [
.tca,
.kmpClient,
.theme
.theme,
.model,
.commonComponents,
]
),
.testTarget(
Expand Down
23 changes: 20 additions & 3 deletions app-ios/Sources/SponsorFeature/SponsorReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,29 @@ public struct SponsorReducer : Sendable {
var platinums = [Sponsor]()
var golds = [Sponsor]()
var supporters = [Sponsor]()
var url: IdentifiableURL?

public init() { }
}

public enum Action : Sendable {
case onAppear
public enum Action : Sendable, BindableAction {
case binding(BindingAction<State>)
case response(Result<[Sponsor], any Error>)
case view(View)

public enum View: Sendable {
case onAppear
case sponsorTapped(URL)
}
}

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

switch action {
case .onAppear:
case .view(.onAppear):
return .run { send in
do {
for try await sponsors in try sponsorsData.streamSponsors() {
Expand All @@ -39,6 +47,11 @@ public struct SponsorReducer : Sendable {
}
}
.cancellable(id: CancelID.connection)

case let .view(.sponsorTapped(url)):
state.url = IdentifiableURL(url)
return .none

case .response(.success(let sponsors)):
var platinums = [Sponsor]()
var golds = [Sponsor]()
Expand All @@ -59,9 +72,13 @@ public struct SponsorReducer : Sendable {
state.golds = golds
state.supporters = supporters
return .none

case .response(.failure(let error)):
print(error)
return .none

case .binding:
return .none
}
}
}
Expand Down
21 changes: 13 additions & 8 deletions app-ios/Sources/SponsorFeature/SponsorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import ComposableArchitecture
import SwiftUI
import Theme
import Model
import CommonComponents

public struct SponsorView: View {
private let store: StoreOf<SponsorReducer>
@State private var selectedSponsorData: Sponsor?
@Bindable private var store: StoreOf<SponsorReducer>

public init(store: StoreOf<SponsorReducer>) {
self.store = store
Expand Down Expand Up @@ -39,10 +39,14 @@ public struct SponsorView: View {
}
.background(AssetColors.Surface.surface.swiftUIColor)
.onAppear {
store.send(.onAppear)
store.send(.view(.onAppear))
}
.navigationBarTitleDisplayMode(.large)
.navigationTitle(String(localized: "Sponsor", bundle: .module))
.sheet(item: $store.url, content: { url in
SafariView(url: url.id)
.ignoresSafeArea()
})
}

@ViewBuilder
Expand All @@ -53,15 +57,16 @@ public struct SponsorView: View {
}
LazyVGrid(columns: gridItems, spacing: 12) {
ForEach(items) { item in
Button {
selectedSponsorData = item
} label: {
ZStack {
Color.white.clipShape(RoundedRectangle(cornerRadius: 12))
ZStack {
Color.white.clipShape(RoundedRectangle(cornerRadius: 12))
Button {
store.send(.view(.sponsorTapped(item.link)))
} label: {
AsyncImage(url: item.logo) {
$0.image?
.resizable()
.scaledToFit()
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
.frame(height: imageHeight)
.padding(.vertical, 6)
Expand Down
13 changes: 12 additions & 1 deletion app-ios/Tests/SponsorFeatureTests/SponsorFeatureTests.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import XCTest
import ComposableArchitecture
import Model
@testable import SponsorFeature

final class SponsorFeatureTests: XCTestCase {
Expand All @@ -20,7 +21,7 @@ final class SponsorFeatureTests: XCTestCase {
}
}
}
await store.send(.onAppear)
await store.send(.view(.onAppear))
await store.receive(\.response.success) {
$0.platinums = [
.init(id: "Hoge", logo: .init(string: "https://avatars.githubusercontent.com/u/10727543?s=200&v=4")!, link: .init(string: "https://2024.droidkaigi.jp/")!, plan: .platinum)
Expand All @@ -34,4 +35,14 @@ final class SponsorFeatureTests: XCTestCase {
}
}

@MainActor
func testSponsorTapped() async throws {
let url = URL(string: "https://github.com/DroidKaigi/conference-app-2024")!
let store = TestStore(initialState: SponsorReducer.State()) {
SponsorReducer()
}
await store.send(.view(.sponsorTapped(url))) {
$0.url = IdentifiableURL(url)
}
}
}
Loading