Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add randomly selected interestgroups to frontpage #2696

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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> {
PeterJFB marked this conversation as resolved.
Show resolved Hide resolved
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