File size: 1,169 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { SELECTED_SITE_SET, MOST_RECENTLY_SELECTED_SITE_SET } from 'calypso/state/action-types';
import 'calypso/state/ui/init';

/**
 * Returns a thunk function that dispatches two actions related to the selected site ID.
 * The dispatched actions have type of MOST_RECENTLY_SELECTED_SITE_SET and SELECTED_SITE_SET where they both pass the new site ID to select.
 * Note that MOST_RECENTLY_SELECTED_SITE_SET is never be null since we can refer to the most recently selected site ID even when no site is selected.
 * @param {number | null} siteId - The ID of the site to be set as selected.
 * @returns {Function} A Redux thunk function.
 */
export const setSelectedSiteId = ( siteId ) => {
	return ( dispatch ) => {
		if ( siteId ) {
			dispatch( {
				type: MOST_RECENTLY_SELECTED_SITE_SET,
				siteId,
			} );
		}

		dispatch( {
			type: SELECTED_SITE_SET,
			siteId,
		} );
	};
};

/**
 * Returns an action object to be used in signalling that all sites have been
 * set as selected.
 * @returns {Object} Action object
 */
export const setAllSitesSelected = () => {
	return ( dispatch ) => {
		dispatch( {
			type: SELECTED_SITE_SET,
			siteId: null,
		} );
	};
};