From 009ae8b8fac991c306179b66ac76066e92e16322 Mon Sep 17 00:00:00 2001 From: Sean Yesmunt Date: Tue, 2 Jul 2019 16:33:57 -0400 Subject: [PATCH] add tags back to redux --- dist/bundle.es.js | 36 +++++++++--- dist/flow-typed/Lbry.js | 4 +- src/constants/tags.js | 24 ++++++++ src/index.js | 8 ++- src/redux/reducers/tags.js | 115 +++++++++++++++++++++---------------- src/util/claim.js | 8 +-- 6 files changed, 127 insertions(+), 68 deletions(-) create mode 100644 src/constants/tags.js diff --git a/dist/bundle.es.js b/dist/bundle.es.js index d81f802..2bde5b9 100644 --- a/dist/bundle.es.js +++ b/dist/bundle.es.js @@ -645,6 +645,12 @@ const SEARCH_OPTIONS = { MEDIA_APPLICATION: 'application' }; +const DEFAULT_FOLLOWED_TAGS = ['blockchain', 'news', 'learning', 'technology', 'automotive', 'economics', 'food', 'science', 'art', 'nature']; + +const MATURE_TAGS = ['porn', 'nsfw', 'mature', 'xxx']; + +const DEFAULT_KNOWN_TAGS = ['beliefs', 'funny', 'gaming', 'pop culture', 'music', 'sports', 'weapons']; + // const CHECK_DAEMON_STARTED_TRY_NUMBER = 200; @@ -1208,9 +1214,7 @@ function doDismissError() { var _extends$2 = 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; }; -// - -const naughtyTags = ['porn', 'nsfw', 'mature', 'xxx'].reduce((acc, tag) => _extends$2({}, acc, { [tag]: true }), {}); +const matureTagMap = MATURE_TAGS.reduce((acc, tag) => _extends$2({}, acc, { [tag]: true }), {}); const isClaimNsfw = claim => { if (!claim) { @@ -1224,7 +1228,7 @@ const isClaimNsfw = claim => { const tags = claim.value.tags || []; for (let i = 0; i < tags.length; i += 1) { const tag = tags[i].toLowerCase(); - if (naughtyTags[tag]) { + if (matureTagMap[tag]) { return true; } } @@ -4152,7 +4156,18 @@ const searchReducer = handleActions({ var _extends$d = 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; }; -const tagsReducerBuilder = defaultState => handleActions({ +function getDefaultKnownTags() { + return DEFAULT_FOLLOWED_TAGS.concat(DEFAULT_KNOWN_TAGS).reduce((tagsMap, tag) => _extends$d({}, tagsMap, { + [tag]: { name: tag } + }), {}); +} + +const defaultState$8 = { + followedTags: DEFAULT_FOLLOWED_TAGS, + knownTags: getDefaultKnownTags() +}; + +const tagsReducer = handleActions({ [TOGGLE_TAG_FOLLOW]: (state, action) => { const { followedTags } = state; const { name } = action.data; @@ -4195,7 +4210,7 @@ const tagsReducerBuilder = defaultState => handleActions({ followedTags: newFollowedTags }); } -}, defaultState); +}, defaultState$8); var _extends$e = 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; }; @@ -4208,7 +4223,7 @@ const buildDraftTransaction = () => ({ // See details in https://github.com/lbryio/lbry/issues/1307 -const defaultState$8 = { +const defaultState$9 = { balance: undefined, totalBalance: undefined, latestBlock: undefined, @@ -4451,7 +4466,7 @@ const walletReducer = handleActions({ [UPDATE_CURRENT_HEIGHT]: (state, action) => _extends$e({}, state, { latestBlock: action.data }) -}, defaultState$8); +}, defaultState$9); const selectState$5 = state => state.content || {}; @@ -4613,8 +4628,11 @@ const selectUnfollowedTags = reselect.createSelector(selectKnownTagsByName, sele exports.ACTIONS = action_types; exports.CLAIM_VALUES = claim; +exports.DEFAULT_FOLLOWED_TAGS = DEFAULT_FOLLOWED_TAGS; +exports.DEFAULT_KNOWN_TAGS = DEFAULT_KNOWN_TAGS; exports.LICENSES = licenses; exports.Lbry = lbryProxy; +exports.MATURE_TAGS = MATURE_TAGS; exports.PAGES = pages; exports.SEARCH_OPTIONS = SEARCH_OPTIONS; exports.SEARCH_TYPES = SEARCH_TYPES; @@ -4818,6 +4836,6 @@ exports.selectWalletUnlockPending = selectWalletUnlockPending; exports.selectWalletUnlockResult = selectWalletUnlockResult; exports.selectWalletUnlockSucceeded = selectWalletUnlockSucceeded; exports.setSearchApi = setSearchApi; -exports.tagsReducerBuilder = tagsReducerBuilder; +exports.tagsReducer = tagsReducer; exports.toQueryString = toQueryString; exports.walletReducer = walletReducer; diff --git a/dist/flow-typed/Lbry.js b/dist/flow-typed/Lbry.js index bc02e1f..335eda1 100644 --- a/dist/flow-typed/Lbry.js +++ b/dist/flow-typed/Lbry.js @@ -103,7 +103,7 @@ declare type ChannelCreateResponse = GenericTxResponse & { outputs: Array, }; -declare type UpdateChannelResponse = GenericTxResponse & { +declare type ChannelUpdateResponse = GenericTxResponse & { outputs: Array, }; @@ -178,7 +178,7 @@ declare type LbryTypes = { claim_search: (params: {}) => Promise, claim_list: (params?: {}) => Promise, channel_create: (params: {}) => Promise, - channel_update: (params: {}) => Promise, + channel_update: (params: {}) => Promise, channel_list: () => Promise, stream_abandon: (params: {}) => Promise, channel_abandon: (params: {}) => Promise, diff --git a/src/constants/tags.js b/src/constants/tags.js new file mode 100644 index 0000000..09630bb --- /dev/null +++ b/src/constants/tags.js @@ -0,0 +1,24 @@ +export const DEFAULT_FOLLOWED_TAGS = [ + 'blockchain', + 'news', + 'learning', + 'technology', + 'automotive', + 'economics', + 'food', + 'science', + 'art', + 'nature', +]; + +export const MATURE_TAGS = ['porn', 'nsfw', 'mature', 'xxx']; + +export const DEFAULT_KNOWN_TAGS = [ + 'beliefs', + 'funny', + 'gaming', + 'pop culture', + 'music', + 'sports', + 'weapons', +]; diff --git a/src/index.js b/src/index.js index 9754c25..3202149 100644 --- a/src/index.js +++ b/src/index.js @@ -7,6 +7,7 @@ import * as SORT_OPTIONS from 'constants/sort_options'; import * as THUMBNAIL_STATUSES from 'constants/thumbnail_upload_statuses'; import * as TRANSACTIONS from 'constants/transaction_types'; import { SEARCH_TYPES, SEARCH_OPTIONS } from 'constants/search'; +import { DEFAULT_KNOWN_TAGS, DEFAULT_FOLLOWED_TAGS, MATURE_TAGS } from 'constants/tags'; import Lbry from 'lbry'; import { selectState as selectSearchState } from 'redux/selectors/search'; @@ -22,6 +23,9 @@ export { TRANSACTIONS, SORT_OPTIONS, PAGES, + DEFAULT_KNOWN_TAGS, + DEFAULT_FOLLOWED_TAGS, + MATURE_TAGS, }; // common @@ -69,7 +73,7 @@ export { doUploadThumbnail, doPrepareEdit, doPublish, - doCheckPendingPublishes + doCheckPendingPublishes, } from 'redux/actions/publish'; export { @@ -122,7 +126,7 @@ export { fileReducer } from 'redux/reducers/file'; export { notificationsReducer } from 'redux/reducers/notifications'; export { publishReducer } from 'redux/reducers/publish'; export { searchReducer } from 'redux/reducers/search'; -export { tagsReducerBuilder } from 'redux/reducers/tags'; +export { tagsReducer } from 'redux/reducers/tags'; export { walletReducer } from 'redux/reducers/wallet'; // selectors diff --git a/src/redux/reducers/tags.js b/src/redux/reducers/tags.js index aca5976..79692ba 100644 --- a/src/redux/reducers/tags.js +++ b/src/redux/reducers/tags.js @@ -1,55 +1,70 @@ // @flow import * as ACTIONS from 'constants/action_types'; import { handleActions } from 'util/redux-utils'; +import { DEFAULT_KNOWN_TAGS, DEFAULT_FOLLOWED_TAGS } from 'constants/tags'; -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 +function getDefaultKnownTags() { + return DEFAULT_FOLLOWED_TAGS.concat(DEFAULT_KNOWN_TAGS).reduce( + (tagsMap, tag) => ({ + ...tagsMap, + [tag]: { name: tag }, + }), + {} ); +} + +const defaultState: TagState = { + followedTags: DEFAULT_FOLLOWED_TAGS, + knownTags: getDefaultKnownTags(), +}; + +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 +); diff --git a/src/util/claim.js b/src/util/claim.js index 73adb7a..b5d6a96 100644 --- a/src/util/claim.js +++ b/src/util/claim.js @@ -1,9 +1,7 @@ // @flow +import { MATURE_TAGS } from 'constants/tags'; -const naughtyTags = ['porn', 'nsfw', 'mature', 'xxx'].reduce( - (acc, tag) => ({ ...acc, [tag]: true }), - {} -); +const matureTagMap = MATURE_TAGS.reduce((acc, tag) => ({ ...acc, [tag]: true }), {}); export const isClaimNsfw = (claim: Claim): boolean => { if (!claim) { @@ -17,7 +15,7 @@ export const isClaimNsfw = (claim: Claim): boolean => { const tags = claim.value.tags || []; for (let i = 0; i < tags.length; i += 1) { const tag = tags[i].toLowerCase(); - if (naughtyTags[tag]) { + if (matureTagMap[tag]) { return true; } }