From 04789190b060f27bf0c438a9af449b4a18ef4925 Mon Sep 17 00:00:00 2001 From: jessop Date: Mon, 12 Oct 2020 09:26:31 -0400 Subject: [PATCH] remove tags from redux (to desktop) --- dist/bundle.es.js | 239 ++++++++-------------------------- src/constants/action_types.js | 5 - src/index.js | 10 -- src/redux/actions/tags.js | 24 ---- src/redux/reducers/tags.js | 86 ------------ src/redux/selectors/tags.js | 47 ------- 6 files changed, 53 insertions(+), 358 deletions(-) delete mode 100644 src/redux/actions/tags.js delete mode 100644 src/redux/reducers/tags.js delete mode 100644 src/redux/selectors/tags.js diff --git a/dist/bundle.es.js b/dist/bundle.es.js index 67d88d2..24a503c 100644 --- a/dist/bundle.es.js +++ b/dist/bundle.es.js @@ -287,11 +287,6 @@ const FETCH_COST_INFO_STARTED = 'FETCH_COST_INFO_STARTED'; const FETCH_COST_INFO_COMPLETED = 'FETCH_COST_INFO_COMPLETED'; const FETCH_COST_INFO_FAILED = 'FETCH_COST_INFO_FAILED'; -// Tags -const TOGGLE_TAG_FOLLOW = 'TOGGLE_TAG_FOLLOW'; -const TAG_ADD = 'TAG_ADD'; -const TAG_DELETE = 'TAG_DELETE'; - // Sync const USER_STATE_POPULATE = 'USER_STATE_POPULATE'; @@ -534,9 +529,6 @@ var action_types = /*#__PURE__*/Object.freeze({ FETCH_COST_INFO_STARTED: FETCH_COST_INFO_STARTED, FETCH_COST_INFO_COMPLETED: FETCH_COST_INFO_COMPLETED, FETCH_COST_INFO_FAILED: FETCH_COST_INFO_FAILED, - TOGGLE_TAG_FOLLOW: TOGGLE_TAG_FOLLOW, - TAG_ADD: TAG_ADD, - TAG_DELETE: TAG_DELETE, USER_STATE_POPULATE: USER_STATE_POPULATE }); @@ -4634,29 +4626,6 @@ function savePosition(claimId, outpoint, position) { // -const doToggleTagFollow = name => ({ - type: TOGGLE_TAG_FOLLOW, - data: { - name - } -}); - -const doAddTag = name => ({ - type: TAG_ADD, - data: { - name - } -}); - -const doDeleteTag = name => ({ - type: TAG_DELETE, - data: { - name - } -}); - -// - function parseQueryParams(queryString) { if (queryString === '') return {}; const parts = queryString.split('?').pop().split('&').map(p => p.split('=')); @@ -5707,73 +5676,6 @@ const publishReducer = 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; }; -function getDefaultKnownTags() { - return DEFAULT_FOLLOWED_TAGS.concat(DEFAULT_KNOWN_TAGS).reduce((tagsMap, tag) => _extends$d({}, tagsMap, { - [tag]: { name: tag } - }), {}); -} - -const defaultState$5 = { - followedTags: [], - knownTags: getDefaultKnownTags() -}; - -const tagsReducer = handleActions({ - [TOGGLE_TAG_FOLLOW]: (state, action) => { - 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 _extends$d({}, state, { - followedTags: newFollowedTags - }); - }, - - [TAG_ADD]: (state, action) => { - const { knownTags } = state; - const { name } = action.data; - - let newKnownTags = _extends$d({}, knownTags); - newKnownTags[name] = { name }; - - return _extends$d({}, state, { - knownTags: newKnownTags - }); - }, - - [TAG_DELETE]: (state, action) => { - const { knownTags, followedTags } = state; - const { name } = action.data; - - let newKnownTags = _extends$d({}, knownTags); - delete newKnownTags[name]; - const newFollowedTags = followedTags.filter(tag => tag !== name); - - return _extends$d({}, state, { - knownTags: newKnownTags, - followedTags: newFollowedTags - }); - }, - [USER_STATE_POPULATE]: (state, action) => { - const { tags } = action.data; - if (Array.isArray(tags)) { - return _extends$d({}, state, { - followedTags: tags - }); - } - return _extends$d({}, state); - } -}, defaultState$5); - -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; }; - const buildDraftTransaction = () => ({ amount: undefined, address: undefined @@ -5783,7 +5685,7 @@ const buildDraftTransaction = () => ({ // See details in https://github.com/lbryio/lbry/issues/1307 -const defaultState$6 = { +const defaultState$5 = { balance: undefined, totalBalance: undefined, reservedBalance: undefined, @@ -5824,40 +5726,40 @@ const defaultState$6 = { }; const walletReducer = handleActions({ - [FETCH_TRANSACTIONS_STARTED]: state => _extends$e({}, state, { + [FETCH_TRANSACTIONS_STARTED]: state => _extends$d({}, state, { fetchingTransactions: true }), [FETCH_TRANSACTIONS_COMPLETED]: (state, action) => { - const byId = _extends$e({}, state.transactions); + const byId = _extends$d({}, state.transactions); const { transactions } = action.data; transactions.forEach(transaction => { byId[transaction.txid] = transaction; }); - return _extends$e({}, state, { + return _extends$d({}, state, { transactions: byId, fetchingTransactions: false }); }, [FETCH_TXO_PAGE_STARTED]: state => { - return _extends$e({}, state, { + return _extends$d({}, state, { fetchingTxos: true, fetchingTxosError: undefined }); }, [FETCH_TXO_PAGE_COMPLETED]: (state, action) => { - return _extends$e({}, state, { + return _extends$d({}, state, { txoPage: action.data, fetchingTxos: false }); }, [FETCH_TXO_PAGE_FAILED]: (state, action) => { - return _extends$e({}, state, { + return _extends$d({}, state, { txoPage: {}, fetchingTxos: false, fetchingTxosError: action.data @@ -5865,12 +5767,12 @@ const walletReducer = handleActions({ }, [UPDATE_TXO_FETCH_PARAMS]: (state, action) => { - return _extends$e({}, state, { + return _extends$d({}, state, { txoFetchParams: action.data }); }, - [FETCH_SUPPORTS_STARTED]: state => _extends$e({}, state, { + [FETCH_SUPPORTS_STARTED]: state => _extends$d({}, state, { fetchingSupports: true }), @@ -5883,7 +5785,7 @@ const walletReducer = handleActions({ byOutpoint[`${txid}:${nout}`] = transaction; }); - return _extends$e({}, state, { supports: byOutpoint, fetchingSupports: false }); + return _extends$d({}, state, { supports: byOutpoint, fetchingSupports: false }); }, [ABANDON_SUPPORT_STARTED]: (state, action) => { @@ -5892,7 +5794,7 @@ const walletReducer = handleActions({ currentlyAbandoning[outpoint] = true; - return _extends$e({}, state, { + return _extends$d({}, state, { abandoningSupportsByOutpoint: currentlyAbandoning }); }, @@ -5905,20 +5807,20 @@ const walletReducer = handleActions({ delete currentlyAbandoning[outpoint]; delete byOutpoint[outpoint]; - return _extends$e({}, state, { + return _extends$d({}, state, { supports: byOutpoint, abandoningSupportsById: currentlyAbandoning }); }, [ABANDON_CLAIM_SUPPORT_STARTED]: (state, action) => { - return _extends$e({}, state, { + return _extends$d({}, state, { abandonClaimSupportError: undefined }); }, [ABANDON_CLAIM_SUPPORT_PREVIEW]: (state, action) => { - return _extends$e({}, state, { + return _extends$d({}, state, { abandonClaimSupportError: undefined }); }, @@ -5929,36 +5831,36 @@ const walletReducer = handleActions({ pendingtxs[claimId] = { txid, type, effective }; - return _extends$e({}, state, { + return _extends$d({}, state, { pendingSupportTransactions: pendingtxs, abandonClaimSupportError: undefined }); }, [ABANDON_CLAIM_SUPPORT_FAILED]: (state, action) => { - return _extends$e({}, state, { + return _extends$d({}, state, { abandonClaimSupportError: action.data }); }, [PENDING_SUPPORTS_UPDATED]: (state, action) => { - return _extends$e({}, state, { + return _extends$d({}, state, { pendingSupportTransactions: action.data }); }, - [GET_NEW_ADDRESS_STARTED]: state => _extends$e({}, state, { + [GET_NEW_ADDRESS_STARTED]: state => _extends$d({}, state, { gettingNewAddress: true }), [GET_NEW_ADDRESS_COMPLETED]: (state, action) => { const { address } = action.data; - return _extends$e({}, state, { gettingNewAddress: false, receiveAddress: address }); + return _extends$d({}, state, { gettingNewAddress: false, receiveAddress: address }); }, - [UPDATE_BALANCE]: (state, action) => _extends$e({}, state, { + [UPDATE_BALANCE]: (state, action) => _extends$d({}, state, { totalBalance: action.data.totalBalance, balance: action.data.balance, reservedBalance: action.data.reservedBalance, @@ -5967,32 +5869,32 @@ const walletReducer = handleActions({ tipsBalance: action.data.tipsBalance }), - [CHECK_ADDRESS_IS_MINE_STARTED]: state => _extends$e({}, state, { + [CHECK_ADDRESS_IS_MINE_STARTED]: state => _extends$d({}, state, { checkingAddressOwnership: true }), - [CHECK_ADDRESS_IS_MINE_COMPLETED]: state => _extends$e({}, state, { + [CHECK_ADDRESS_IS_MINE_COMPLETED]: state => _extends$d({}, state, { checkingAddressOwnership: false }), [SET_DRAFT_TRANSACTION_AMOUNT]: (state, action) => { const oldDraft = state.draftTransaction; - const newDraft = _extends$e({}, oldDraft, { amount: parseFloat(action.data.amount) }); + const newDraft = _extends$d({}, oldDraft, { amount: parseFloat(action.data.amount) }); - return _extends$e({}, state, { draftTransaction: newDraft }); + return _extends$d({}, state, { draftTransaction: newDraft }); }, [SET_DRAFT_TRANSACTION_ADDRESS]: (state, action) => { const oldDraft = state.draftTransaction; - const newDraft = _extends$e({}, oldDraft, { address: action.data.address }); + const newDraft = _extends$d({}, oldDraft, { address: action.data.address }); - return _extends$e({}, state, { draftTransaction: newDraft }); + return _extends$d({}, state, { draftTransaction: newDraft }); }, [SEND_TRANSACTION_STARTED]: state => { - const newDraftTransaction = _extends$e({}, state.draftTransaction, { sending: true }); + const newDraftTransaction = _extends$d({}, state.draftTransaction, { sending: true }); - return _extends$e({}, state, { draftTransaction: newDraftTransaction }); + return _extends$d({}, state, { draftTransaction: newDraftTransaction }); }, [SEND_TRANSACTION_COMPLETED]: state => Object.assign({}, state, { @@ -6005,117 +5907,117 @@ const walletReducer = handleActions({ error: action.data.error }); - return _extends$e({}, state, { draftTransaction: newDraftTransaction }); + return _extends$d({}, state, { draftTransaction: newDraftTransaction }); }, - [SUPPORT_TRANSACTION_STARTED]: state => _extends$e({}, state, { + [SUPPORT_TRANSACTION_STARTED]: state => _extends$d({}, state, { sendingSupport: true }), - [SUPPORT_TRANSACTION_COMPLETED]: state => _extends$e({}, state, { + [SUPPORT_TRANSACTION_COMPLETED]: state => _extends$d({}, state, { sendingSupport: false }), - [SUPPORT_TRANSACTION_FAILED]: (state, action) => _extends$e({}, state, { + [SUPPORT_TRANSACTION_FAILED]: (state, action) => _extends$d({}, state, { error: action.data.error, sendingSupport: false }), - [CLEAR_SUPPORT_TRANSACTION]: state => _extends$e({}, state, { + [CLEAR_SUPPORT_TRANSACTION]: state => _extends$d({}, state, { sendingSupport: false }), - [WALLET_STATUS_COMPLETED]: (state, action) => _extends$e({}, state, { + [WALLET_STATUS_COMPLETED]: (state, action) => _extends$d({}, state, { walletIsEncrypted: action.result }), - [WALLET_ENCRYPT_START]: state => _extends$e({}, state, { + [WALLET_ENCRYPT_START]: state => _extends$d({}, state, { walletEncryptPending: true, walletEncryptSucceded: null, walletEncryptResult: null }), - [WALLET_ENCRYPT_COMPLETED]: (state, action) => _extends$e({}, state, { + [WALLET_ENCRYPT_COMPLETED]: (state, action) => _extends$d({}, state, { walletEncryptPending: false, walletEncryptSucceded: true, walletEncryptResult: action.result }), - [WALLET_ENCRYPT_FAILED]: (state, action) => _extends$e({}, state, { + [WALLET_ENCRYPT_FAILED]: (state, action) => _extends$d({}, state, { walletEncryptPending: false, walletEncryptSucceded: false, walletEncryptResult: action.result }), - [WALLET_DECRYPT_START]: state => _extends$e({}, state, { + [WALLET_DECRYPT_START]: state => _extends$d({}, state, { walletDecryptPending: true, walletDecryptSucceded: null, walletDecryptResult: null }), - [WALLET_DECRYPT_COMPLETED]: (state, action) => _extends$e({}, state, { + [WALLET_DECRYPT_COMPLETED]: (state, action) => _extends$d({}, state, { walletDecryptPending: false, walletDecryptSucceded: true, walletDecryptResult: action.result }), - [WALLET_DECRYPT_FAILED]: (state, action) => _extends$e({}, state, { + [WALLET_DECRYPT_FAILED]: (state, action) => _extends$d({}, state, { walletDecryptPending: false, walletDecryptSucceded: false, walletDecryptResult: action.result }), - [WALLET_UNLOCK_START]: state => _extends$e({}, state, { + [WALLET_UNLOCK_START]: state => _extends$d({}, state, { walletUnlockPending: true, walletUnlockSucceded: null, walletUnlockResult: null }), - [WALLET_UNLOCK_COMPLETED]: (state, action) => _extends$e({}, state, { + [WALLET_UNLOCK_COMPLETED]: (state, action) => _extends$d({}, state, { walletUnlockPending: false, walletUnlockSucceded: true, walletUnlockResult: action.result }), - [WALLET_UNLOCK_FAILED]: (state, action) => _extends$e({}, state, { + [WALLET_UNLOCK_FAILED]: (state, action) => _extends$d({}, state, { walletUnlockPending: false, walletUnlockSucceded: false, walletUnlockResult: action.result }), - [WALLET_LOCK_START]: state => _extends$e({}, state, { + [WALLET_LOCK_START]: state => _extends$d({}, state, { walletLockPending: false, walletLockSucceded: null, walletLockResult: null }), - [WALLET_LOCK_COMPLETED]: (state, action) => _extends$e({}, state, { + [WALLET_LOCK_COMPLETED]: (state, action) => _extends$d({}, state, { walletLockPending: false, walletLockSucceded: true, walletLockResult: action.result }), - [WALLET_LOCK_FAILED]: (state, action) => _extends$e({}, state, { + [WALLET_LOCK_FAILED]: (state, action) => _extends$d({}, state, { walletLockPending: false, walletLockSucceded: false, walletLockResult: action.result }), - [SET_TRANSACTION_LIST_FILTER]: (state, action) => _extends$e({}, state, { + [SET_TRANSACTION_LIST_FILTER]: (state, action) => _extends$d({}, state, { transactionListFilter: action.data }), - [UPDATE_CURRENT_HEIGHT]: (state, action) => _extends$e({}, state, { + [UPDATE_CURRENT_HEIGHT]: (state, action) => _extends$d({}, state, { latestBlock: action.data }), - [WALLET_RESTART]: state => _extends$e({}, state, { + [WALLET_RESTART]: state => _extends$d({}, state, { walletReconnecting: true }), - [WALLET_RESTART_COMPLETED]: state => _extends$e({}, state, { + [WALLET_RESTART_COMPLETED]: state => _extends$d({}, state, { walletReconnecting: false }) -}, defaultState$6); +}, defaultState$5); // @@ -6130,14 +6032,14 @@ const makeSelectContentPositionForUri = uri => reselect.createSelector(selectSta return state.positions[id] ? state.positions[id][outpoint] : null; }); -var _extends$f = 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; }; const selectState$5 = state => state.notifications || {}; const selectToast = reselect.createSelector(selectState$5, state => { if (state.toasts.length) { const { id, params } = state.toasts[0]; - return _extends$f({ + return _extends$e({ id }, params); } @@ -6156,33 +6058,6 @@ const selectError = reselect.createSelector(selectState$5, state => { return null; }); -// - -const selectState$6 = state => state.tags || {}; - -const selectKnownTagsByName = reselect.createSelector(selectState$6, state => state.knownTags); - -const selectFollowedTagsList = reselect.createSelector(selectState$6, state => state.followedTags.filter(tag => typeof tag === 'string')); - -const selectFollowedTags = reselect.createSelector(selectFollowedTagsList, followedTags => followedTags.map(tag => ({ name: tag.toLowerCase() })).sort((a, b) => a.name.localeCompare(b.name))); - -const selectUnfollowedTags = reselect.createSelector(selectKnownTagsByName, selectFollowedTagsList, (tagsByName, followedTags) => { - const followedTagsSet = new Set(followedTags); - let tagsToReturn = []; - Object.keys(tagsByName).forEach(key => { - if (!followedTagsSet.has(key)) { - const { name } = tagsByName[key]; - tagsToReturn.push({ name: name.toLowerCase() }); - } - }); - - return tagsToReturn; -}); - -const makeSelectIsFollowingTag = tag => reselect.createSelector(selectFollowedTags, followedTags => { - return followedTags.some(followedTag => followedTag.name === tag.toLowerCase()); -}); - exports.ABANDON_STATES = abandon_states; exports.ACTIONS = action_types; exports.CLAIM_VALUES = claim; @@ -6213,7 +6088,6 @@ exports.createNormalizedClaimSearchKey = createNormalizedClaimSearchKey; exports.creditsToString = creditsToString; exports.doAbandonClaim = doAbandonClaim; exports.doAbandonTxo = doAbandonTxo; -exports.doAddTag = doAddTag; exports.doBalanceSubscribe = doBalanceSubscribe; exports.doCheckAddressIsMine = doCheckAddressIsMine; exports.doCheckPendingClaims = doCheckPendingClaims; @@ -6226,7 +6100,6 @@ exports.doClearPurchasedUriSuccess = doClearPurchasedUriSuccess; exports.doClearRepostError = doClearRepostError; exports.doClearSupport = doClearSupport; exports.doCreateChannel = doCreateChannel; -exports.doDeleteTag = doDeleteTag; exports.doDismissError = doDismissError; exports.doDismissToast = doDismissToast; exports.doError = doError; @@ -6260,7 +6133,6 @@ exports.doSetFileListSort = doSetFileListSort; exports.doSetTransactionListFilter = doSetTransactionListFilter; exports.doSupportAbandonForClaim = doSupportAbandonForClaim; exports.doToast = doToast; -exports.doToggleTagFollow = doToggleTagFollow; exports.doUpdateBalance = doUpdateBalance; exports.doUpdateBlockHeight = doUpdateBlockHeight; exports.doUpdateChannel = doUpdateChannel; @@ -6303,7 +6175,6 @@ exports.makeSelectFileNameForUri = makeSelectFileNameForUri; exports.makeSelectFilePartlyDownloaded = makeSelectFilePartlyDownloaded; exports.makeSelectFilteredTransactionsForPage = makeSelectFilteredTransactionsForPage; exports.makeSelectIsAbandoningClaimForUri = makeSelectIsAbandoningClaimForUri; -exports.makeSelectIsFollowingTag = makeSelectIsFollowingTag; exports.makeSelectIsUriResolving = makeSelectIsUriResolving; exports.makeSelectLatestTransactions = makeSelectLatestTransactions; exports.makeSelectLoadingForUri = makeSelectLoadingForUri; @@ -6381,8 +6252,6 @@ exports.selectFileListDownloadedSort = selectFileListDownloadedSort; exports.selectFileListPublishedSort = selectFileListPublishedSort; exports.selectFilteredTransactionCount = selectFilteredTransactionCount; exports.selectFilteredTransactions = selectFilteredTransactions; -exports.selectFollowedTags = selectFollowedTags; -exports.selectFollowedTagsList = selectFollowedTagsList; exports.selectGettingNewAddress = selectGettingNewAddress; exports.selectHasTransactions = selectHasTransactions; exports.selectIsFetchingClaimListMine = selectIsFetchingClaimListMine; @@ -6436,7 +6305,6 @@ exports.selectTxoItemCount = selectTxoItemCount; exports.selectTxoPage = selectTxoPage; exports.selectTxoPageNumber = selectTxoPageNumber; exports.selectTxoPageParams = selectTxoPageParams; -exports.selectUnfollowedTags = selectUnfollowedTags; exports.selectUpdateChannelError = selectUpdateChannelError; exports.selectUpdatingChannel = selectUpdatingChannel; exports.selectUrisLoading = selectUrisLoading; @@ -6451,6 +6319,5 @@ exports.selectWalletState = selectWalletState; exports.selectWalletUnlockPending = selectWalletUnlockPending; exports.selectWalletUnlockResult = selectWalletUnlockResult; exports.selectWalletUnlockSucceeded = selectWalletUnlockSucceeded; -exports.tagsReducer = tagsReducer; exports.toQueryString = toQueryString; exports.walletReducer = walletReducer; diff --git a/src/constants/action_types.js b/src/constants/action_types.js index 74a718f..a8f88d9 100644 --- a/src/constants/action_types.js +++ b/src/constants/action_types.js @@ -266,10 +266,5 @@ export const FETCH_COST_INFO_STARTED = 'FETCH_COST_INFO_STARTED'; export const FETCH_COST_INFO_COMPLETED = 'FETCH_COST_INFO_COMPLETED'; export const FETCH_COST_INFO_FAILED = 'FETCH_COST_INFO_FAILED'; -// Tags -export const TOGGLE_TAG_FOLLOW = 'TOGGLE_TAG_FOLLOW'; -export const TAG_ADD = 'TAG_ADD'; -export const TAG_DELETE = 'TAG_DELETE'; - // Sync export const USER_STATE_POPULATE = 'USER_STATE_POPULATE'; diff --git a/src/index.js b/src/index.js index 5ef85db..67410f2 100644 --- a/src/index.js +++ b/src/index.js @@ -122,8 +122,6 @@ export { doSupportAbandonForClaim, } from 'redux/actions/wallet'; -export { doToggleTagFollow, doAddTag, doDeleteTag } from 'redux/actions/tags'; - export { doPopulateSharedUserState, doPreferenceGet, doPreferenceSet } from 'redux/actions/sync'; // utils @@ -138,7 +136,6 @@ export { contentReducer } from 'redux/reducers/content'; export { fileInfoReducer } from 'redux/reducers/file_info'; export { notificationsReducer } from 'redux/reducers/notifications'; export { publishReducer } from 'redux/reducers/publish'; -export { tagsReducer } from 'redux/reducers/tags'; export { walletReducer } from 'redux/reducers/wallet'; // selectors @@ -314,10 +311,3 @@ export { selectAbandonClaimSupportError, makeSelectPendingAmountByUri, } from 'redux/selectors/wallet'; - -export { - selectFollowedTags, - selectFollowedTagsList, - selectUnfollowedTags, - makeSelectIsFollowingTag, -} from 'redux/selectors/tags'; diff --git a/src/redux/actions/tags.js b/src/redux/actions/tags.js deleted file mode 100644 index cd7568b..0000000 --- a/src/redux/actions/tags.js +++ /dev/null @@ -1,24 +0,0 @@ -// @flow -import * as ACTIONS from 'constants/action_types'; -import Lbry from 'lbry'; - -export const doToggleTagFollow = (name: string) => ({ - type: ACTIONS.TOGGLE_TAG_FOLLOW, - data: { - name, - }, -}); - -export const doAddTag = (name: string) => ({ - type: ACTIONS.TAG_ADD, - data: { - name, - }, -}); - -export const doDeleteTag = (name: string) => ({ - type: ACTIONS.TAG_DELETE, - data: { - name, - }, -}); diff --git a/src/redux/reducers/tags.js b/src/redux/reducers/tags.js deleted file mode 100644 index b465376..0000000 --- a/src/redux/reducers/tags.js +++ /dev/null @@ -1,86 +0,0 @@ -// @flow -import * as ACTIONS from 'constants/action_types'; -import { handleActions } from 'util/redux-utils'; -import { DEFAULT_KNOWN_TAGS, DEFAULT_FOLLOWED_TAGS } from 'constants/tags'; - -function getDefaultKnownTags() { - return DEFAULT_FOLLOWED_TAGS.concat(DEFAULT_KNOWN_TAGS).reduce( - (tagsMap, tag) => ({ - ...tagsMap, - [tag]: { name: tag }, - }), - {} - ); -} - -const defaultState: TagState = { - followedTags: [], - 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, - }; - }, - [ACTIONS.USER_STATE_POPULATE]: ( - state: TagState, - action: { data: { tags: ?Array } } - ) => { - const { tags } = action.data; - if (Array.isArray(tags)) { - return { - ...state, - followedTags: tags, - }; - } - return { - ...state, - }; - - }, - }, - defaultState -); diff --git a/src/redux/selectors/tags.js b/src/redux/selectors/tags.js deleted file mode 100644 index 17f3fd8..0000000 --- a/src/redux/selectors/tags.js +++ /dev/null @@ -1,47 +0,0 @@ -// @flow -import { createSelector } from 'reselect'; - -const selectState = (state: { tags: TagState }) => state.tags || {}; - -export const selectKnownTagsByName = createSelector( - selectState, - (state: TagState): KnownTags => state.knownTags -); - -export const selectFollowedTagsList = createSelector( - selectState, - (state: TagState): Array => state.followedTags.filter(tag => typeof tag === 'string') -); - -export const selectFollowedTags = createSelector( - selectFollowedTagsList, - (followedTags: Array): Array => - followedTags - .map(tag => ({ name: tag.toLowerCase() })) - .sort((a, b) => a.name.localeCompare(b.name)) -); - -export const selectUnfollowedTags = createSelector( - selectKnownTagsByName, - selectFollowedTagsList, - (tagsByName: KnownTags, followedTags: Array): Array => { - const followedTagsSet = new Set(followedTags); - let tagsToReturn = []; - Object.keys(tagsByName).forEach(key => { - if (!followedTagsSet.has(key)) { - const { name } = tagsByName[key]; - tagsToReturn.push({ name: name.toLowerCase() }); - } - }); - - return tagsToReturn; - } -); - -export const makeSelectIsFollowingTag = (tag: string) => - createSelector( - selectFollowedTags, - followedTags => { - return followedTags.some(followedTag => followedTag.name === tag.toLowerCase()); - } - );