diff --git a/packages/common/src/store/pages/feed/actions.ts b/packages/common/src/store/pages/feed/actions.ts index 9caf849d7ea..bfd53edba9b 100644 --- a/packages/common/src/store/pages/feed/actions.ts +++ b/packages/common/src/store/pages/feed/actions.ts @@ -1,25 +1,54 @@ -// @ts-nocheck -// TODO(nkang) - convert to TS +import { FeedFilter } from 'models/FeedFilter' +import { ID } from 'models/Identifiers' + export const FETCH_SUGGESTED_FOLLOW_USERS = 'FEED/FETCH_SUGGESTED_FOLLOW_USERS' export const FOLLOW_USERS = 'FEED/FOLLOW_USERS' export const SET_SUGGESTED_FOLLOWS = 'FEED/SET_SUGGESTED_FOLLOWS' export const SET_FEED_FILTER = 'FEED/SET_FEED_FILTER' -export const fetchSuggestedFollowUsers = () => ({ - type: FETCH_SUGGESTED_FOLLOW_USERS -}) +export type FetchSuggestedFollowUsersAction = { + type: typeof FETCH_SUGGESTED_FOLLOW_USERS +} + +export type FollowUsersAction = { + type: typeof FOLLOW_USERS + userIds: ID[] +} + +export type SetSuggestedFollowsAction = { + type: typeof SET_SUGGESTED_FOLLOWS + userIds: ID[] +} + +export type SetFeedFilterAction = { + type: typeof SET_FEED_FILTER + filter: FeedFilter +} + +export type FeedPageActions = + | FetchSuggestedFollowUsersAction + | FollowUsersAction + | SetSuggestedFollowsAction + | SetFeedFilterAction + +export const fetchSuggestedFollowUsers = + (): FetchSuggestedFollowUsersAction => ({ + type: FETCH_SUGGESTED_FOLLOW_USERS + }) -export const followUsers = (userIds) => ({ +export const followUsers = (userIds: ID[]): FollowUsersAction => ({ type: FOLLOW_USERS, userIds }) -export const setSuggestedFollows = (userIds) => ({ +export const setSuggestedFollows = ( + userIds: ID[] +): SetSuggestedFollowsAction => ({ type: SET_SUGGESTED_FOLLOWS, userIds }) -export const setFeedFilter = (filter) => ({ +export const setFeedFilter = (filter: FeedFilter): SetFeedFilterAction => ({ type: SET_FEED_FILTER, filter }) diff --git a/packages/common/src/store/pages/feed/lineup/reducer.ts b/packages/common/src/store/pages/feed/lineup/reducer.ts index 9b75da90a00..52582c029b9 100644 --- a/packages/common/src/store/pages/feed/lineup/reducer.ts +++ b/packages/common/src/store/pages/feed/lineup/reducer.ts @@ -1,5 +1,5 @@ -// @ts-nocheck -// TODO(nkang) - convert to TS +import { LineupState } from 'models/Lineup' +import { Track } from 'models/Track' import { RESET_SUCCEEDED, stripPrefix } from 'store/lineup/actions' import { initialLineupState } from 'store/lineup/reducer' import { PREFIX } from 'store/pages/feed/lineup/actions' @@ -11,15 +11,22 @@ export const initialState = { entryIds: new Set([]) } +type ResetSucceededAction = { + type: typeof RESET_SUCCEEDED +} + const actionsMap = { - [RESET_SUCCEEDED](state, action) { + [RESET_SUCCEEDED](_state: LineupState, _action: ResetSucceededAction) { const newState = initialState return newState } } -const feed = (state = initialState, action) => { - const baseActionType = stripPrefix(PREFIX, action.type) +const feed = (state = initialState, action: ResetSucceededAction) => { + const baseActionType = stripPrefix( + PREFIX, + action.type + ) as typeof RESET_SUCCEEDED const matchingReduceFunction = actionsMap[baseActionType] if (!matchingReduceFunction) return state return matchingReduceFunction(state, action) diff --git a/packages/common/src/store/pages/feed/reducer.ts b/packages/common/src/store/pages/feed/reducer.ts index ba927381b10..4e0fc44cedd 100644 --- a/packages/common/src/store/pages/feed/reducer.ts +++ b/packages/common/src/store/pages/feed/reducer.ts @@ -1,16 +1,19 @@ -// @ts-nocheck -// TODO(nkang) - convert to TS -import { asLineup } from 'store/lineup/reducer' +import { LineupActions, asLineup } from 'store/lineup/reducer' import { SET_SUGGESTED_FOLLOWS, - SET_FEED_FILTER + SET_FEED_FILTER, + SetSuggestedFollowsAction, + SetFeedFilterAction, + FeedPageActions } from 'store/pages/feed/actions' import { PREFIX as FeedPrefix } from 'store/pages/feed/lineup/actions' import feedReducer, { initialState as feedLinupInitialState } from 'store/pages/feed/lineup/reducer' -import { FeedFilter } from '../../../models' +import { FeedFilter, Track } from '../../../models' + +import { FeedPageState } from './types' const initialState = { suggestedFollows: [], @@ -19,13 +22,16 @@ const initialState = { } const actionsMap = { - [SET_SUGGESTED_FOLLOWS](state, action) { + [SET_SUGGESTED_FOLLOWS]( + state: FeedPageState, + action: SetSuggestedFollowsAction + ) { return { ...state, suggestedFollows: action.userIds } }, - [SET_FEED_FILTER](state, action) { + [SET_FEED_FILTER](state: FeedPageState, action: SetFeedFilterAction) { return { ...state, feedFilter: action.filter @@ -35,13 +41,16 @@ const actionsMap = { const feedLineupReducer = asLineup(FeedPrefix, feedReducer) -const reducer = (state = initialState, action) => { - const feed = feedLineupReducer(state.feed, action) +const reducer = ( + state = initialState, + action: FeedPageActions | LineupActions +) => { + const feed = feedLineupReducer(state.feed, action as LineupActions) if (feed !== state.feed) return { ...state, feed } const matchingReduceFunction = actionsMap[action.type] if (!matchingReduceFunction) return state - return matchingReduceFunction(state, action) + return matchingReduceFunction(state, action as FeedPageActions) } export default reducer