Merge pull request #160 from lbryio/tags-redux

add tags back to redux
This commit is contained in:
Sean Yesmunt 2019-07-03 00:45:50 -04:00 committed by GitHub
commit 1ad35b8b40
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 127 additions and 68 deletions

36
dist/bundle.es.js vendored
View file

@ -645,6 +645,12 @@ const SEARCH_OPTIONS = {
MEDIA_APPLICATION: 'application' 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; 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; }; 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 matureTagMap = MATURE_TAGS.reduce((acc, tag) => _extends$2({}, acc, { [tag]: true }), {});
const naughtyTags = ['porn', 'nsfw', 'mature', 'xxx'].reduce((acc, tag) => _extends$2({}, acc, { [tag]: true }), {});
const isClaimNsfw = claim => { const isClaimNsfw = claim => {
if (!claim) { if (!claim) {
@ -1224,7 +1228,7 @@ const isClaimNsfw = claim => {
const tags = claim.value.tags || []; const tags = claim.value.tags || [];
for (let i = 0; i < tags.length; i += 1) { for (let i = 0; i < tags.length; i += 1) {
const tag = tags[i].toLowerCase(); const tag = tags[i].toLowerCase();
if (naughtyTags[tag]) { if (matureTagMap[tag]) {
return true; 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; }; 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) => { [TOGGLE_TAG_FOLLOW]: (state, action) => {
const { followedTags } = state; const { followedTags } = state;
const { name } = action.data; const { name } = action.data;
@ -4195,7 +4210,7 @@ const tagsReducerBuilder = defaultState => handleActions({
followedTags: newFollowedTags 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; }; 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 // See details in https://github.com/lbryio/lbry/issues/1307
const defaultState$8 = { const defaultState$9 = {
balance: undefined, balance: undefined,
totalBalance: undefined, totalBalance: undefined,
latestBlock: undefined, latestBlock: undefined,
@ -4451,7 +4466,7 @@ const walletReducer = handleActions({
[UPDATE_CURRENT_HEIGHT]: (state, action) => _extends$e({}, state, { [UPDATE_CURRENT_HEIGHT]: (state, action) => _extends$e({}, state, {
latestBlock: action.data latestBlock: action.data
}) })
}, defaultState$8); }, defaultState$9);
const selectState$5 = state => state.content || {}; const selectState$5 = state => state.content || {};
@ -4613,8 +4628,11 @@ const selectUnfollowedTags = reselect.createSelector(selectKnownTagsByName, sele
exports.ACTIONS = action_types; exports.ACTIONS = action_types;
exports.CLAIM_VALUES = claim; exports.CLAIM_VALUES = claim;
exports.DEFAULT_FOLLOWED_TAGS = DEFAULT_FOLLOWED_TAGS;
exports.DEFAULT_KNOWN_TAGS = DEFAULT_KNOWN_TAGS;
exports.LICENSES = licenses; exports.LICENSES = licenses;
exports.Lbry = lbryProxy; exports.Lbry = lbryProxy;
exports.MATURE_TAGS = MATURE_TAGS;
exports.PAGES = pages; exports.PAGES = pages;
exports.SEARCH_OPTIONS = SEARCH_OPTIONS; exports.SEARCH_OPTIONS = SEARCH_OPTIONS;
exports.SEARCH_TYPES = SEARCH_TYPES; exports.SEARCH_TYPES = SEARCH_TYPES;
@ -4818,6 +4836,6 @@ exports.selectWalletUnlockPending = selectWalletUnlockPending;
exports.selectWalletUnlockResult = selectWalletUnlockResult; exports.selectWalletUnlockResult = selectWalletUnlockResult;
exports.selectWalletUnlockSucceeded = selectWalletUnlockSucceeded; exports.selectWalletUnlockSucceeded = selectWalletUnlockSucceeded;
exports.setSearchApi = setSearchApi; exports.setSearchApi = setSearchApi;
exports.tagsReducerBuilder = tagsReducerBuilder; exports.tagsReducer = tagsReducer;
exports.toQueryString = toQueryString; exports.toQueryString = toQueryString;
exports.walletReducer = walletReducer; exports.walletReducer = walletReducer;

View file

@ -103,7 +103,7 @@ declare type ChannelCreateResponse = GenericTxResponse & {
outputs: Array<ChannelClaim>, outputs: Array<ChannelClaim>,
}; };
declare type UpdateChannelResponse = GenericTxResponse & { declare type ChannelUpdateResponse = GenericTxResponse & {
outputs: Array<ChannelClaim>, outputs: Array<ChannelClaim>,
}; };
@ -178,7 +178,7 @@ declare type LbryTypes = {
claim_search: (params: {}) => Promise<ClaimSearchResponse>, claim_search: (params: {}) => Promise<ClaimSearchResponse>,
claim_list: (params?: {}) => Promise<ClaimListResponse>, claim_list: (params?: {}) => Promise<ClaimListResponse>,
channel_create: (params: {}) => Promise<ChannelCreateResponse>, channel_create: (params: {}) => Promise<ChannelCreateResponse>,
channel_update: (params: {}) => Promise<UpdateChannelResponse>, channel_update: (params: {}) => Promise<ChannelUpdateResponse>,
channel_list: () => Promise<ChannelListResponse>, channel_list: () => Promise<ChannelListResponse>,
stream_abandon: (params: {}) => Promise<GenericTxResponse>, stream_abandon: (params: {}) => Promise<GenericTxResponse>,
channel_abandon: (params: {}) => Promise<GenericTxResponse>, channel_abandon: (params: {}) => Promise<GenericTxResponse>,

24
src/constants/tags.js Normal file
View file

@ -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',
];

View file

@ -7,6 +7,7 @@ import * as SORT_OPTIONS from 'constants/sort_options';
import * as THUMBNAIL_STATUSES from 'constants/thumbnail_upload_statuses'; import * as THUMBNAIL_STATUSES from 'constants/thumbnail_upload_statuses';
import * as TRANSACTIONS from 'constants/transaction_types'; import * as TRANSACTIONS from 'constants/transaction_types';
import { SEARCH_TYPES, SEARCH_OPTIONS } from 'constants/search'; 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 Lbry from 'lbry';
import { selectState as selectSearchState } from 'redux/selectors/search'; import { selectState as selectSearchState } from 'redux/selectors/search';
@ -22,6 +23,9 @@ export {
TRANSACTIONS, TRANSACTIONS,
SORT_OPTIONS, SORT_OPTIONS,
PAGES, PAGES,
DEFAULT_KNOWN_TAGS,
DEFAULT_FOLLOWED_TAGS,
MATURE_TAGS,
}; };
// common // common
@ -69,7 +73,7 @@ export {
doUploadThumbnail, doUploadThumbnail,
doPrepareEdit, doPrepareEdit,
doPublish, doPublish,
doCheckPendingPublishes doCheckPendingPublishes,
} from 'redux/actions/publish'; } from 'redux/actions/publish';
export { export {
@ -122,7 +126,7 @@ export { fileReducer } from 'redux/reducers/file';
export { notificationsReducer } from 'redux/reducers/notifications'; export { notificationsReducer } from 'redux/reducers/notifications';
export { publishReducer } from 'redux/reducers/publish'; export { publishReducer } from 'redux/reducers/publish';
export { searchReducer } from 'redux/reducers/search'; export { searchReducer } from 'redux/reducers/search';
export { tagsReducerBuilder } from 'redux/reducers/tags'; export { tagsReducer } from 'redux/reducers/tags';
export { walletReducer } from 'redux/reducers/wallet'; export { walletReducer } from 'redux/reducers/wallet';
// selectors // selectors

View file

@ -1,55 +1,70 @@
// @flow // @flow
import * as ACTIONS from 'constants/action_types'; import * as ACTIONS from 'constants/action_types';
import { handleActions } from 'util/redux-utils'; import { handleActions } from 'util/redux-utils';
import { DEFAULT_KNOWN_TAGS, DEFAULT_FOLLOWED_TAGS } from 'constants/tags';
export const tagsReducerBuilder = (defaultState: TagState) => function getDefaultKnownTags() {
handleActions( return DEFAULT_FOLLOWED_TAGS.concat(DEFAULT_KNOWN_TAGS).reduce(
{ (tagsMap, tag) => ({
[ACTIONS.TOGGLE_TAG_FOLLOW]: (state: TagState, action: TagAction): TagState => { ...tagsMap,
const { followedTags } = state; [tag]: { name: tag },
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: 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
);

View file

@ -1,9 +1,7 @@
// @flow // @flow
import { MATURE_TAGS } from 'constants/tags';
const naughtyTags = ['porn', 'nsfw', 'mature', 'xxx'].reduce( const matureTagMap = MATURE_TAGS.reduce((acc, tag) => ({ ...acc, [tag]: true }), {});
(acc, tag) => ({ ...acc, [tag]: true }),
{}
);
export const isClaimNsfw = (claim: Claim): boolean => { export const isClaimNsfw = (claim: Claim): boolean => {
if (!claim) { if (!claim) {
@ -17,7 +15,7 @@ export const isClaimNsfw = (claim: Claim): boolean => {
const tags = claim.value.tags || []; const tags = claim.value.tags || [];
for (let i = 0; i < tags.length; i += 1) { for (let i = 0; i < tags.length; i += 1) {
const tag = tags[i].toLowerCase(); const tag = tags[i].toLowerCase();
if (naughtyTags[tag]) { if (matureTagMap[tag]) {
return true; return true;
} }
} }