Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ui/reducers: convert reducers to typescript #4280

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions web/src/app/reducers/auth.js → web/src/app/reducers/auth.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { AUTH_LOGOUT } from '../actions/auth'
import { Action, State } from './main'

const initialState = () => ({
const initialState = (): State => ({
valid: true,
})

export default function authReducer(state = initialState(), action) {
export default function authReducer(
state = initialState(),
action: Action,
): State {
switch (action.type) {
case AUTH_LOGOUT:
return { ...state, valid: false }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { combineReducers } from 'redux'
import { combineReducers, Reducer } from 'redux'
import auth from './auth'
import main from './main'

export default function createRootReducer() {
export default function createRootReducer(): Reducer {
return combineReducers({
auth, // auth status
main, // reducer for new user setup flag
Expand Down
17 changes: 15 additions & 2 deletions web/src/app/reducers/main.js → web/src/app/reducers/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import { SET_SHOW_NEW_USER_FORM } from '../actions'
import { getParameterByName } from '../util/query_param'

const initialState = {
export interface State {
valid?: boolean
isFirstLogin?: boolean
}

export interface Action {
type: string
payload?: boolean
}

const initialState: State = {
isFirstLogin: getParameterByName('isFirstLogin') === '1',
}

Expand All @@ -10,7 +20,10 @@ const initialState = {
*
* Returns the immutable final state afterwards (reduce)
*/
export default function mainReducer(state = initialState, action = {}) {
export default function mainReducer(
state = initialState,
action = {} as Action,
): State {
switch (action.type) {
case SET_SHOW_NEW_USER_FORM:
return {
Expand Down
Loading