Skip to content
This repository has been archived by the owner on Oct 1, 2019. It is now read-only.

Commit

Permalink
Add recentTags redux store
Browse files Browse the repository at this point in the history
  • Loading branch information
voidxnull committed Nov 26, 2017
1 parent eabd9f4 commit 383f738
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const tags = require('./tags');
export const hashtags = require('./hashtags');
export const geotags = require('./geotags');
export const schools = require('./schools');
export const recentTags = require('./recent-tags');

export const geo = require('./geo');

Expand Down
27 changes: 27 additions & 0 deletions src/actions/recent-tags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
This file is a part of libertysoil.org website
Copyright (C) 2016 Loki Education (Social Enterprise)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
export const SET_RECENT_TAGS = 'SET_RECENT_TAGS';

export function setRecentTags(tags) {
return {
type: SET_RECENT_TAGS,
payload: {
...tags
}
};
}
3 changes: 2 additions & 1 deletion src/store/geotags.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import i from 'immutable';
import { concat, keyBy } from 'lodash';

import { geotags as g } from '../actions';
import { geotags as g, recentTags } from '../actions';

const initialState = i.Map({});

Expand Down Expand Up @@ -47,6 +47,7 @@ export default function reducer(state = initialState, action) {
break;
}

case recentTags.SET_RECENT_TAGS:
case g.SET_GEOTAGS: {
const geotags = keyBy(action.payload.geotags, 'url_name');
state = i.fromJS(geotags);
Expand Down
3 changes: 2 additions & 1 deletion src/store/hashtags.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import i from 'immutable';
import _ from 'lodash';

import { hashtags as h } from '../actions';
import { hashtags as h, recentTags } from '../actions';

const initialState = i.Map({});

Expand All @@ -31,6 +31,7 @@ export default function reducer(state = initialState, action) {
break;
}

case recentTags.SET_RECENT_TAGS:
case h.SET_HASHTAGS: {
const hashtags = _.keyBy(action.payload.hashtags, 'name');
state = state.merge(i.fromJS(hashtags));
Expand Down
52 changes: 52 additions & 0 deletions src/store/recent_tags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
This file is a part of libertysoil.org website
Copyright (C) 2016 Loki Education (Social Enterprise)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import i from 'immutable';
import { map } from 'lodash';
import { recentTags } from '../actions';

export const initialState = i.fromJS({
hashtags: [],
schools: [],
geotags: [],
});

export function reducer(state = initialState, action) {
switch (action.type) {
case recentTags.SET_RECENT_TAGS: {
const tags = {};

if (action.payload.hashtags) {
tags.hashtags = map(action.payload.hashtags, 'name');
}

if (action.payload.schools) {
tags.schools = map(action.payload.schools, 'id');
}

if (action.payload.geotags) {
tags.geotags = map(action.payload.geotags, 'url_name');
}

state = state.merge(i.fromJS(tags));

break;
}
}

return state;
}
3 changes: 2 additions & 1 deletion src/store/schools.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import i from 'immutable';
import { keyBy } from 'lodash';

import { schools as s } from '../actions';
import { schools as s, recentTags } from '../actions';

function cleanupSchoolObject(school) {
if (school.description === null) {
Expand Down Expand Up @@ -47,6 +47,7 @@ export default function reducer(state = initialState, action) {
break;
}

case recentTags.SET_RECENT_TAGS:
case s.SET_SCHOOLS: {
const schools = keyBy(action.payload.schools.map(school => cleanupSchoolObject(school)), 'id');
state = state.merge(i.fromJS(schools));
Expand Down

0 comments on commit 383f738

Please sign in to comment.