From 0d4079f370a103110720500f83595fbdad871456 Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Wed, 20 Mar 2019 14:54:36 +0100 Subject: [PATCH] add action, reducer and selector for saving media position (#120) --- dist/bundle.js | 185 ++++++++++++++++++++++++++++----- src/index.js | 5 + src/redux/actions/content.js | 10 ++ src/redux/reducers/content.js | 26 +++++ src/redux/selectors/content.js | 14 +++ 5 files changed, 214 insertions(+), 26 deletions(-) create mode 100644 src/redux/actions/content.js create mode 100644 src/redux/reducers/content.js create mode 100644 src/redux/selectors/content.js diff --git a/dist/bundle.js b/dist/bundle.js index e477dcc..95d03e0 100644 --- a/dist/bundle.js +++ b/dist/bundle.js @@ -89,8 +89,8 @@ return /******/ (function(modules) { // webpackBootstrap Object.defineProperty(exports, "__esModule", { value: true }); -exports.selectTransactionListFilter = exports.selectWalletUnlockResult = exports.selectWalletUnlockSucceeded = exports.selectWalletUnlockPending = exports.selectWalletDecryptResult = exports.selectWalletDecryptSucceeded = exports.selectWalletDecryptPending = exports.selectWalletEncryptResult = exports.selectWalletEncryptSucceeded = exports.selectWalletEncryptPending = exports.selectWalletState = exports.selectWalletIsEncrypted = exports.selectBlocks = exports.selectDraftTransactionError = exports.selectDraftTransactionAddress = exports.selectDraftTransactionAmount = exports.selectDraftTransaction = exports.selectGettingNewAddress = exports.selectReceiveAddress = exports.selectIsSendingSupport = exports.selectIsFetchingTransactions = exports.selectHasTransactions = exports.selectRecentTransactions = exports.selectTransactionItems = exports.selectTransactionsById = exports.selectBalance = exports.makeSelectBlockDate = exports.makeSelectQueryWithOptions = exports.selectSearchSuggestions = exports.selectSearchBarFocused = exports.selectWunderBarAddress = exports.selectSearchUrisByQuery = exports.selectIsSearching = exports.selectSearchOptions = exports.selectSearchValue = exports.selectSearchQuery = exports.makeSelectSearchUris = exports.selectSearchState = exports.selectActiveHistoryEntry = exports.selectHistoryStack = exports.selectHistoryIndex = exports.selectIsForwardDisabled = exports.selectIsBackDisabled = exports.selectPathAfterAuth = exports.selectPageTitle = exports.selectHeaderLinks = exports.selectCurrentParams = exports.selectCurrentPage = exports.selectCurrentPath = exports.makeSelectCurrentParam = exports.computePageFromPath = exports.selectFileListPublishedSort = exports.selectFileListDownloadedSort = exports.selectSearchDownloadUris = exports.selectTotalDownloadProgress = exports.selectDownloadingFileInfos = exports.selectFileInfosDownloaded = exports.selectUrisLoading = exports.selectDownloadingByOutpoint = exports.selectIsFetchingFileListDownloadedOrPublished = exports.selectIsFetchingFileList = exports.selectFileInfosByOutpoint = exports.makeSelectLoadingForUri = exports.makeSelectDownloadingForUri = exports.makeSelectFileInfoForUri = exports.selectCurrentChannelPage = exports.selectChannelClaimCounts = exports.selectPlayingUri = exports.selectFetchingTrendingUris = exports.selectTrendingUris = exports.selectFetchingFeaturedUris = exports.selectFeaturedUris = exports.selectResolvingUris = exports.selectMyChannelClaims = exports.selectFetchingMyChannels = exports.selectMyClaimsOutpoints = undefined; -exports.selectAllMyClaimsByOutpoint = exports.selectMyClaimsWithoutChannels = exports.selectMyClaims = exports.selectPendingClaims = exports.selectIsFetchingClaimListMine = exports.selectAllFetchingChannelClaims = exports.selectMyActiveClaims = exports.selectAbandoningIds = exports.selectMyClaimsRaw = exports.selectAllClaimsByChannel = exports.selectClaimsByUri = exports.selectClaimsById = exports.selectPendingById = exports.makeSelectClaimsInChannelForCurrentPageState = exports.makeSelectPendingByUri = exports.makeSelectClaimIsPending = exports.makeSelectChannelForClaimUri = exports.makeSelectFirstRecommendedFileForUri = exports.makeSelectRecommendedContentForUri = exports.makeSelectNsfwCountForChannel = exports.makeSelectNsfwCountFromUris = exports.makeSelectTotalPagesForChannel = exports.makeSelectTotalItemsForChannel = exports.makeSelectIsUriResolving = exports.makeSelectContentTypeForUri = exports.makeSelectTitleForUri = exports.makeSelectMetadataForUri = exports.makeSelectClaimsInChannelForPage = exports.makeSelectClaimsInChannelForCurrentPage = exports.makeSelectFetchingChannelClaims = exports.makeSelectClaimIsMine = exports.makeSelectClaimForUri = exports.selectError = exports.selectToast = exports.walletReducer = exports.searchReducer = exports.notificationsReducer = exports.fileInfoReducer = exports.claimsReducer = exports.creditsToString = exports.formatFullPrice = exports.formatCredits = exports.toQueryString = exports.parseQueryParams = exports.batchActions = exports.doUpdateBlockHeight = exports.doSetTransactionListFilter = exports.doWalletStatus = exports.doWalletUnlock = exports.doWalletDecrypt = exports.doWalletEncrypt = exports.doSendTip = exports.doSetDraftTransactionAddress = exports.doSetDraftTransactionAmount = exports.doSendDraftTransaction = exports.doCheckAddressIsMine = exports.doGetNewAddress = exports.doFetchBlock = exports.doFetchTransactions = exports.doBalanceSubscribe = exports.doUpdateBalance = exports.doUpdateSearchOptions = exports.setSearchApi = exports.doBlurSearchInput = exports.doFocusSearchInput = exports.doUpdateSearchQuery = exports.doSearch = exports.doSetFileListSort = exports.doFetchFileInfosAndPublishedClaims = exports.doFileList = exports.doFetchFileInfo = exports.doResolveUri = exports.doResolveUris = exports.doAbandonClaim = exports.doFetchClaimListMine = exports.doFetchClaimCountByChannel = exports.doFetchClaimsByChannel = exports.doDismissError = exports.doError = exports.doDismissToast = exports.doToast = exports.convertToShareLink = exports.isNameValid = exports.isURIClaimable = exports.isURIValid = exports.normalizeURI = exports.buildURI = exports.parseURI = exports.regexAddress = exports.regexInvalidURI = exports.Lbry = exports.PAGES = exports.SORT_OPTIONS = exports.TRANSACTIONS = exports.SETTINGS = exports.SEARCH_OPTIONS = exports.SEARCH_TYPES = exports.THUMBNAIL_STATUSES = exports.ACTIONS = exports.Toast = undefined; +exports.selectTransactionListFilter = exports.selectWalletUnlockResult = exports.selectWalletUnlockSucceeded = exports.selectWalletUnlockPending = exports.selectWalletDecryptResult = exports.selectWalletDecryptSucceeded = exports.selectWalletDecryptPending = exports.selectWalletEncryptResult = exports.selectWalletEncryptSucceeded = exports.selectWalletEncryptPending = exports.selectWalletState = exports.selectWalletIsEncrypted = exports.selectBlocks = exports.selectDraftTransactionError = exports.selectDraftTransactionAddress = exports.selectDraftTransactionAmount = exports.selectDraftTransaction = exports.selectGettingNewAddress = exports.selectReceiveAddress = exports.selectIsSendingSupport = exports.selectIsFetchingTransactions = exports.selectHasTransactions = exports.selectRecentTransactions = exports.selectTransactionItems = exports.selectTransactionsById = exports.selectBalance = exports.makeSelectBlockDate = exports.makeSelectQueryWithOptions = exports.selectSearchSuggestions = exports.selectSearchBarFocused = exports.selectWunderBarAddress = exports.selectSearchUrisByQuery = exports.selectIsSearching = exports.selectSearchOptions = exports.selectSearchValue = exports.selectSearchQuery = exports.makeSelectSearchUris = exports.selectSearchState = exports.selectActiveHistoryEntry = exports.selectHistoryStack = exports.selectHistoryIndex = exports.selectIsForwardDisabled = exports.selectIsBackDisabled = exports.selectPathAfterAuth = exports.selectPageTitle = exports.selectHeaderLinks = exports.selectCurrentParams = exports.selectCurrentPage = exports.selectCurrentPath = exports.makeSelectCurrentParam = exports.computePageFromPath = exports.selectFileListPublishedSort = exports.selectFileListDownloadedSort = exports.selectSearchDownloadUris = exports.selectTotalDownloadProgress = exports.selectDownloadingFileInfos = exports.selectFileInfosDownloaded = exports.selectUrisLoading = exports.selectDownloadingByOutpoint = exports.selectIsFetchingFileListDownloadedOrPublished = exports.selectIsFetchingFileList = exports.selectFileInfosByOutpoint = exports.makeSelectLoadingForUri = exports.makeSelectDownloadingForUri = exports.makeSelectFileInfoForUri = exports.selectCurrentChannelPage = exports.selectChannelClaimCounts = exports.selectPlayingUri = exports.selectFetchingTrendingUris = exports.selectTrendingUris = exports.selectFetchingFeaturedUris = exports.selectFeaturedUris = exports.selectResolvingUris = exports.selectMyChannelClaims = exports.selectFetchingMyChannels = exports.selectMyClaimsOutpoints = exports.selectAllMyClaimsByOutpoint = exports.selectMyClaimsWithoutChannels = exports.selectMyClaims = undefined; +exports.selectPendingClaims = exports.selectIsFetchingClaimListMine = exports.selectAllFetchingChannelClaims = exports.selectMyActiveClaims = exports.selectAbandoningIds = exports.selectMyClaimsRaw = exports.selectAllClaimsByChannel = exports.selectClaimsByUri = exports.selectClaimsById = exports.selectPendingById = exports.makeSelectClaimsInChannelForCurrentPageState = exports.makeSelectPendingByUri = exports.makeSelectClaimIsPending = exports.makeSelectChannelForClaimUri = exports.makeSelectFirstRecommendedFileForUri = exports.makeSelectRecommendedContentForUri = exports.makeSelectNsfwCountForChannel = exports.makeSelectNsfwCountFromUris = exports.makeSelectTotalPagesForChannel = exports.makeSelectTotalItemsForChannel = exports.makeSelectIsUriResolving = exports.makeSelectContentTypeForUri = exports.makeSelectTitleForUri = exports.makeSelectMetadataForUri = exports.makeSelectClaimsInChannelForPage = exports.makeSelectClaimsInChannelForCurrentPage = exports.makeSelectFetchingChannelClaims = exports.makeSelectClaimIsMine = exports.makeSelectClaimForUri = exports.selectError = exports.selectToast = exports.makeSelectContentPositionForUri = exports.contentReducer = exports.walletReducer = exports.searchReducer = exports.notificationsReducer = exports.fileInfoReducer = exports.claimsReducer = exports.creditsToString = exports.formatFullPrice = exports.formatCredits = exports.toQueryString = exports.parseQueryParams = exports.batchActions = exports.doUpdateBlockHeight = exports.doSetTransactionListFilter = exports.doWalletStatus = exports.doWalletUnlock = exports.doWalletDecrypt = exports.doWalletEncrypt = exports.doSendTip = exports.doSetDraftTransactionAddress = exports.doSetDraftTransactionAmount = exports.doSendDraftTransaction = exports.doCheckAddressIsMine = exports.doGetNewAddress = exports.doFetchBlock = exports.doFetchTransactions = exports.doBalanceSubscribe = exports.doUpdateBalance = exports.savePosition = exports.doUpdateSearchOptions = exports.setSearchApi = exports.doBlurSearchInput = exports.doFocusSearchInput = exports.doUpdateSearchQuery = exports.doSearch = exports.doSetFileListSort = exports.doFetchFileInfosAndPublishedClaims = exports.doFileList = exports.doFetchFileInfo = exports.doResolveUri = exports.doResolveUris = exports.doAbandonClaim = exports.doFetchClaimListMine = exports.doFetchClaimCountByChannel = exports.doFetchClaimsByChannel = exports.doDismissError = exports.doError = exports.doDismissToast = exports.doToast = exports.convertToShareLink = exports.isNameValid = exports.isURIClaimable = exports.isURIValid = exports.normalizeURI = exports.buildURI = exports.parseURI = exports.regexAddress = exports.regexInvalidURI = exports.Lbry = exports.PAGES = exports.SORT_OPTIONS = exports.TRANSACTIONS = exports.SETTINGS = exports.SEARCH_OPTIONS = exports.SEARCH_TYPES = exports.THUMBNAIL_STATUSES = exports.ACTIONS = exports.Toast = undefined; var _Notification = __webpack_require__(1); @@ -290,6 +290,15 @@ Object.defineProperty(exports, 'doUpdateSearchOptions', { } }); +var _content = __webpack_require__(29); + +Object.defineProperty(exports, 'savePosition', { + enumerable: true, + get: function get() { + return _content.savePosition; + } +}); + var _wallet = __webpack_require__(19); Object.defineProperty(exports, 'doUpdateBalance', { @@ -434,7 +443,7 @@ Object.defineProperty(exports, 'creditsToString', { } }); -var _claims2 = __webpack_require__(29); +var _claims2 = __webpack_require__(30); Object.defineProperty(exports, 'claimsReducer', { enumerable: true, @@ -443,7 +452,7 @@ Object.defineProperty(exports, 'claimsReducer', { } }); -var _file_info2 = __webpack_require__(30); +var _file_info2 = __webpack_require__(31); Object.defineProperty(exports, 'fileInfoReducer', { enumerable: true, @@ -452,7 +461,7 @@ Object.defineProperty(exports, 'fileInfoReducer', { } }); -var _notifications2 = __webpack_require__(33); +var _notifications2 = __webpack_require__(34); Object.defineProperty(exports, 'notificationsReducer', { enumerable: true, @@ -461,7 +470,7 @@ Object.defineProperty(exports, 'notificationsReducer', { } }); -var _search2 = __webpack_require__(35); +var _search2 = __webpack_require__(36); Object.defineProperty(exports, 'searchReducer', { enumerable: true, @@ -470,7 +479,7 @@ Object.defineProperty(exports, 'searchReducer', { } }); -var _wallet2 = __webpack_require__(36); +var _wallet2 = __webpack_require__(37); Object.defineProperty(exports, 'walletReducer', { enumerable: true, @@ -479,7 +488,25 @@ Object.defineProperty(exports, 'walletReducer', { } }); -var _notifications3 = __webpack_require__(37); +var _content2 = __webpack_require__(38); + +Object.defineProperty(exports, 'contentReducer', { + enumerable: true, + get: function get() { + return _content2.contentReducer; + } +}); + +var _content3 = __webpack_require__(39); + +Object.defineProperty(exports, 'makeSelectContentPositionForUri', { + enumerable: true, + get: function get() { + return _content3.makeSelectContentPositionForUri; + } +}); + +var _notifications3 = __webpack_require__(40); Object.defineProperty(exports, 'selectToast', { enumerable: true, @@ -1155,11 +1182,11 @@ var _action_types = __webpack_require__(2); var ACTIONS = _interopRequireWildcard(_action_types); -var _thumbnail_upload_statuses = __webpack_require__(38); +var _thumbnail_upload_statuses = __webpack_require__(41); var THUMBNAIL_STATUSES = _interopRequireWildcard(_thumbnail_upload_statuses); -var _settings = __webpack_require__(39); +var _settings = __webpack_require__(42); var SETTINGS = _interopRequireWildcard(_settings); @@ -1167,11 +1194,11 @@ var _transaction_types = __webpack_require__(21); var TRANSACTIONS = _interopRequireWildcard(_transaction_types); -var _sort_options = __webpack_require__(31); +var _sort_options = __webpack_require__(32); var SORT_OPTIONS = _interopRequireWildcard(_sort_options); -var _pages = __webpack_require__(32); +var _pages = __webpack_require__(33); var PAGES = _interopRequireWildcard(_pages); @@ -4812,6 +4839,33 @@ function handleFetchResponse(response) { "use strict"; +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.savePosition = savePosition; + +var _action_types = __webpack_require__(2); + +var ACTIONS = _interopRequireWildcard(_action_types); + +function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } + +function savePosition(claimId /*: string*/, outpoint /*: string*/, position /*: number*/) { + return function (dispatch) { + dispatch({ + type: ACTIONS.SET_CONTENT_POSITION, + data: { claimId: claimId, outpoint: outpoint, position: position } + }); + }; +} + +/***/ }), +/* 30 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + Object.defineProperty(exports, "__esModule", { value: true }); @@ -5095,7 +5149,7 @@ function claimsReducer() { } /***/ }), -/* 30 */ +/* 31 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -5113,11 +5167,11 @@ var _action_types = __webpack_require__(2); var ACTIONS = _interopRequireWildcard(_action_types); -var _sort_options = __webpack_require__(31); +var _sort_options = __webpack_require__(32); var SORT_OPTIONS = _interopRequireWildcard(_sort_options); -var _pages = __webpack_require__(32); +var _pages = __webpack_require__(33); var PAGES = _interopRequireWildcard(_pages); @@ -5337,7 +5391,7 @@ function fileInfoReducer() { } /***/ }), -/* 31 */ +/* 32 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -5352,7 +5406,7 @@ var TITLE = exports.TITLE = 'title'; var FILENAME = exports.FILENAME = 'filename'; /***/ }), -/* 32 */ +/* 33 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -5384,7 +5438,7 @@ var HISTORY = exports.HISTORY = 'user_history'; var WALLET = exports.WALLET = 'wallet'; /***/ }), -/* 33 */ +/* 34 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -5403,7 +5457,7 @@ var _action_types = __webpack_require__(2); var ACTIONS = _interopRequireWildcard(_action_types); -var _reduxUtils = __webpack_require__(34); +var _reduxUtils = __webpack_require__(35); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } @@ -5492,7 +5546,7 @@ var notificationsReducer = (0, _reduxUtils.handleActions)((_handleActions = {}, exports.notificationsReducer = notificationsReducer; /***/ }), -/* 34 */ +/* 35 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -5525,7 +5579,7 @@ var handleActions = exports.handleActions = function handleActions(actionMap, de }; /***/ }), -/* 35 */ +/* 36 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -5544,7 +5598,7 @@ var _action_types = __webpack_require__(2); var ACTIONS = _interopRequireWildcard(_action_types); -var _reduxUtils = __webpack_require__(34); +var _reduxUtils = __webpack_require__(35); var _search = __webpack_require__(16); @@ -5630,7 +5684,7 @@ var searchReducer = exports.searchReducer = (0, _reduxUtils.handleActions)((_han }), _handleActions), defaultState); /***/ }), -/* 36 */ +/* 37 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -5973,7 +6027,86 @@ function walletReducer() { } /***/ }), -/* 37 */ +/* 38 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _extends = 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; }; + +exports.contentReducer = contentReducer; + +var _action_types = __webpack_require__(2); + +var ACTIONS = _interopRequireWildcard(_action_types); + +function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } + +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } + +var reducers = {}; +var defaultState = { + positions: {} +}; + +reducers[ACTIONS.SET_CONTENT_POSITION] = function (state, action) { + var _action$data = action.data, + claimId = _action$data.claimId, + outpoint = _action$data.outpoint, + position = _action$data.position; + + return _extends({}, state, { + positions: _extends({}, state.positions, _defineProperty({}, claimId, _extends({}, state.positions[claimId], _defineProperty({}, outpoint, position)))) + }); +}; + +function contentReducer() { + var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultState; + var action = arguments[1]; + + var handler = reducers[action.type]; + if (handler) return handler(state, action); + return state; +} + +/***/ }), +/* 39 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.makeSelectContentPositionForUri = exports.selectState = undefined; + +var _reselect = __webpack_require__(14); + +var _claims = __webpack_require__(12); + +var selectState = exports.selectState = function selectState(state /*: any*/) { + return state.content || {}; +}; + +var makeSelectContentPositionForUri = exports.makeSelectContentPositionForUri = function makeSelectContentPositionForUri(uri /*: string*/) { + return (0, _reselect.createSelector)(selectState, (0, _claims.makeSelectClaimForUri)(uri), function (state, claim) { + if (!claim) { + return null; + } + var outpoint = claim.txid + ':' + claim.nout; + var id = claim.claim_id; + return state.positions[id] ? state.positions[id][outpoint] : null; + }); +}; + +/***/ }), +/* 40 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -6019,7 +6152,7 @@ var selectError = exports.selectError = (0, _reselect.createSelector)(selectStat }); /***/ }), -/* 38 */ +/* 41 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -6035,7 +6168,7 @@ var COMPLETE = exports.COMPLETE = 'complete'; var MANUAL = exports.MANUAL = 'manual'; /***/ }), -/* 39 */ +/* 42 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; diff --git a/src/index.js b/src/index.js index 390100b..18d7237 100644 --- a/src/index.js +++ b/src/index.js @@ -66,6 +66,8 @@ export { doUpdateSearchOptions, } from 'redux/actions/search'; +export { savePosition } from 'redux/actions/content'; + export { doUpdateBalance, doBalanceSubscribe, @@ -96,8 +98,11 @@ export { fileInfoReducer } from 'redux/reducers/file_info'; export { notificationsReducer } from 'redux/reducers/notifications'; export { searchReducer } from 'redux/reducers/search'; export { walletReducer } from 'redux/reducers/wallet'; +export { contentReducer } from 'redux/reducers/content'; // selectors +export { makeSelectContentPositionForUri } from 'redux/selectors/content'; + export { selectToast, selectError } from 'redux/selectors/notifications'; export { diff --git a/src/redux/actions/content.js b/src/redux/actions/content.js new file mode 100644 index 0000000..fff0f11 --- /dev/null +++ b/src/redux/actions/content.js @@ -0,0 +1,10 @@ +import * as ACTIONS from 'constants/action_types'; + +export function savePosition(claimId: string, outpoint: string, position: number) { + return dispatch => { + dispatch({ + type: ACTIONS.SET_CONTENT_POSITION, + data: { claimId, outpoint, position }, + }); + }; +} diff --git a/src/redux/reducers/content.js b/src/redux/reducers/content.js new file mode 100644 index 0000000..b8d9a5f --- /dev/null +++ b/src/redux/reducers/content.js @@ -0,0 +1,26 @@ +import * as ACTIONS from 'constants/action_types'; + +const reducers = {}; +const defaultState = { + positions: {}, +}; + +reducers[ACTIONS.SET_CONTENT_POSITION] = (state, action) => { + const { claimId, outpoint, position } = action.data; + return { + ...state, + positions: { + ...state.positions, + [claimId]: { + ...state.positions[claimId], + [outpoint]: position, + }, + }, + }; +}; + +export function contentReducer(state = defaultState, action) { + const handler = reducers[action.type]; + if (handler) return handler(state, action); + return state; +} diff --git a/src/redux/selectors/content.js b/src/redux/selectors/content.js new file mode 100644 index 0000000..f494fab --- /dev/null +++ b/src/redux/selectors/content.js @@ -0,0 +1,14 @@ +import { createSelector } from 'reselect'; +import { makeSelectClaimForUri } from 'redux/selectors/claims'; + +export const selectState = (state: any) => state.content || {}; + +export const makeSelectContentPositionForUri = (uri: string) => + createSelector(selectState, makeSelectClaimForUri(uri), (state, claim) => { + if (!claim) { + return null; + } + const outpoint = `${claim.txid}:${claim.nout}`; + const id = claim.claim_id; + return state.positions[id] ? state.positions[id][outpoint] : null; + });