Skip to content

Commit

Permalink
Fix 01-CreateViewWithTCA tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
kalupas226 committed Feb 18, 2024
1 parent f208ae4 commit deebca9
Show file tree
Hide file tree
Showing 12 changed files with 141 additions and 165 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import ComposableArchitecture
import Entity
import Foundation

public struct RepositoryList: Reducer {
@Reducer
public struct RepositoryList {
public init() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import ComposableArchitecture
import Entity
import Foundation

public struct RepositoryList: Reducer {
@Reducer
public struct RepositoryList {
@ObservableState
public struct State: Equatable {
var repositories: [Repository] = []
var isLoading: Bool = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ import ComposableArchitecture
import Entity
import Foundation

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
}

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

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], Error>)
}

public init() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ import ComposableArchitecture
import Entity
import Foundation

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], Error>)
}

public init() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ import ComposableArchitecture
import Entity
import Foundation

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], Error>)
}

public init() {}
Expand All @@ -25,7 +27,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 @@ -2,15 +2,17 @@ import ComposableArchitecture
import Entity
import Foundation

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]>)
}
Expand All @@ -25,7 +27,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 @@ -5,14 +5,20 @@ import SwiftUI

public struct RepositoryListView: View {
let store: StoreOf<RepositoryList>

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

public var body: some View {
WithViewStore(store, observe: { $0 }) { viewStore in

Group {
if store.isLoading {
ProgressView()
} else {
}
}
.onAppear {
store.send(.onAppear)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,58 @@ import SwiftUI

public struct RepositoryListView: View {
let store: StoreOf<RepositoryList>

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

public var body: some View {
WithViewStore(store, observe: { $0 }) { viewStore in
Group {
if viewStore.isLoading {
ProgressView()
} else {
Group {
if store.isLoading {
ProgressView()
} else {
List {
ForEach(store.repositories, id: \.id) { repository 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)
}
)
}
}
.frame(maxWidth: .infinity, alignment: .leading)
}
.buttonStyle(.plain)
}
}
}
.onAppear {
viewStore.send(.onAppear)
}
}
.onAppear {
store.send(.onAppear)
}
}
}

This file was deleted.

Loading

0 comments on commit deebca9

Please sign in to comment.