Skip to content

Commit

Permalink
Convert main issues display control to Redux
Browse files Browse the repository at this point in the history
  • Loading branch information
markerikson committed Aug 26, 2019
1 parent ec80934 commit 07bea70
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions src/app/App.tsx
@@ -1,12 +1,19 @@
import React, { useState } from 'react'
import './App.css'
import React from 'react'
import { useSelector, useDispatch } from 'react-redux'

import { RootState } from './rootReducer'

import { RepoSearchForm } from 'features/repoSearch/RepoSearchForm'
import { IssuesListPage } from 'features/issuesList/IssuesListPage'
import { IssueDetailsPage } from 'features/issueDetails/IssueDetailsPage'

const ORG = 'rails'
const REPO = 'rails'
import {
displayRepo,
setCurrentDisplayType,
setCurrentPage
} from 'features/issuesDisplay/issuesDisplaySlice'

import './App.css'

type CurrentDisplay =
| {
Expand All @@ -18,33 +25,31 @@ type CurrentDisplay =
}

const App: React.FC = () => {
const [org, setOrg] = useState(ORG)
const [repo, setRepo] = useState(REPO)
const [page, setPage] = useState(1)
const [currentDisplay, setCurrentDisplay] = useState<CurrentDisplay>({
type: 'issues'
})
const dispatch = useDispatch()

const { org, repo, displayType, page, issueId } = useSelector(
(state: RootState) => state.issuesDisplay
)

const setOrgAndRepo = (org: string, repo: string) => {
setOrg(org)
setRepo(repo)
dispatch(displayRepo({ org, repo }))
}

const setJumpToPage = (page: number) => {
setPage(page)
dispatch(setCurrentPage(page))
}

const showIssuesList = () => {
setCurrentDisplay({ type: 'issues' })
dispatch(setCurrentDisplayType({ displayType: 'issues' }))
}

const showIssueComments = (issueId: number) => {
setCurrentDisplay({ type: 'comments', issueId })
dispatch(setCurrentDisplayType({ displayType: 'comments', issueId }))
}

let content

if (currentDisplay.type === 'issues') {
if (displayType === 'issues') {
content = (
<React.Fragment>
<RepoSearchForm
Expand All @@ -62,8 +67,7 @@ const App: React.FC = () => {
/>
</React.Fragment>
)
} else {
const { issueId } = currentDisplay
} else if (issueId !== null) {
const key = `${org}/${repo}/${issueId}`
content = (
<IssueDetailsPage
Expand Down

0 comments on commit 07bea70

Please sign in to comment.