This commit is contained in:
Oleg Silkin 2020-01-13 16:55:28 -05:00
parent 13cd56dabc
commit c0db949a53
7 changed files with 53 additions and 38 deletions

View file

@ -1,10 +1,10 @@
/* /*
* How to use this file: * How to use this file:
* Settings exported from here will trigger the setting to be * Settings exported from here will trigger the setting to be
* sent to the preference middleware when set using the * sent to the preference middleware when set using the
* usual setDaemonSettings and clearDaemonSettings methods. * usual setDaemonSettings and clearDaemonSettings methods.
* *
* See redux/settings/actions in the app for where this is used. * See redux/settings/actions in the app for where this is used.
*/ */
import * as DAEMON_SETTINGS from './daemon_settings'; import * as DAEMON_SETTINGS from './daemon_settings';

View file

@ -1,7 +1,8 @@
// @flow
import * as ACTIONS from 'constants/action_types'; import * as ACTIONS from 'constants/action_types';
export function savePosition(claimId: string, outpoint: string, position: number) { export function savePosition(claimId: string, outpoint: string, position: number) {
return dispatch => { return (dispatch: Dispatch) => {
dispatch({ dispatch({
type: ACTIONS.SET_CONTENT_POSITION, type: ACTIONS.SET_CONTENT_POSITION,
data: { claimId, outpoint, position }, data: { claimId, outpoint, position },

View file

@ -14,7 +14,7 @@ type SharedData = {
function extractUserState(rawObj: SharedData) { function extractUserState(rawObj: SharedData) {
if (rawObj && rawObj.version === '0.1' && rawObj.value) { if (rawObj && rawObj.version === '0.1' && rawObj.value) {
const { subscriptions, tags, blocked, settings} = rawObj.value; const { subscriptions, tags, blocked, settings } = rawObj.value;
return { return {
...(subscriptions ? { subscriptions } : {}), ...(subscriptions ? { subscriptions } : {}),
@ -30,7 +30,10 @@ function extractUserState(rawObj: SharedData) {
export function doPopulateSharedUserState(sharedSettings: any) { export function doPopulateSharedUserState(sharedSettings: any) {
return (dispatch: Dispatch) => { return (dispatch: Dispatch) => {
const { subscriptions, tags, blocked, settings } = extractUserState(sharedSettings); const { subscriptions, tags, blocked, settings } = extractUserState(sharedSettings);
dispatch({ type: ACTIONS.USER_STATE_POPULATE, data: { subscriptions, tags, blocked, settings } }); dispatch({
type: ACTIONS.USER_STATE_POPULATE,
data: { subscriptions, tags, blocked, settings },
});
}; };
} }

View file

@ -33,8 +33,7 @@ export const blockedReducer = handleActions(
const { blocked } = action.data; const { blocked } = action.data;
return { return {
...state, ...state,
blockedChannels: blockedChannels: blocked && blocked.length ? blocked : state.blockedChannels,
blocked && blocked.length ? blocked : state.blockedChannels,
}; };
}, },
}, },

View file

@ -265,7 +265,8 @@ reducers[ACTIONS.FETCH_CHANNEL_CLAIMS_COMPLETED] = (state: State, action: any):
const paginatedClaimsByChannel = Object.assign({}, state.paginatedClaimsByChannel); const paginatedClaimsByChannel = Object.assign({}, state.paginatedClaimsByChannel);
// check if count has changed - that means cached pagination will be wrong, so clear it // check if count has changed - that means cached pagination will be wrong, so clear it
const previousCount = paginatedClaimsByChannel[uri] && paginatedClaimsByChannel[uri]['itemCount']; const previousCount = paginatedClaimsByChannel[uri] && paginatedClaimsByChannel[uri]['itemCount'];
const byChannel = (claimsInChannel === previousCount) ? Object.assign({}, paginatedClaimsByChannel[uri]) : {}; const byChannel =
claimsInChannel === previousCount ? Object.assign({}, paginatedClaimsByChannel[uri]) : {};
const allClaimIds = new Set(byChannel.all); const allClaimIds = new Set(byChannel.all);
const currentPageClaimIds = []; const currentPageClaimIds = [];
const byId = Object.assign({}, state.byId); const byId = Object.assign({}, state.byId);

View file

@ -1,14 +1,19 @@
// @flow
import { createSelector } from 'reselect'; import { createSelector } from 'reselect';
import { makeSelectClaimForUri } from 'redux/selectors/claims'; import { makeSelectClaimForUri } from 'redux/selectors/claims';
export const selectState = (state: any) => state.content || {}; export const selectState = (state: any) => state.content || {};
export const makeSelectContentPositionForUri = (uri: string) => export const makeSelectContentPositionForUri = (uri: string) =>
createSelector(selectState, makeSelectClaimForUri(uri), (state, claim) => { createSelector(
if (!claim) { selectState,
return null; 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;
} }
const outpoint = `${claim.txid}:${claim.nout}`; );
const id = claim.claim_id;
return state.positions[id] ? state.positions[id][outpoint] : null;
});

View file

@ -1,26 +1,32 @@
import { createSelector } from 'reselect'; import { createSelector } from 'reselect';
export const selectState = (state) => state.notifications || {}; export const selectState = state => state.notifications || {};
export const selectToast = createSelector(selectState, (state) => { export const selectToast = createSelector(
if (state.toasts.length) { selectState,
const { id, params } = state.toasts[0]; state => {
return { if (state.toasts.length) {
id, const { id, params } = state.toasts[0];
...params, return {
}; id,
...params,
};
}
return null;
} }
);
return null; export const selectError = createSelector(
}); selectState,
state => {
if (state.errors.length) {
const { error } = state.errors[0];
return {
error,
};
}
export const selectError = createSelector(selectState, (state) => { return null;
if (state.errors.length) {
const { error } = state.errors[0];
return {
error,
};
} }
);
return null;
});