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'
};
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;

View file

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

View file

@ -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
);

View file

@ -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;
}
}