Skip to content

Commit

Permalink
Fix 02-ForEachComposition
Browse files Browse the repository at this point in the history
  • Loading branch information
kalupas226 committed Feb 21, 2024
1 parent dd7555e commit c4b9a7d
Show file tree
Hide file tree
Showing 18 changed files with 233 additions and 226 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import ComposableArchitecture
import Entity

public struct RepositoryRow: Reducer {
@Reducer
public struct RepositoryRow {
@ObservableState
public struct State: Equatable {

}

public enum Action: Equatable {
public enum Action {

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import ComposableArchitecture
import Entity

public struct RepositoryRow: Reducer {
@Reducer
public struct RepositoryRow {
@ObservableState
public struct State: Equatable {
let repository: Repository
}

public enum Action: Equatable {
public enum Action {

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import ComposableArchitecture
import Entity

public struct RepositoryRow: Reducer {
@Reducer
public struct RepositoryRow {
@ObservableState
public struct State: Equatable, Identifiable {
public var id: Int { repository.id }
let repository: Repository
}

public enum Action: Equatable {
public enum Action {

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import ComposableArchitecture
import Entity

public struct RepositoryRow: Reducer {
@Reducer
public struct RepositoryRow {
@ObservableState
public struct State: Equatable, Identifiable {
public var id: Int { repository.id }
let repository: Repository
}

public enum Action: Equatable {
public enum Action {
case rowTapped
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import ComposableArchitecture
import Entity

public struct RepositoryRow: Reducer {
@Reducer
public struct RepositoryRow {
@ObservableState
public struct State: Equatable, Identifiable {
public var id: Int { repository.id }
let repository: Repository
}

public enum Action: Equatable {
public enum Action {
case rowTapped
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,5 @@ struct RepositoryRowView: View {
}

var body: some View {
WithViewStore(store, observe: { $0 }) { viewStore in
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,39 @@ struct RepositoryRowView: View {
}

var body: some View {
WithViewStore(store, observe: { $0 }) { viewStore in
Button {
} label: {
VStack(alignment: .leading, spacing: 8) {
Text(repository.fullName)
.font(.title2.bold())
Text(repository.description ?? "")
.font(.body)
.lineLimit(2)
HStack(alignment: .center, spacing: 32) {
Label(
title: {
Text("\(repository.stargazersCount)")
.font(.callout)
},
icon: {
Image(systemName: "star.fill")
.foregroundStyle(.yellow)
}
)
Label(
title: {
Text(repository.language ?? "")
.font(.callout)
},
icon: {
Image(systemName: "text.word.spacing")
.foregroundStyle(.gray)
}
)
}
Button {
} label: {
VStack(alignment: .leading, spacing: 8) {
Text(repository.fullName)
.font(.title2.bold())
Text(repository.description ?? "")
.font(.body)
.lineLimit(2)
HStack(alignment: .center, spacing: 32) {
Label(
title: {
Text("\(repository.stargazersCount)")
.font(.callout)
},
icon: {
Image(systemName: "star.fill")
.foregroundStyle(.yellow)
}
)
Label(
title: {
Text(repository.language ?? "")
.font(.callout)
},
icon: {
Image(systemName: "text.word.spacing")
.foregroundStyle(.gray)
}
)
}
.frame(maxWidth: .infinity, alignment: .leading)
}
.buttonStyle(.plain)
.frame(maxWidth: .infinity, alignment: .leading)
}
.buttonStyle(.plain)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,40 @@ struct RepositoryRowView: View {
}

var body: some View {
WithViewStore(store, observe: { $0 }) { viewStore in
Button {
viewStore.send(.rowTapped)
} label: {
VStack(alignment: .leading, spacing: 8) {
Text(viewStore.repository.fullName)
.font(.title2.bold())
Text(viewStore.repository.description ?? "")
.font(.body)
.lineLimit(2)
HStack(alignment: .center, spacing: 32) {
Label(
title: {
Text("\(viewStore.repository.stargazersCount)")
.font(.callout)
},
icon: {
Image(systemName: "star.fill")
.foregroundStyle(.yellow)
}
)
Label(
title: {
Text(viewStore.repository.language ?? "")
.font(.callout)
},
icon: {
Image(systemName: "text.word.spacing")
.foregroundStyle(.gray)
}
)
}
Button {
store.send(.rowTapped)
} label: {
VStack(alignment: .leading, spacing: 8) {
Text(store.repository.fullName)
.font(.title2.bold())
Text(store.repository.description ?? "")
.font(.body)
.lineLimit(2)
HStack(alignment: .center, spacing: 32) {
Label(
title: {
Text("\(store.repository.stargazersCount)")
.font(.callout)
},
icon: {
Image(systemName: "star.fill")
.foregroundStyle(.yellow)
}
)
Label(
title: {
Text(store.repository.language ?? "")
.font(.callout)
},
icon: {
Image(systemName: "text.word.spacing")
.foregroundStyle(.gray)
}
)
}
.frame(maxWidth: .infinity, alignment: .leading)
}
.buttonStyle(.plain)
.frame(maxWidth: .infinity, alignment: .leading)
}
.buttonStyle(.plain)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,41 @@ struct RepositoryRowView: View {
}

var body: some View {
WithViewStore(store, observe: { $0 }) { viewStore in
Button {
viewStore.send(.rowTapped)
} label: {
VStack(alignment: .leading, spacing: 8) {
Text(viewStore.repository.fullName)
.font(.title2.bold())
Text(viewStore.repository.description ?? "")
.font(.body)
.lineLimit(2)
HStack(alignment: .center, spacing: 32) {
Label(
title: {
Text("\(viewStore.repository.stargazersCount)")
.font(.callout)
},
icon: {
Image(systemName: "star.fill")
.foregroundStyle(.yellow)
}
)
Label(
title: {
Text(viewStore.repository.language ?? "")
.font(.callout)
},
icon: {
Image(systemName: "text.word.spacing")
.foregroundStyle(.gray)
}
)
}
Button {
store.send(.rowTapped)
} label: {
VStack(alignment: .leading, spacing: 8) {
Text(store.repository.fullName)
.font(.title2.bold())
Text(store.repository.description ?? "")
.font(.body)
.lineLimit(2)
HStack(alignment: .center, spacing: 32) {
Label(
title: {
Text("\(store.repository.stargazersCount)")
.font(.callout)
},
icon: {
Image(systemName: "star.fill")
.foregroundStyle(.yellow)
}
)
Label(
title: {
Text(store.repository.language ?? "")
.font(.callout)
},
icon: {
Image(systemName: "text.word.spacing")
.foregroundStyle(.gray)
}
)
}
.frame(maxWidth: .infinity, alignment: .leading)
}
.buttonStyle(.plain)
.frame(maxWidth: .infinity, alignment: .leading)
}
.buttonStyle(.plain)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@ import Entity
import Foundation
import SwiftUI

public struct RepositoryList: Reducer {
@Reducer
public struct RepositoryList {
@ObservableState
public struct State: Equatable {
var repositories: [Repository] = []
var isLoading: Bool = false

public init() {}
}

public enum Action: Equatable {
public enum Action {
case onAppear
case searchRepositoriesResponse(TaskResult<[Repository]>)
case searchRepositoriesResponse(Result<[Repository]>)
}

public init() {}
Expand All @@ -26,7 +28,7 @@ public struct RepositoryList: Reducer {
return .run { send in
await send(
.searchRepositoriesResponse(
TaskResult {
Result {
let query = "composable"
let url = URL(
string: "https://api.github.com/search/repositories?q=\(query)&sort=stars"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@ import Foundation
import IdentifiedCollections
import SwiftUI

public struct RepositoryList: Reducer {
@Reducer
public struct RepositoryList {
@ObservableState
public struct State: Equatable {
var repositoryRows: IdentifiedArrayOf<RepositoryRow.State> = []
var isLoading: Bool = false

public init() {}
}

public enum Action: Equatable {
public enum Action {
case onAppear
case searchRepositoriesResponse(TaskResult<[Repository]>)
case searchRepositoriesResponse(Result<[Repository]>)
}

public init() {}
Expand All @@ -27,7 +29,7 @@ public struct RepositoryList: Reducer {
return .run { send in
await send(
.searchRepositoriesResponse(
TaskResult {
Result {
let query = "composable"
let url = URL(
string: "https://api.github.com/search/repositories?q=\(query)&sort=stars"
Expand Down
Loading

0 comments on commit c4b9a7d

Please sign in to comment.