From ae2f720d1da430c6b931a02ee821799270dff5d7 Mon Sep 17 00:00:00 2001 From: Sean Yesmunt Date: Thu, 13 Jun 2019 12:10:27 -0400 Subject: [PATCH] allow apps to set their own default followed tags --- dist/bundle.es.js | 21 +------ src/constants/tags.js | 21 ------- src/index.js | 2 +- src/redux/reducers/tags.js | 115 ++++++++++++++++--------------------- 4 files changed, 54 insertions(+), 105 deletions(-) delete mode 100644 src/constants/tags.js diff --git a/dist/bundle.es.js b/dist/bundle.es.js index 4b0de17..bc5368f 100644 --- a/dist/bundle.es.js +++ b/dist/bundle.es.js @@ -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; diff --git a/src/constants/tags.js b/src/constants/tags.js deleted file mode 100644 index 7f00bd2..0000000 --- a/src/constants/tags.js +++ /dev/null @@ -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 = []; diff --git a/src/index.js b/src/index.js index e3d84b0..4ae019e 100644 --- a/src/index.js +++ b/src/index.js @@ -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'; diff --git a/src/redux/reducers/tags.js b/src/redux/reducers/tags.js index fb01577..aca5976 100644 --- a/src/redux/reducers/tags.js +++ b/src/redux/reducers/tags.js @@ -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 -);