Skip to content

mui-z/GithubRepoSearcher-FlowRouter

Repository files navigation

GithubRepoSearcher-FlowRouter

License Platform

FlowRouter GitHub Repo Search App.

About

A FlowRouter exists for each Flow.

It is responsible for single flow control.

  flowchart LR;
    subgraph search_flow
      SearchPresenter--Push Transition Screen-->SearchFlowRouter;
      DetailPresenter-->SearchFlowRouter;
      subgraph detail
        DetailView-->DetailPresenter;
      end
      subgraph search
        SearchView-->SearchPresenter;
      end
    end
    subgraph readme_flow
      subgraph readme
        ReadmeView-->ReadmePresenter;
      end
      ReadmePresenter-->ReadmeFlowRouter;
    end

    SearchPresenter-->GithubUseCase;
    DetailPresenter-->GithubUseCase;
    ReadmePresenter-->GithubUseCase;
    GithubUseCase-->GithubRepoGateway;

    DetailView--Open Modal-->ReadmeView;
Loading

Usage

protocol FlowRouter: Hashable {
    associatedtype PushRoute: Hashable
    associatedtype NextScreen: View

    var id: UUID { get }

    var navigationPath: NavigationPath { get set }

    var nextTransitionRoute: PushRoute { get }

    func triggerScreenTransition(route: PushRoute)
    func nextTransitionScreen() -> NextScreen
}
final class SearchFlowRouter: ObservableObject, FlowRouter {
    let id = UUID()

    @Published
    var navigationPath: NavigationPath = .init()

    private(set) var nextTransitionRoute: PushRoute = .unknown

    func triggerScreenTransition(route: PushRoute) {
        navigationPath.append(route)
        nextTransitionRoute = route
    }

    func nextTransitionScreen() -> some View {
        nextTransitionRoute.nextView(router: self)
    }
}

extension SearchFlowRouter {
    enum PushRoute: Hashable {
        case unknown
        case detail(repo: GithubRepo)

        func nextView(router: SearchFlowRouter) -> some View {
            switch self {
            case .detail(let repo):
                return DetailScreen(repo: repo, router: router)
            case .unknown:
                fatalError("no set next transition screen.")
            }
        }
    }
}

Setup

  1. You generate GitHub token. The only permission required is public_repo.

  2. Paste to authorization header in GithubRepoGatewayImpl#searchGithubRepo()

  3. Build and Run App!

Reference

License

This is licensed under MIT License