allow apps to set their own default followed tags

This commit is contained in:
Sean Yesmunt 2019-06-13 12:10:27 -04:00
parent 82a5f242d0
commit ae2f720d1d
4 changed files with 54 additions and 105 deletions

21
dist/bundle.es.js vendored
View file

@ -3732,24 +3732,9 @@ function contentReducer(state = defaultState$6, action) {
return state;
}
const defaultFollowedTags = ['gaming', 'blockchain', 'news', 'learning', 'funny', 'technology', 'automotive', 'economics', 'sports', 'food', 'science', 'art', 'nature', 'beliefs', 'music', 'pop culture', 'weapons'];
const defaultRecommendedTags = [];
var _extends$b = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
function getDefaultRecommendedTags() {
return defaultFollowedTags.concat(defaultRecommendedTags).reduce((tagsMap, tag) => _extends$b({}, tagsMap, {
[tag]: { name: tag }
}), {});
}
const defaultState$7 = {
followedTags: defaultFollowedTags,
knownTags: getDefaultRecommendedTags()
};
const tagsReducer = handleActions({
const tagsReducerBuilder = defaultState => handleActions({
[TOGGLE_TAG_FOLLOW]: (state, action) => {
const { followedTags } = state;
const { name } = action.data;
@ -3792,7 +3777,7 @@ const tagsReducer = handleActions({
followedTags: newFollowedTags
});
}
}, defaultState$7);
}, defaultState);
const selectState$5 = state => state.content || {};
@ -4041,6 +4026,6 @@ exports.selectWalletUnlockPending = selectWalletUnlockPending;
exports.selectWalletUnlockResult = selectWalletUnlockResult;
exports.selectWalletUnlockSucceeded = selectWalletUnlockSucceeded;
exports.setSearchApi = setSearchApi;
exports.tagsReducer = tagsReducer;
exports.tagsReducerBuilder = tagsReducerBuilder;
exports.toQueryString = toQueryString;
exports.walletReducer = walletReducer;

View file

@ -1,21 +0,0 @@
export const defaultFollowedTags = [
'gaming',
'blockchain',
'news',
'learning',
'funny',
'technology',
'automotive',
'economics',
'sports',
'food',
'science',
'art',
'nature',
'beliefs',
'music',
'pop culture',
'weapons',
];
export const defaultRecommendedTags = [];

View file

@ -104,7 +104,7 @@ export { notificationsReducer } from 'redux/reducers/notifications';
export { searchReducer } from 'redux/reducers/search';
export { walletReducer } from 'redux/reducers/wallet';
export { contentReducer } from 'redux/reducers/content';
export { tagsReducer } from 'redux/reducers/tags';
export { tagsReducerBuilder } from 'redux/reducers/tags';
// selectors
export { makeSelectContentPositionForUri } from 'redux/selectors/content';

View file

@ -1,70 +1,55 @@
// @flow
import * as ACTIONS from 'constants/action_types';
import { handleActions } from 'util/redux-utils';
import { defaultRecommendedTags, defaultFollowedTags } from 'constants/tags';
function getDefaultRecommendedTags() {
return defaultFollowedTags.concat(defaultRecommendedTags).reduce(
(tagsMap, tag) => ({
...tagsMap,
[tag]: { name: tag },
}),
{}
export const tagsReducerBuilder = (defaultState: TagState) =>
handleActions(
{
[ACTIONS.TOGGLE_TAG_FOLLOW]: (state: TagState, action: TagAction): TagState => {
const { followedTags } = state;
const { name } = action.data;
let newFollowedTags = followedTags.slice();
if (newFollowedTags.includes(name)) {
newFollowedTags = newFollowedTags.filter(tag => tag !== name);
} else {
newFollowedTags.push(name);
}
return {
...state,
followedTags: newFollowedTags,
};
},
[ACTIONS.TAG_ADD]: (state: TagState, action: TagAction) => {
const { knownTags } = state;
const { name } = action.data;
let newKnownTags = { ...knownTags };
newKnownTags[name] = { name };
return {
...state,
knownTags: newKnownTags,
};
},
[ACTIONS.TAG_DELETE]: (state: TagState, action: TagAction) => {
const { knownTags, followedTags } = state;
const { name } = action.data;
let newKnownTags = { ...knownTags };
delete newKnownTags[name];
const newFollowedTags = followedTags.filter(tag => tag !== name);
return {
...state,
knownTags: newKnownTags,
followedTags: newFollowedTags,
};
},
},
defaultState
);
}
const defaultState: TagState = {
followedTags: defaultFollowedTags,
knownTags: getDefaultRecommendedTags(),
};
export const tagsReducer = handleActions(
{
[ACTIONS.TOGGLE_TAG_FOLLOW]: (state: TagState, action: TagAction): TagState => {
const { followedTags } = state;
const { name } = action.data;
let newFollowedTags = followedTags.slice();
if (newFollowedTags.includes(name)) {
newFollowedTags = newFollowedTags.filter(tag => tag !== name);
} else {
newFollowedTags.push(name);
}
return {
...state,
followedTags: newFollowedTags,
};
},
[ACTIONS.TAG_ADD]: (state: TagState, action: TagAction) => {
const { knownTags } = state;
const { name } = action.data;
let newKnownTags = { ...knownTags };
newKnownTags[name] = { name };
return {
...state,
knownTags: newKnownTags,
};
},
[ACTIONS.TAG_DELETE]: (state: TagState, action: TagAction) => {
const { knownTags, followedTags } = state;
const { name } = action.data;
let newKnownTags = { ...knownTags };
delete newKnownTags[name];
const newFollowedTags = followedTags.filter(tag => tag !== name);
return {
...state,
knownTags: newKnownTags,
followedTags: newFollowedTags,
};
},
},
defaultState
);