Created
May 2, 2019 16:26
-
-
Save hoorayimhelping/17d3aef29069af3cfbeec347ab23a076 to your computer and use it in GitHub Desktop.
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
diff --git a/static/jsx/activity_feed.tsx b/static/jsx/activity_feed.tsx | |
index 217882f5f..1425da3cd 100644 | |
--- a/static/jsx/activity_feed.tsx | |
+++ b/static/jsx/activity_feed.tsx | |
@@ -41,7 +41,9 @@ const rootReducer = combineReducers({ | |
activitiesState, | |
buildingDetailsState, | |
paginationState, | |
-}); | |
+} as any); | |
+// This `as any`cast is a workaround to a bug in redux's TypeScript typings | |
+// see https://github.com/reduxjs/redux/issues/2709#issuecomment-357328709 | |
const store = createStore(rootReducer, applyMiddleware(thunk)); | |
store.dispatch(loadActivity()); | |
diff --git a/static/jsx/broker/activity/actions.ts b/static/jsx/broker/activity/actions.ts | |
index 6f31f7676..5e6a572ef 100644 | |
--- a/static/jsx/broker/activity/actions.ts | |
+++ b/static/jsx/broker/activity/actions.ts | |
@@ -1,5 +1,10 @@ | |
-import Axios from 'axios'; | |
+import Axios, { CancelTokenSource } from 'axios'; | |
+import { | |
+ ActivityFeedState, | |
+ BuildingDetailsState, | |
+ PaginationState, | |
+} from 'jsx/broker/activity/types'; | |
import { | |
addBuildingDetailsToUrl, | |
handleActivityFeedNetworkError, | |
@@ -26,7 +31,6 @@ export const LOAD_ACTIVITIES_SUCCESS = 'LOAD_ACTIVITIES_SUCCESS'; | |
export const LOAD_ACTIVITIES_FAILURE = 'LOAD_ACTIVITIES_FAILURE'; | |
const activityFeedApiUrl: string = Urls['broker-activity-api'](); | |
- | |
const getAdvisorOverrideFromUrl = (): URLSearchParams => { | |
// We use URLSearchParams here because they format repeating arguments the way Django likes, | |
// object_type=favorite&object_type=signup is used rather than | |
@@ -83,6 +87,37 @@ export function loadActivity(url: string = activityFeedApiUrl) { | |
export const FILTER_ACTIVITIES_SUCCESS = 'FILTER_ACTIVITIES_SUCCESS'; | |
+interface LoadActivitiesRequestAction { | |
+ type: typeof LOAD_ACTIVITIES_REQUEST; | |
+ payload: CancelTokenSource; | |
+}; | |
+ | |
+interface LoadActivitiesSuccessAction { | |
+ type: typeof LOAD_ACTIVITIES_SUCCESS; | |
+ payload: { data: Array<any> }; | |
+}; | |
+ | |
+interface LoadActivitiesFailureAction { | |
+ type: typeof LOAD_ACTIVITIES_FAILURE; | |
+ payload: Array<any>; | |
+}; | |
+ | |
+interface FilterActivitiesSuccessAction { | |
+ type: typeof FILTER_ACTIVITIES_SUCCESS; | |
+ payload: { data: Array<any> }; | |
+}; | |
+ | |
+export type ActivitesActionTypes = | |
+ LoadActivitiesRequestAction | | |
+ LoadActivitiesSuccessAction | | |
+ LoadActivitiesFailureAction | | |
+ FilterActivitiesSuccessAction; | |
+ | |
+export interface PaginationAction { | |
+ type: typeof LOAD_ACTIVITIES_SUCCESS | typeof FILTER_ACTIVITIES_SUCCESS; | |
+ payload: { links: PaginationState } | |
+}; | |
+ | |
// Todo: clean this duplication between loadActivity and filterActivity that was introduced | |
// to fix a bug. See #4020 | |
export function filterActivity(selected: Array<string>, url: string = activityFeedApiUrl) { | |
diff --git a/static/jsx/broker/activity/reducers.ts b/static/jsx/broker/activity/reducers.ts | |
index 2559ac970..c48a24827 100644 | |
--- a/static/jsx/broker/activity/reducers.ts | |
+++ b/static/jsx/broker/activity/reducers.ts | |
@@ -1,20 +1,22 @@ | |
import * as Actions from 'jsx/broker/activity/actions'; | |
+import { | |
+ ActivityFeedState, | |
+ BuildingDetailsState, | |
+ PaginationState, | |
+} from 'jsx/broker/activity/types'; | |
-export interface DefaultActivityFeedState { | |
- activities: Array<any>; | |
- axiosSource: any | null; | |
- errors: Array<Error>; | |
- isLoading: boolean; | |
-}; | |
-const defaultActivityFeedState: DefaultActivityFeedState = { | |
+const defaultActivityFeedState: ActivityFeedState = { | |
activities: [], | |
axiosSource: null, // The mechanism Axios (our request library) uses to abort in-flight requests | |
errors: [], | |
isLoading: false, | |
}; | |
-export function activitiesState(state: DefaultActivityFeedState = defaultActivityFeedState, action: any) { | |
+export function activitiesState( | |
+ state: ActivityFeedState = defaultActivityFeedState, | |
+ action: Actions.ActivitesActionTypes, | |
+) { | |
switch (action.type) { | |
case Actions.LOAD_ACTIVITIES_REQUEST: { | |
if (state.axiosSource) { | |
@@ -58,13 +60,16 @@ export function activitiesState(state: DefaultActivityFeedState = defaultActivit | |
} | |
} | |
-const defaultPaginationState = { | |
+const defaultPaginationState: PaginationState = { | |
prev: null, | |
self: null, | |
next: null, | |
}; | |
-export function paginationState(state = defaultPaginationState, action) { | |
+export function paginationState( | |
+ state: PaginationState = defaultPaginationState, | |
+ action: Actions.PaginationAction, | |
+) { | |
switch (action.type) { | |
case Actions.LOAD_ACTIVITIES_SUCCESS: | |
case Actions.FILTER_ACTIVITIES_SUCCESS: { | |
@@ -79,12 +84,12 @@ export function paginationState(state = defaultPaginationState, action) { | |
} | |
} | |
-const defaultBuildingDetailsState = { | |
+const defaultBuildingDetailsState: BuildingDetailsState = { | |
buildingDetails: null, | |
shouldShowBuildingPanel: false, | |
}; | |
-export function buildingDetailsState(state = defaultBuildingDetailsState, action) { | |
+export function buildingDetailsState(state: BuildingDetailsState = defaultBuildingDetailsState, action) { | |
switch (action.type) { | |
case Actions.LOAD_BUILDING_DETAILS_SUCCESS: { | |
return { | |
diff --git a/static/jsx/broker/activity/types.ts b/static/jsx/broker/activity/types.ts | |
new file mode 100644 | |
index 000000000..973f4a717 | |
--- /dev/null | |
+++ b/static/jsx/broker/activity/types.ts | |
@@ -0,0 +1,17 @@ | |
+export interface ActivityFeedState { | |
+ activities: Array<any>; | |
+ axiosSource: any | null; | |
+ errors: Array<Error>; | |
+ isLoading: boolean; | |
+}; | |
+ | |
+export interface PaginationState { | |
+ prev: string | null; | |
+ self: string | null; | |
+ next: string | null; | |
+}; | |
+ | |
+export interface BuildingDetailsState { | |
+ buildingDetails: any | null; | |
+ shouldShowBuildingPanel: boolean; | |
+} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment