Skip to content
Closed
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
3 changes: 3 additions & 0 deletions app/actions/ActionTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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_RANDOM_INTERESTS: (generateStatuses(
'Group.FETCH_RANDOM_INTERESTS'
): AAT),
};

export const CompanyInterestForm = {
Expand Down
13 changes: 13 additions & 0 deletions app/actions/GroupActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,19 @@ export function fetchAllWithType(type: string): Thunk<any> {
});
}

export function fetchRandomInterestGroups(): Thunk<any> {
return callAPI({
types: Group.FETCH_RANDOM_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(
Expand Down
4 changes: 3 additions & 1 deletion app/reducers/frontpage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
13 changes: 13 additions & 0 deletions app/reducers/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ export default createEntityReducer({
}
break;

case Group.FETCH_RANDOM_INTERESTS.SUCCESS:
newState.randomInterestById = action.payload.result;
break;

default:
break;
}
Expand All @@ -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]);
}
);
8 changes: 7 additions & 1 deletion app/routes/overview/IndexRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}),
Expand All @@ -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 }
Expand Down