Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial state slice for UI display
- Loading branch information
1 parent
df3c9b7
commit daeff01
Showing
2 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { createSlice, PayloadAction } from '@reduxjs/toolkit' | ||
|
||
interface CurrentDisplay { | ||
displayType: 'issues' | 'comments' | ||
issueId: number | null | ||
} | ||
|
||
interface CurrentDisplayPayload { | ||
displayType: 'issues' | 'comments' | ||
issueId?: number | ||
} | ||
|
||
interface CurrentRepo { | ||
org: string | ||
repo: string | ||
} | ||
|
||
type CurrentDisplayState = { | ||
page: number | ||
} & CurrentDisplay & | ||
CurrentRepo | ||
|
||
let initialState: CurrentDisplayState = { | ||
org: 'rails', | ||
repo: 'rails', | ||
page: 1, | ||
displayType: 'issues', | ||
issueId: null | ||
} | ||
|
||
const issuesDisplaySlice = createSlice({ | ||
name: 'issuesDisplay', | ||
initialState, | ||
reducers: { | ||
displayRepo(state, action: PayloadAction<CurrentRepo>) { | ||
const { org, repo } = action.payload | ||
state.org = org | ||
state.repo = repo | ||
}, | ||
setCurrentPage(state, action: PayloadAction<number>) { | ||
state.page = action.payload | ||
}, | ||
setCurrentDisplayType(state, action: PayloadAction<CurrentDisplayPayload>) { | ||
const { displayType, issueId = null } = action.payload | ||
state.displayType = displayType | ||
state.issueId = issueId | ||
} | ||
} | ||
}) | ||
|
||
export const { | ||
displayRepo, | ||
setCurrentDisplayType, | ||
setCurrentPage | ||
} = issuesDisplaySlice.actions | ||
|
||
export default issuesDisplaySlice.reducer |