update subscriptions reducer to handle USER_STATE_POPULATE action
This commit is contained in:
parent
ebc8122c99
commit
32f8ded652
3 changed files with 105 additions and 5 deletions
35
dist/bundle.es.js
vendored
35
dist/bundle.es.js
vendored
|
@ -632,7 +632,40 @@ var subscriptions = handleActions({
|
||||||
}),
|
}),
|
||||||
[VIEW_SUGGESTED_SUBSCRIPTIONS]: state => ({ ...state,
|
[VIEW_SUGGESTED_SUBSCRIPTIONS]: state => ({ ...state,
|
||||||
showSuggestedSubs: true
|
showSuggestedSubs: true
|
||||||
})
|
}),
|
||||||
|
[lbryRedux.ACTIONS.USER_STATE_POPULATE]: (state, action) => {
|
||||||
|
const {
|
||||||
|
subscriptions
|
||||||
|
} = action.data;
|
||||||
|
let newSubscriptions;
|
||||||
|
|
||||||
|
if (!subscriptions) {
|
||||||
|
newSubscriptions = state.subscriptions;
|
||||||
|
} else {
|
||||||
|
const parsedSubscriptions = subscriptions.map(uri => {
|
||||||
|
const {
|
||||||
|
channelName
|
||||||
|
} = lbryRedux.parseURI(uri);
|
||||||
|
return {
|
||||||
|
uri,
|
||||||
|
channelName: `@${channelName}`
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!state.subscriptions || !state.subscriptions.length) {
|
||||||
|
newSubscriptions = parsedSubscriptions;
|
||||||
|
} else {
|
||||||
|
const map = {};
|
||||||
|
newSubscriptions = parsedSubscriptions.concat(state.subscriptions).filter(sub => {
|
||||||
|
return map[sub.uri] ? false : map[sub.uri] = true;
|
||||||
|
}, {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return { ...state,
|
||||||
|
subscriptions: newSubscriptions
|
||||||
|
};
|
||||||
|
}
|
||||||
}, defaultState);
|
}, defaultState);
|
||||||
|
|
||||||
function swapKeyAndValue(dict) {
|
function swapKeyAndValue(dict) {
|
||||||
|
|
41
dist/bundle.js
vendored
41
dist/bundle.js
vendored
|
@ -1207,8 +1207,10 @@ rewards.setCallback = function (name, method) {
|
||||||
"use strict";
|
"use strict";
|
||||||
__webpack_require__.r(__webpack_exports__);
|
__webpack_require__.r(__webpack_exports__);
|
||||||
/* harmony import */ var constants_action_types__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
|
/* harmony import */ var constants_action_types__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
|
||||||
/* harmony import */ var constants_subscriptions__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(9);
|
/* harmony import */ var lbry_redux__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(3);
|
||||||
/* harmony import */ var util_redux_utils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(10);
|
/* harmony import */ var lbry_redux__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(lbry_redux__WEBPACK_IMPORTED_MODULE_1__);
|
||||||
|
/* harmony import */ var constants_subscriptions__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(9);
|
||||||
|
/* harmony import */ var util_redux_utils__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(10);
|
||||||
var _handleActions;
|
var _handleActions;
|
||||||
|
|
||||||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
|
||||||
|
@ -1218,18 +1220,19 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var defaultState = {
|
var defaultState = {
|
||||||
enabledChannelNotifications: [],
|
enabledChannelNotifications: [],
|
||||||
subscriptions: [],
|
subscriptions: [],
|
||||||
unread: {},
|
unread: {},
|
||||||
suggested: {},
|
suggested: {},
|
||||||
loading: false,
|
loading: false,
|
||||||
viewMode: constants_subscriptions__WEBPACK_IMPORTED_MODULE_1__["VIEW_ALL"],
|
viewMode: constants_subscriptions__WEBPACK_IMPORTED_MODULE_2__["VIEW_ALL"],
|
||||||
loadingSuggested: false,
|
loadingSuggested: false,
|
||||||
firstRunCompleted: false,
|
firstRunCompleted: false,
|
||||||
showSuggestedSubs: false
|
showSuggestedSubs: false
|
||||||
};
|
};
|
||||||
/* harmony default export */ __webpack_exports__["default"] = (Object(util_redux_utils__WEBPACK_IMPORTED_MODULE_2__["handleActions"])((_handleActions = {}, _defineProperty(_handleActions, constants_action_types__WEBPACK_IMPORTED_MODULE_0__["CHANNEL_SUBSCRIBE"], function (state, action) {
|
/* harmony default export */ __webpack_exports__["default"] = (Object(util_redux_utils__WEBPACK_IMPORTED_MODULE_3__["handleActions"])((_handleActions = {}, _defineProperty(_handleActions, constants_action_types__WEBPACK_IMPORTED_MODULE_0__["CHANNEL_SUBSCRIBE"], function (state, action) {
|
||||||
var newSubscription = action.data;
|
var newSubscription = action.data;
|
||||||
var newSubscriptions = state.subscriptions.slice();
|
var newSubscriptions = state.subscriptions.slice();
|
||||||
newSubscriptions.unshift(newSubscription);
|
newSubscriptions.unshift(newSubscription);
|
||||||
|
@ -1354,6 +1357,36 @@ var defaultState = {
|
||||||
return _objectSpread({}, state, {
|
return _objectSpread({}, state, {
|
||||||
showSuggestedSubs: true
|
showSuggestedSubs: true
|
||||||
});
|
});
|
||||||
|
}), _defineProperty(_handleActions, lbry_redux__WEBPACK_IMPORTED_MODULE_1__["ACTIONS"].USER_STATE_POPULATE, function (state, action) {
|
||||||
|
var subscriptions = action.data.subscriptions;
|
||||||
|
var newSubscriptions;
|
||||||
|
|
||||||
|
if (!subscriptions) {
|
||||||
|
newSubscriptions = state.subscriptions;
|
||||||
|
} else {
|
||||||
|
var parsedSubscriptions = subscriptions.map(function (uri) {
|
||||||
|
var _parseURI = Object(lbry_redux__WEBPACK_IMPORTED_MODULE_1__["parseURI"])(uri),
|
||||||
|
channelName = _parseURI.channelName;
|
||||||
|
|
||||||
|
return {
|
||||||
|
uri: uri,
|
||||||
|
channelName: "@".concat(channelName)
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!state.subscriptions || !state.subscriptions.length) {
|
||||||
|
newSubscriptions = parsedSubscriptions;
|
||||||
|
} else {
|
||||||
|
var map = {};
|
||||||
|
newSubscriptions = parsedSubscriptions.concat(state.subscriptions).filter(function (sub) {
|
||||||
|
return map[sub.uri] ? false : map[sub.uri] = true;
|
||||||
|
}, {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return _objectSpread({}, state, {
|
||||||
|
subscriptions: newSubscriptions
|
||||||
|
});
|
||||||
}), _handleActions), defaultState));
|
}), _handleActions), defaultState));
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
// @flow
|
// @flow
|
||||||
import * as ACTIONS from 'constants/action_types';
|
import * as ACTIONS from 'constants/action_types';
|
||||||
|
import { parseURI, ACTIONS as LBRY_REDUX_ACTIONS } from 'lbry-redux';
|
||||||
import { VIEW_ALL } from 'constants/subscriptions';
|
import { VIEW_ALL } from 'constants/subscriptions';
|
||||||
import { handleActions } from 'util/redux-utils';
|
import { handleActions } from 'util/redux-utils';
|
||||||
|
|
||||||
|
@ -194,6 +195,39 @@ export default handleActions(
|
||||||
...state,
|
...state,
|
||||||
showSuggestedSubs: true,
|
showSuggestedSubs: true,
|
||||||
}),
|
}),
|
||||||
|
[LBRY_REDUX_ACTIONS.USER_STATE_POPULATE]: (
|
||||||
|
state: SubscriptionState,
|
||||||
|
action: { data: { subscriptions: ?Array<string> } }
|
||||||
|
) => {
|
||||||
|
const { subscriptions } = action.data;
|
||||||
|
let newSubscriptions;
|
||||||
|
|
||||||
|
if (!subscriptions) {
|
||||||
|
newSubscriptions = state.subscriptions;
|
||||||
|
} else {
|
||||||
|
const parsedSubscriptions = subscriptions.map(uri => {
|
||||||
|
const { channelName } = parseURI(uri);
|
||||||
|
|
||||||
|
return {
|
||||||
|
uri,
|
||||||
|
channelName: `@${channelName}`,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
if (!state.subscriptions || !state.subscriptions.length) {
|
||||||
|
newSubscriptions = parsedSubscriptions;
|
||||||
|
} else {
|
||||||
|
const map = {};
|
||||||
|
newSubscriptions = parsedSubscriptions.concat(state.subscriptions).filter(sub => {
|
||||||
|
return map[sub.uri] ? false : (map[sub.uri] = true);
|
||||||
|
}, {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
subscriptions: newSubscriptions,
|
||||||
|
};
|
||||||
|
},
|
||||||
},
|
},
|
||||||
defaultState
|
defaultState
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue