Example #1
0
/**
 * Tracks mappings between queries --> num results
 *
 * A of query counts to results, keyed by query key.
 * The query key is supplied by the action, making it opaque to the reducer.
 * Here is what the state tree may look like:
 * feedSearches: {
		total: {
			'wordpress tavern-X': 4,
			'thingsldkjflskjfsdf-A': 0,
			'chickens-A': 4000,
			...
		},
	}
 *
 * @param  {Array}  state  Current state
 * @param  {Object} action Action payload
 * @return {Array}         Updated state
 */
export const total = keyedReducer(
	'queryKey',
	createReducer( null, {
		[ READER_FEED_SEARCH_RECEIVE ]: ( state, action ) => action.payload.total,
	} )
);

export default combineReducers( {
	items,
	total,
} );
Example #2
0
							displayOnNextPage: false,
						};
					}

					memo[ noticeId ] = nextNotice;
					return memo;
				},
				{}
			);
		},
	}
);

export const lastTimeShown = createReducer(
	{},
	{
		[ NOTICE_CREATE ]: ( state, action ) => {
			const { notice } = action;
			return {
				...state,
				[ notice.noticeId ]: Date.now(),
			};
		},
	}
);

export default combineReducers( {
	items,
	lastTimeShown,
} );
Example #3
0
	USER_PROFILE_LINKS_RESET_ERRORS,
} from 'state/action-types';

export const items = createReducer( null, {
	[ USER_PROFILE_LINKS_RECEIVE ]: ( state, { profileLinks } ) => profileLinks,
	[ USER_PROFILE_LINKS_DELETE_SUCCESS ]: ( state, { linkSlug } ) =>
		reject( state, { link_slug: linkSlug } ),
} );

export const errors = createReducer(
	{},
	{
		[ USER_PROFILE_LINKS_ADD_SUCCESS ]: () => ( {} ),
		[ USER_PROFILE_LINKS_ADD_DUPLICATE ]: ( state, { profileLinks } ) => ( {
			duplicate: profileLinks,
		} ),
		[ USER_PROFILE_LINKS_ADD_MALFORMED ]: ( state, { profileLinks } ) => ( {
			malformed: profileLinks,
		} ),
		[ USER_PROFILE_LINKS_ADD_FAILURE ]: ( state, { error } ) => ( { error } ),
		[ USER_PROFILE_LINKS_DELETE_SUCCESS ]: () => ( {} ),
		[ USER_PROFILE_LINKS_DELETE_FAILURE ]: ( state, { error } ) => ( { error } ),
		[ USER_PROFILE_LINKS_RESET_ERRORS ]: () => ( {} ),
	}
);

export default combineReducers( {
	items,
	errors,
} );
Example #4
0
	{
		[ PUBLICIZE_CONNECTIONS_RECEIVE ]: ( state, action ) => ( {
			...omitBy( state, { site_ID: action.siteId } ),
			...keyBy( action.data.connections, 'ID' ),
		} ),
		[ PUBLICIZE_CONNECTION_CREATE ]: ( state, { connection } ) => ( {
			...state,
			[ connection.ID ]: connection,
		} ),
		[ PUBLICIZE_CONNECTION_DELETE ]: ( state, { connection: { ID } } ) => omit( state, ID ),
		[ PUBLICIZE_CONNECTION_RECEIVE ]: ( state, { connection } ) => ( {
			...state,
			[ connection.ID ]: connection,
		} ),
		[ PUBLICIZE_CONNECTION_UPDATE ]: ( state, { connection } ) => ( {
			...state,
			[ connection.ID ]: connection,
		} ),
	},
	connectionsSchema
);

export default combineReducers( {
	fetchingConnection,
	fetchingConnections,
	fetchedConnections,
	connections,
	sharePostStatus,
	sharePostActions,
} );
Example #5
0
/**
 * Tracks the total number of pages of orders for the current site.
 *
 * @param  {Object} state  Current state
 * @param  {Object} action Action payload
 * @return {Object}        Updated state
 */
export function total( state = 1, action ) {
	switch ( action.type ) {
		case WOOCOMMERCE_ORDERS_REQUEST_SUCCESS:
			const query = getSerializedOrdersQuery( omit( action.query, 'page' ) );
			return Object.assign( {}, state, { [ query ]: action.total } );
		default:
			return state;
	}
}

export default combineReducers( {
	invoice,
	isDeleting,
	isQueryLoading,
	isLoading,
	isUpdating,
	items,
	queries,
	refunds,
	total,
	notes,
} );
Example #6
0
} );

/**
 * `Reducer` function which handles request/response actions
 * concerning Jetpack settings save requests
 *
 * @param  {Object} state  Current state
 * @param  {Object} action Action payload
 * @return {Object}        Updated state
 */
export const saveRequests = createReducer( {}, {
	[ JETPACK_SETTINGS_UPDATE ]: ( state, { siteId } ) => ( {
		...state,
		[ siteId ]: { saving: true, status: 'pending', error: false }
	} ),
	[ JETPACK_SETTINGS_UPDATE_SUCCESS ]: ( state, { siteId } ) => ( {
		...state,
		[ siteId ]: { saving: false, status: 'success', error: false }
	} ),
	[ JETPACK_SETTINGS_UPDATE_FAILURE ]: ( state, { siteId, error } ) => ( {
		...state,
		[ siteId ]: { saving: false, status: 'error', error }
	} )
} );

export const reducer = combineReducers( {
	items,
	requests,
	saveRequests
} );
Example #7
0
			[ siteId ]: {
				...state[ siteId ],
				[ taxonomy ]: nextManager
			}
		};
	},
	[ SERIALIZE ]: ( state ) => {
		return mapValues( state, ( taxonomies ) => {
			return mapValues( taxonomies, ( { data, options } ) => {
				return { data, options };
			} );
		} );
	},
	[ DESERIALIZE ]: ( state ) => {
		if ( ! isValidStateWithSchema( state, queriesSchema ) ) {
			return {};
		}

		return mapValues( state, ( taxonomies ) => {
			return mapValues( taxonomies, ( { data, options } ) => {
				return new TermQueryManager( data, options );
			} );
		} );
	}
} );

export default combineReducers( {
	queries,
	queryRequests
} );
Example #8
0
/** @format */

/**
 * Internal dependencies
 */

import designType from './design-type/reducer';
import siteTitle from './site-title/reducer';
import siteGoals from './site-goals/reducer';
import userExperience from './user-experience/reducer';
import { combineReducers } from 'state/utils';
import survey from './survey/reducer';

export default combineReducers( {
	designType,
	siteTitle,
	siteGoals,
	userExperience,
	survey,
} );
Example #9
0
		return Object.assign( {}, state, { [ query ]: action.total } );
	}

	return state;
}

/**
 * Tracks the total number of pages for the current query.
 *
 * @param  {Object} state  Current state
 * @param  {Object} action Action payload
 * @return {Object}        Updated state
 */
export function totalPages( state = {}, action ) {
	if ( WOOCOMMERCE_PRODUCT_CATEGORIES_REQUEST_SUCCESS === action.type && action.data ) {
		const query = getSerializedProductCategoriesQuery( omit( action.query, 'page' ) );
		return Object.assign( {}, state, { [ query ]: action.totalPages } );
	}

	return state;
}

export default combineReducers( {
	isQueryLoading,
	isQueryError,
	items,
	queries,
	total,
	totalPages,
} );
Example #10
0
import { combineReducers } from 'state/utils';
import {
	GOOGLE_APPS_USERS_FETCH,
	GOOGLE_APPS_USERS_FETCH_COMPLETED,
	GOOGLE_APPS_USERS_FETCH_FAILED,
} from 'state/action-types';

export function items( state = [], action ) {
	switch ( action.type ) {
		case GOOGLE_APPS_USERS_FETCH_COMPLETED:
			return uniqBy( state.concat( action.items ), 'email' );
	}
	return state;
}

export function loaded( state = false, action ) {
	switch ( action.type ) {
		case GOOGLE_APPS_USERS_FETCH:
			return false;
		case GOOGLE_APPS_USERS_FETCH_FAILED:
		case GOOGLE_APPS_USERS_FETCH_COMPLETED:
			return true;
	}
	return state;
}

export default combineReducers( {
	items,
	loaded,
} );
Example #11
0
 * @param  {Object} action Action payload
 * @return {Object}        Updated state
 */
export function errors( state = {}, action ) {
	const serializedQuery = action.queryObject && getSerializedDomainsSuggestionsQuery( action.queryObject );
	switch ( action.type ) {
		case DOMAINS_SUGGESTIONS_REQUEST:
		case DOMAINS_SUGGESTIONS_REQUEST_SUCCESS:
			if ( serializedQuery ) {
				return Object.assign( {}, state, {
					[ serializedQuery ]: null
				} );
			}
			return state;
		case DOMAINS_SUGGESTIONS_REQUEST_FAILURE:
			if ( serializedQuery ) {
				return Object.assign( {}, state, {
					[ serializedQuery ]: action.error
				} );
			}
			return state;
	}
	return state;
}

export default combineReducers( {
	items,
	requesting,
	errors
} );
Example #12
0
 * concerning stored card deletion
 *
 * @param {Object} state - current state
 * @param {Object} action - storedCard action
 * @return {Object} updated state
 */
export const isDeleting = ( state = {}, action ) => {
	switch ( action.type ) {
		case STORED_CARDS_DELETE:
			return {
				...state,
				[ action.card.stored_details_id ]: true,
			};

		case STORED_CARDS_DELETE_FAILED:
		case STORED_CARDS_DELETE_COMPLETED:
			const nextState = { ...state };
			delete nextState[ action.card.stored_details_id ];
			return nextState;
	}

	return state;
};

export default combineReducers( {
	hasLoadedFromServer,
	isDeleting,
	isFetching,
	items,
} );
Example #13
0
import feeds from './feeds/reducer';
import feedSearches from './feed-searches/reducer';
import follows from './follows/reducer';
import lists from './lists/reducer';
import posts from './posts/reducer';
import recommendedSites from './recommended-sites/reducer';
import relatedPosts from './related-posts/reducer';
import siteBlocks from './site-blocks/reducer';
import sites from './sites/reducer';
import streams from './streams/reducer';
import tags from './tags/reducer';
import teams from './teams/reducer';
import thumbnails from './thumbnails/reducer';

export default combineReducers( {
	conversations,
	feeds,
	feedSearches,
	follows,
	lists,
	posts,
	recommendedSites,
	relatedPosts,
	siteBlocks,
	sites,
	streams,
	tags,
	teams,
	thumbnails,
} );
Example #14
0
export const rawOffsets = createReducer(
	{},
	{
		[ TIMEZONES_RECEIVE ]: ( state, actions ) => actions.rawOffsets,
	},
	rawOffsetsSchema
);

export const labels = createReducer(
	{},
	{
		[ TIMEZONES_RECEIVE ]: ( state, actions ) => actions.labels,
	},
	labelsSchema
);

export const byContinents = createReducer(
	{},
	{
		[ TIMEZONES_RECEIVE ]: ( state, actions ) => actions.byContinents,
	},
	continentsSchema
);

export default combineReducers( {
	rawOffsets,
	labels,
	byContinents,
} );
Example #15
0
/**
 * Internal dependencies
 */
import {
	COUNTRY_STATES_RECEIVE,
	COUNTRY_STATES_REQUEST,
	COUNTRY_STATES_REQUEST_FAILURE,
	COUNTRY_STATES_REQUEST_SUCCESS,
} from 'state/action-types';
import { combineReducers, createReducer } from 'state/utils';
import { itemSchema } from './schema';

// Stores the complete list of states, indexed by locale key
export const items = createReducer( {}, {
	[ COUNTRY_STATES_RECEIVE ]: ( state, action ) => ( { ...state, [ action.countryCode ]: action.countryStates } ),
}, itemSchema );

// Tracks states list fetching state
export const isFetching = createReducer( {}, {
	[ COUNTRY_STATES_REQUEST ]: ( state, { countryCode } ) => ( { ...state, [ countryCode ]: true } ),
	[ COUNTRY_STATES_REQUEST_SUCCESS ]: ( state, { countryCode } ) => ( { ...state, [ countryCode ]: false } ),
	[ COUNTRY_STATES_REQUEST_FAILURE ]: ( state, { countryCode } ) => ( { ...state, [ countryCode ]: false } )
} );

export default combineReducers( {
	isFetching,
	items,
} );
Example #16
0
/**
 * Internal dependencies
 */
import { combineReducers, keyedReducer } from 'state/utils';
import currency from './currency/reducer';
import methods from './methods/reducer';

const methodsReducer = combineReducers( {
	currency,
	methods,
} );

export default keyedReducer( 'siteId', methodsReducer );
Example #17
0
		...state,
		[ domain ]: { saving: false, status: 'error', error }
	} )
} );

/**
 * Returns the updated items state after an action has been dispatched. The
 * state maps domain to the domain's whoisData object.
 *
 * @param  {Object} state  Current state
 * @param  {Object} action Action payload
 * @return {Object}        Updated state
 */
export const items = createReducer( {}, {
	[ DOMAIN_MANAGEMENT_CONTACT_DETAILS_CACHE_RECEIVE ]: ( state, { data } ) => ( { ...state, _contactDetailsCache: data } ),
	[ DOMAIN_MANAGEMENT_CONTACT_DETAILS_CACHE_UPDATE ]: ( state, { data } ) => {
		return merge( {}, state, { _contactDetailsCache: data } );
	},
	[ DOMAIN_MANAGEMENT_WHOIS_RECEIVE ]: ( state, { domain, whoisData } ) => ( { ...state, [ domain ]: whoisData } ),
	[ DOMAIN_MANAGEMENT_WHOIS_UPDATE ]: ( state, { domain, whoisData } ) => {
		return merge( {}, state, { [ domain ]: { ...state[ domain ], ...whoisData } } );
	},
}, domainWhoisSchema );

export default combineReducers( {
	items,
	isRequestingContactDetailsCache,
	isRequestingWhois,
	isSaving
} );
Example #18
0
/**
 * External dependencies
 */

/**
 * Internal dependencies
 */
import { createReducer, combineReducers } from 'state/utils';
import { ROUTE_SET } from 'state/action-types';

const initial = createReducer(
	'',
	{
		[ ROUTE_SET ]: ( state, { path } ) => ( state === '' ? path : state ),
	},
	{ type: 'string' }
);

const current = createReducer(
	'',
	{
		[ ROUTE_SET ]: ( state, { path } ) => path,
	},
	{ type: 'string' }
);

export default combineReducers( {
	initial,
	current,
} );
Example #19
0
	USER_SETTINGS_UPDATE === type ? { ...state, ...settingValues } : state;

export const unsavedSettings = ( state = {}, action ) => {
	switch ( action.type ) {
		case USER_SETTINGS_UNSAVED_CLEAR:
			// After a successful save, remove the saved settings (either all of them,
			// or a subset) from the `unsavedSettings`.
			if ( ! action.settingNames ) {
				return {};
			}
			return omit( state, action.settingNames );

		case USER_SETTINGS_UNSAVED_SET:
			if ( state[ action.settingName ] === action.value ) {
				return state;
			}
			return { ...state, [ action.settingName ]: action.value };

		case USER_SETTINGS_UNSAVED_REMOVE:
			return omit( state, action.settingName );

		default:
			return state;
	}
};

export default combineReducers( {
	settings,
	unsavedSettings,
} );
Example #20
0
/**
 * Internal dependencies
 */
import { combineReducers, keyedReducer } from 'state/utils';
import edits from './edits-reducer';
import list from './list-reducer';

export default combineReducers( {
	edits: keyedReducer( 'siteId', edits ),
	list,
} );
Example #21
0
		},
		[ PAGE_TEMPLATES_REQUEST_SUCCESS ]: ( state, { siteId } ) => {
			return { ...state, [ siteId ]: false };
		},
	}
);

/**
 * Returns the updated items state after an action has been dispatched. Items
 * state tracks an array of page templates available for a site. Receiving
 * templates for a site will replace the existing set.
 *
 * @param  {Object} state  Current state
 * @param  {Object} action Action object
 * @return {Object}        Updated state
 */
export const items = createReducer(
	{},
	{
		[ PAGE_TEMPLATES_RECEIVE ]: ( state, { siteId, templates } ) => {
			return { ...state, [ siteId ]: templates };
		},
	},
	itemsSchema
);

export default combineReducers( {
	requesting,
	items,
} );
Example #22
0
/** @format */

/**
 * Internal dependencies
 */

import { SIGNUP_OPTIONAL_DEPENDENCY_SUGGESTED_USERNAME_SET } from 'state/action-types';
import { combineReducers, createReducer } from 'state/utils';
import { suggestedUsernameSchema } from './schema';

const suggestedUsername = createReducer(
	'',
	{
		[ SIGNUP_OPTIONAL_DEPENDENCY_SUGGESTED_USERNAME_SET ]: ( state, action ) => {
			return action.data;
		},
	},
	suggestedUsernameSchema
);

export default combineReducers( {
	suggestedUsername,
} );
Example #23
0
/** @format */

/**
 * Internal dependencies
 */
import { createReducer, combineReducers, keyedReducer } from 'state/utils';
import credentialsSchema from './schema';
import {
	JETPACK_CONNECT_AUTHORIZE_RECEIVE,
	JETPACK_ONBOARDING_CREDENTIALS_RECEIVE,
} from 'state/action-types';

const credentialsReducer = keyedReducer(
	'siteId',
	createReducer(
		{},
		{
			[ JETPACK_ONBOARDING_CREDENTIALS_RECEIVE ]: ( state, { credentials } ) => credentials,
			[ JETPACK_CONNECT_AUTHORIZE_RECEIVE ]: () => undefined,
		},
		credentialsSchema
	)
);
credentialsReducer.hasCustomPersistence = true;

export { credentialsReducer as credentials };

export const reducer = combineReducers( {
	credentials: credentialsReducer,
} );
Example #24
0
/** @format */

/**
 * External dependencies
 */

import { combineReducers, keyedReducer } from 'state/utils';

/**
 * Internal dependencies
 */
import edits from './edits/reducer';
import list from './list/reducer';

export default keyedReducer(
	'siteId',
	combineReducers( {
		edits,
		list,
	} )
);
Example #25
0
				[ action.siteId ]: Object.assign(
					{
						isRequesting: false,
						error: false,
						lastSuccessfulStatus,
						errorCounter: 0
					},
					pick( action.data, getExpectedResponseKeys() )
				)
			} );
		case JETPACK_SYNC_STATUS_ERROR:
			const errorCounter = get( state, [ action.siteId, 'errorCounter' ], 0 );
			return Object.assign( {}, state, {
				[ action.siteId ]: Object.assign(
					{
						isRequesting: false,
						error: action.error,
						errorCounter: errorCounter + 1
					},
					pick( action.data, getExpectedResponseKeys() )
				)
			} );
	}
	return state;
}

export default combineReducers( {
	syncStatus,
	fullSyncRequest
} );
Example #26
0
/**
 * Internal dependencies
 */
import {
	NPS_SURVEY_DIALOG_IS_SHOWING,
} from 'state/action-types';
import { combineReducers, createReducer } from 'state/utils';

export const isNpsSurveyDialogShowing = createReducer( false, {
	[ NPS_SURVEY_DIALOG_IS_SHOWING ]: ( state, { isShowing } ) =>
		isShowing !== undefined ? isShowing : state,
} );

export default combineReducers( {
	isNpsSurveyDialogShowing,
} );
Example #27
0
 */
export function deleting( state = {}, action ) {
	switch ( action.type ) {
		case INVITES_DELETE_REQUEST:
			const inviteDeletionRequests = Object.assign(
				{},
				state[ action.siteId ],
				zipObject( action.inviteIds, map( action.inviteIds, () => 'requesting' ) )
			);
			return Object.assign( {}, state, { [ action.siteId ]: inviteDeletionRequests } );
		case INVITES_DELETE_REQUEST_FAILURE:
			const inviteDeletionFailures = Object.assign(
				{},
				state[ action.siteId ],
				zipObject( action.inviteIds, map( action.inviteIds, () => 'failure' ) )
			);
			return Object.assign( {}, state, { [ action.siteId ]: inviteDeletionFailures } );
		case INVITES_DELETE_REQUEST_SUCCESS:
			const inviteDeletionSuccesses = Object.assign(
				{},
				state[ action.siteId ],
				zipObject( action.inviteIds, map( action.inviteIds, () => 'success' ) )
			);
			return Object.assign( {}, state, { [ action.siteId ]: inviteDeletionSuccesses } );
	}

	return state;
}

export default combineReducers( { requesting, items, counts, requestingResend, deleting } );
Example #28
0
		{
			[ PLUGIN_UPLOAD_PROGRESS ]: ( state, { progress } ) => progress,
			[ PLUGIN_UPLOAD ]: () => 0,
			[ PLUGIN_UPLOAD_CLEAR ]: () => 0,
			[ PLUGIN_UPLOAD_ERROR ]: () => 0,
		}
	)
);

export const inProgress = keyedReducer(
	'siteId',
	createReducer(
		{},
		{
			[ PLUGIN_UPLOAD ]: () => true,
			[ PLUGIN_UPLOAD_COMPLETE ]: () => false,
			[ PLUGIN_UPLOAD_ERROR ]: () => false,
			[ PLUGIN_UPLOAD_CLEAR ]: () => false,
			[ AUTOMATED_TRANSFER_INITIATE_WITH_PLUGIN_ZIP ]: () => true,
			[ AUTOMATED_TRANSFER_STATUS_SET ]: ( state, { status } ) => status !== 'complete',
		}
	)
);

export default combineReducers( {
	uploadedPluginId,
	uploadError,
	progressPercent,
	inProgress,
} );
Example #29
0
					return false;
				}

				return ! find( state, { id: message.id } );
			} );
			return sortTimeline(
				state.concat(
					map( messages, message => ( {
						id: message.id,
						source: message.source,
						message: message.text,
						name: message.user.name,
						image: message.user.picture,
						timestamp: maybeUpscaleTimePrecision( message.timestamp ),
						user_id: message.user.id,
						type: get( message, 'type', 'message' ),
						links: get( message, 'meta.links' ),
					} ) )
				)
			);
	}
	return state;
};
timeline.schema = timelineSchema;

export default combineReducers( {
	status,
	timeline,
	lastActivityTimestamp,
} );
Example #30
0
/** @format */

/**
 * Internal dependencies
 */

import orders from './orders/reducer';
import payments from './payments/reducer';
import products from './products/reducer';
import productCategories from './product-categories/reducer';
import promotions from './promotions/reducer';
import reviews from './reviews/reducer';
import reviewReplies from './review-replies/reducer';
import shipping from './shipping/reducer';
import { combineReducers } from 'state/utils';

export default combineReducers( {
	orders,
	payments,
	products,
	productCategories,
	promotions,
	reviews,
	reviewReplies,
	shipping,
} );