Deprecated: Automatic conversion of false to array is deprecated in /home/u164338858/domains/areyoupop.com/public_html/wp-content/plugins/gs-facebook-comments/public/class-wpfc-public.php on line 258
Published On: February 11th, 2023Categories: AI News

We can finish our repos search app that calls Github API asynchronously and fetches repositories matching a query.

typealias AppStore = Store<AppState, AppAction, AppEnvironment>

struct SearchContainerView: View {
    @EnvironmentObject var store: AppStore
    @State private var query: String = "Swift"

    var body: some View {
        SearchView(
            query: $query,
            repos: store.state.searchResult,
            onCommit: fetch
        ).onAppear(perform: fetch)
    }

    private func fetch() {
        store.send(.search(query: query))
    }
}

struct SearchView : View {
    @Binding var query: String
    let repos: [Repo]
    let onCommit: () -> Void

    var body: some View {
        NavigationView {
            List {
                TextField("Type something", text: $query, onCommit: onCommit)

                if repos.isEmpty {
                    Text("Loading...")
                } else {
                    ForEach(repos) { repo in
      ...

Source link

Leave A Comment