From 5f41b4bd10257ac59e26db76b557b24828f11673 Mon Sep 17 00:00:00 2001 From: PeterJFB Date: Fri, 29 Apr 2022 19:00:01 +0200 Subject: [PATCH 1/3] Add randomly selected interestgroups to frontpage --- app/actions/ActionTypes.js | 3 +++ app/actions/GroupActions.js | 13 +++++++++++++ app/reducers/frontpage.js | 4 +++- app/reducers/groups.js | 13 +++++++++++++ app/routes/overview/IndexRoute.js | 8 +++++++- 5 files changed, 39 insertions(+), 2 deletions(-) diff --git a/app/actions/ActionTypes.js b/app/actions/ActionTypes.js index 3115c10e1f..eadb8f8942 100644 --- a/app/actions/ActionTypes.js +++ b/app/actions/ActionTypes.js @@ -145,6 +145,9 @@ export const Group = { CREATE: (generateStatuses('Group.CREATE'): AAT), REMOVE: (generateStatuses('Group.REMOVE'): AAT), MEMBERSHIP_FETCH: (generateStatuses('Group.MEMBERSHIP_FETCH'): AAT), + FETCH_RADOM_INTERESTS: (generateStatuses( + 'Group.FETCH_RANDOM_INTERESTS' + ): AAT), }; export const CompanyInterestForm = { diff --git a/app/actions/GroupActions.js b/app/actions/GroupActions.js index 016e47918e..705637c078 100644 --- a/app/actions/GroupActions.js +++ b/app/actions/GroupActions.js @@ -84,6 +84,19 @@ export function fetchAllWithType(type: string): Thunk { }); } +export function fetchRandomInterestgroups(): Thunk { + return callAPI({ + types: Group.FETCH_RADOM_INTERESTS, + endpoint: '/groups/random_interests/', + method: 'GET', + meta: { + errorMessage: 'Henting av tilfeldige interessegrupper feilet', + }, + useCache: false, + schema: [groupSchema], + }); +} + export function editGroup(group: Object): Thunk<*> { return (dispatch) => dispatch( diff --git a/app/reducers/frontpage.js b/app/reducers/frontpage.js index 2c47982be8..c348458528 100644 --- a/app/reducers/frontpage.js +++ b/app/reducers/frontpage.js @@ -5,13 +5,15 @@ import { sortBy } from 'lodash'; import { createSelector } from 'reselect'; import { selectArticles } from './articles'; import { selectEvents } from './events'; +import { selectRandomInterestgroups } from './groups'; export default fetching(Frontpage.FETCH); export const selectFrontpage = createSelector( selectArticles, selectEvents, - (articles, events) => { + selectRandomInterestgroups, + (articles, events, interestGroups) => { articles = articles.map((article) => ({ ...article, documentType: 'article', diff --git a/app/reducers/groups.js b/app/reducers/groups.js index 5329c596b5..9d0bf3239c 100644 --- a/app/reducers/groups.js +++ b/app/reducers/groups.js @@ -49,6 +49,10 @@ export default createEntityReducer({ } break; + case Group.FETCH_RADOM_INTERESTS.SUCCESS: + newState.randomInterestById = action.payload.result; + break; + default: break; } @@ -72,3 +76,12 @@ export const selectGroupsWithType = createSelector( (state, props) => props.groupType, (groups, groupType) => groups.filter((g) => g.type === groupType) ); + +export const selectRandomInterestgroups = createSelector( + (state) => state.groups.byId, + (state) => state.groups.randomInterestById, + (groupsById, groupIds) => { + if (!groupsById || !groupIds) return []; + return groupIds.map((id) => groupsById[id]); + } +); diff --git a/app/routes/overview/IndexRoute.js b/app/routes/overview/IndexRoute.js index a16d49f847..0d0b09457a 100644 --- a/app/routes/overview/IndexRoute.js +++ b/app/routes/overview/IndexRoute.js @@ -17,11 +17,14 @@ import { } from 'app/reducers/feeds'; import { selectPinnedPolls } from 'app/reducers/polls'; import { votePoll } from 'app/actions/PollActions'; +import { fetchRandomInterestgroups } from 'app/actions/GroupActions'; +import { selectRandomInterestgroups } from 'app/reducers/groups'; const mapStateToProps = (state) => ({ frontpage: selectFrontpage(state), feed: selectFeedById(state, { feedId: 'personal' }), shouldFetchQuote: isEmpty(selectRandomQuote(state)), + shouldFetchInterestgroups: isEmpty(selectRandomInterestgroups(state)), feedItems: selectFeedActivitesByFeedId(state, { feedId: 'personal', }), @@ -38,10 +41,13 @@ export default compose( // ), connect(mapStateToProps, mapDispatchToProps), prepare( - ({ shouldFetchQuote, loggedIn }, dispatch) => + ({ shouldFetchQuote, shouldFetchInterestgroups, loggedIn }, dispatch) => Promise.all([ loggedIn && shouldFetchQuote && dispatch(fetchRandomQuote()), dispatch(fetchReadmes(loggedIn ? 4 : 1)), + loggedIn && + shouldFetchInterestgroups && + dispatch(fetchRandomInterestgroups()), ]), [], { awaitOnSsr: false } From 9dc39978dc6567379c96359929f25851e6945330 Mon Sep 17 00:00:00 2001 From: PeterJFB Date: Fri, 29 Apr 2022 19:17:59 +0200 Subject: [PATCH 2/3] Correct radom typo --- app/actions/ActionTypes.js | 2 +- app/actions/GroupActions.js | 2 +- app/reducers/groups.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/actions/ActionTypes.js b/app/actions/ActionTypes.js index eadb8f8942..1c90949285 100644 --- a/app/actions/ActionTypes.js +++ b/app/actions/ActionTypes.js @@ -145,7 +145,7 @@ export const Group = { CREATE: (generateStatuses('Group.CREATE'): AAT), REMOVE: (generateStatuses('Group.REMOVE'): AAT), MEMBERSHIP_FETCH: (generateStatuses('Group.MEMBERSHIP_FETCH'): AAT), - FETCH_RADOM_INTERESTS: (generateStatuses( + FETCH_RANDOM_INTERESTS: (generateStatuses( 'Group.FETCH_RANDOM_INTERESTS' ): AAT), }; diff --git a/app/actions/GroupActions.js b/app/actions/GroupActions.js index 705637c078..45f39b3690 100644 --- a/app/actions/GroupActions.js +++ b/app/actions/GroupActions.js @@ -86,7 +86,7 @@ export function fetchAllWithType(type: string): Thunk { export function fetchRandomInterestgroups(): Thunk { return callAPI({ - types: Group.FETCH_RADOM_INTERESTS, + types: Group.FETCH_RANDOM_INTERESTS, endpoint: '/groups/random_interests/', method: 'GET', meta: { diff --git a/app/reducers/groups.js b/app/reducers/groups.js index 9d0bf3239c..8321baed6d 100644 --- a/app/reducers/groups.js +++ b/app/reducers/groups.js @@ -49,7 +49,7 @@ export default createEntityReducer({ } break; - case Group.FETCH_RADOM_INTERESTS.SUCCESS: + case Group.FETCH_RANDOM_INTERESTS.SUCCESS: newState.randomInterestById = action.payload.result; break; From 78c44c391ba3e41bb5a2571d3c4612039e02ddc5 Mon Sep 17 00:00:00 2001 From: PeterJFB Date: Sat, 30 Apr 2022 12:08:17 +0200 Subject: [PATCH 3/3] typo: InterestGroup --- app/actions/GroupActions.js | 2 +- app/reducers/frontpage.js | 4 ++-- app/reducers/groups.js | 2 +- app/routes/overview/IndexRoute.js | 12 ++++++------ 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/actions/GroupActions.js b/app/actions/GroupActions.js index 45f39b3690..b78cbffc61 100644 --- a/app/actions/GroupActions.js +++ b/app/actions/GroupActions.js @@ -84,7 +84,7 @@ export function fetchAllWithType(type: string): Thunk { }); } -export function fetchRandomInterestgroups(): Thunk { +export function fetchRandomInterestGroups(): Thunk { return callAPI({ types: Group.FETCH_RANDOM_INTERESTS, endpoint: '/groups/random_interests/', diff --git a/app/reducers/frontpage.js b/app/reducers/frontpage.js index c348458528..68b3e0f398 100644 --- a/app/reducers/frontpage.js +++ b/app/reducers/frontpage.js @@ -5,14 +5,14 @@ import { sortBy } from 'lodash'; import { createSelector } from 'reselect'; import { selectArticles } from './articles'; import { selectEvents } from './events'; -import { selectRandomInterestgroups } from './groups'; +import { selectRandomInterestGroups } from './groups'; export default fetching(Frontpage.FETCH); export const selectFrontpage = createSelector( selectArticles, selectEvents, - selectRandomInterestgroups, + selectRandomInterestGroups, (articles, events, interestGroups) => { articles = articles.map((article) => ({ ...article, diff --git a/app/reducers/groups.js b/app/reducers/groups.js index 8321baed6d..7ae0896755 100644 --- a/app/reducers/groups.js +++ b/app/reducers/groups.js @@ -77,7 +77,7 @@ export const selectGroupsWithType = createSelector( (groups, groupType) => groups.filter((g) => g.type === groupType) ); -export const selectRandomInterestgroups = createSelector( +export const selectRandomInterestGroups = createSelector( (state) => state.groups.byId, (state) => state.groups.randomInterestById, (groupsById, groupIds) => { diff --git a/app/routes/overview/IndexRoute.js b/app/routes/overview/IndexRoute.js index 0d0b09457a..175594de22 100644 --- a/app/routes/overview/IndexRoute.js +++ b/app/routes/overview/IndexRoute.js @@ -17,14 +17,14 @@ import { } from 'app/reducers/feeds'; import { selectPinnedPolls } from 'app/reducers/polls'; import { votePoll } from 'app/actions/PollActions'; -import { fetchRandomInterestgroups } from 'app/actions/GroupActions'; -import { selectRandomInterestgroups } from 'app/reducers/groups'; +import { fetchRandomInterestGroups } from 'app/actions/GroupActions'; +import { selectRandomInterestGroups } from 'app/reducers/groups'; const mapStateToProps = (state) => ({ frontpage: selectFrontpage(state), feed: selectFeedById(state, { feedId: 'personal' }), shouldFetchQuote: isEmpty(selectRandomQuote(state)), - shouldFetchInterestgroups: isEmpty(selectRandomInterestgroups(state)), + shouldFetchInterestGroups: isEmpty(selectRandomInterestGroups(state)), feedItems: selectFeedActivitesByFeedId(state, { feedId: 'personal', }), @@ -41,13 +41,13 @@ export default compose( // ), connect(mapStateToProps, mapDispatchToProps), prepare( - ({ shouldFetchQuote, shouldFetchInterestgroups, loggedIn }, dispatch) => + ({ shouldFetchQuote, shouldFetchInterestGroups, loggedIn }, dispatch) => Promise.all([ loggedIn && shouldFetchQuote && dispatch(fetchRandomQuote()), dispatch(fetchReadmes(loggedIn ? 4 : 1)), loggedIn && - shouldFetchInterestgroups && - dispatch(fetchRandomInterestgroups()), + shouldFetchInterestGroups && + dispatch(fetchRandomInterestGroups()), ]), [], { awaitOnSsr: false }