File size: 1,034 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
import wpcom from 'calypso/lib/wp';
import type { ViewTable, ViewGrid } from '@wordpress/dataviews';

export type SitesView = ViewTable | ViewGrid;

// The view preferences are a subset of the view object.
// It includes the merged layout object of all view types ever explicitly set by the user.
export type SitesViewPreferences = Partial< Omit< SitesView, 'type' | 'layout' > > & {
	type?: ViewTable[ 'type' ] | ViewGrid[ 'type' ];
	layout?: Partial< ViewTable[ 'layout' ] & ViewGrid[ 'layout' ] >;
};

export interface UserPreferences {
	'sites-view'?: SitesViewPreferences;
	'some-string'?: string;
}

export async function fetchPreferences(): Promise< UserPreferences > {
	const { calypso_preferences } = await wpcom.req.get( '/me/preferences' );
	return calypso_preferences;
}

export async function updatePreferences(
	data: Partial< UserPreferences >
): Promise< UserPreferences > {
	const { calypso_preferences } = await wpcom.req.post( '/me/preferences', {
		calypso_preferences: data,
	} );

	return calypso_preferences;
}