-
-
Notifications
You must be signed in to change notification settings - Fork 275
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(frontend/redux): begin migration to TypeScript
- Loading branch information
Showing
13 changed files
with
265 additions
and
135 deletions.
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
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
This file was deleted.
Oops, something went wrong.
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,35 @@ | ||
import { applyMiddleware, createStore, compose } from 'redux'; | ||
import thunk from 'redux-thunk'; | ||
|
||
import { persistReducer, persistStore } from 'redux-persist'; | ||
import storage from 'redux-persist/lib/storage'; | ||
|
||
import { setItem } from '../utils/safe_storage'; | ||
import reducers from './reducers'; | ||
import { composeWithDevTools } from '@redux-devtools/extension'; | ||
|
||
const persistConfig = { | ||
key: 'root', | ||
storage, | ||
blacklist: ['editor', 'orgBarVisibility'], | ||
}; | ||
|
||
const persistedReducer = persistReducer<{ | ||
preferences: { | ||
mapShown: boolean; | ||
action: string; | ||
projectListView: boolean; | ||
} | ||
}>(persistConfig, reducers); | ||
|
||
const store = createStore(persistedReducer, undefined, composeWithDevTools((applyMiddleware(thunk)))); | ||
|
||
const persistor = persistStore(store); | ||
|
||
store.subscribe(() => { | ||
setItem('mapShown', store.getState().preferences.mapShown); | ||
setItem('action', store.getState().preferences.action); | ||
setItem('projectListView', store.getState().preferences.projectListView); | ||
}); | ||
|
||
export { store, persistor }; |
This file was deleted.
Oops, something went wrong.
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,79 @@ | ||
import { types } from '../actions/auth'; | ||
|
||
type UserData = { | ||
userDetails: { | ||
id: number; | ||
username: string; | ||
emailAddress: string; | ||
role: string; | ||
} | null, | ||
token: string, | ||
session: { | ||
osm_oauth_token: string; | ||
} | null, | ||
osm: { | ||
accountCreated: string; | ||
} | null, | ||
organisations: string[], | ||
pmTeams: string[], | ||
} | ||
|
||
const initialState = { | ||
userDetails: null, | ||
token: '', | ||
session: null, | ||
osm: null, | ||
organisations: [], | ||
pmTeams: [], | ||
} satisfies UserData; | ||
|
||
type Actions = { | ||
type: typeof types.SET_USER_DETAILS, | ||
userDetails: UserData['userDetails'], | ||
} | { | ||
type: typeof types.SET_OSM, | ||
osm: UserData['osm'], | ||
} | { | ||
type: typeof types.SET_ORGANISATIONS, | ||
organisations: UserData['organisations'], | ||
} | { | ||
type: typeof types.SET_PM_TEAMS, | ||
teams: UserData['pmTeams'], | ||
} | { | ||
type: typeof types.SET_TOKEN, | ||
token: UserData['token'], | ||
} | { | ||
type: typeof types.SET_SESSION, | ||
session: UserData['session'], | ||
} | { | ||
type: typeof types.CLEAR_SESSION, | ||
session: null, | ||
} | ||
|
||
export function authorizationReducer(state = initialState, action: Actions) { | ||
switch (action.type) { | ||
case types.SET_USER_DETAILS: { | ||
return { ...state, userDetails: action.userDetails }; | ||
} | ||
case types.SET_OSM: { | ||
return { ...state, osm: action.osm }; | ||
} | ||
case types.SET_ORGANISATIONS: { | ||
return { ...state, organisations: action.organisations }; | ||
} | ||
case types.SET_PM_TEAMS: { | ||
return { ...state, pmTeams: action.teams }; | ||
} | ||
case types.SET_TOKEN: { | ||
return { ...state, token: action.token }; | ||
} | ||
case types.SET_SESSION: { | ||
return { ...state, session: action.session }; | ||
} | ||
case types.CLEAR_SESSION: { | ||
return initialState; | ||
} | ||
default: | ||
return state; | ||
} | ||
} |
File renamed without changes.
Oops, something went wrong.