Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/mets.corals.io/wp-content/plugins/co-authors-plus/src/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/mets.corals.io/wp-content/plugins/co-authors-plus/src/store.js
/**
 * External dependencies.
 */
import apiFetch from '@wordpress/api-fetch';
import { createReduxStore } from '@wordpress/data';

/**
 * Internal dependencies.
 */
import { formatAuthorData } from './utils';

const DEFAULT_STATE = {
	authors: [],
};

const COAUTHORS_ENDPOINT = '/coauthors/v1/authors';

const actions = {
	setAuthors( authors ) {
		return {
			type: 'SET_AUTHORS',
			authors: [ ...authors ],
		};
	},

	setAuthorsStore( newAuthors ) {
		return {
			type: 'SET_AUTHORS_STORE',
			authors: [ ...newAuthors ],
		};
	},

	apiRequest( path, method = 'GET' ) {
		return {
			type: 'API_REQUEST',
			path,
			method,
		};
	},
};

export const coauthorsStore = createReduxStore( 'cap/authors', {
	reducer( state = DEFAULT_STATE, action ) {
		switch ( action.type ) {
			case 'SET_AUTHORS':
				return {
					...state,
					authors: [ ...state.authors, ...action.authors ],
				};

			case 'SET_AUTHORS_STORE':
				return {
					...state,
					authors: [ ...action.authors ],
				};
		}

		return state;
	},

	actions,

	selectors: {
		getAuthors( state ) {
			const { authors } = state;
			return authors;
		},

		saveAuthors( state ) {
			const { authors } = state;
			return authors;
		},
	},

	controls: {
		API_REQUEST( action ) {
			return apiFetch( { path: action.path, method: action.method } );
		},
	},

	resolvers: {
		*getAuthors( postId ) {
			const path = `${ COAUTHORS_ENDPOINT }/${ postId }`;
			const result = yield actions.apiRequest( path );

			const authors = result.map( ( author ) =>
				formatAuthorData( author )
			);
			return actions.setAuthors( authors );
		},

		*saveAuthors( postId, authors ) {
			const authorsStr = authors
				.map( ( item ) => item.value )
				.join( ',' );
			const path = `${ COAUTHORS_ENDPOINT }/${ postId }?new_authors=${ authorsStr }`;

			yield actions.apiRequest( path, 'POST' );
		},
	},
} );

Spamworldpro Mini