/
githubmirror
/
wp-calypso
Обзор
Документация
Войти
/
githubmirror
/
wp-calypso
Код
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
trunk
client/state/posts/actions/request-posts.js
48 строк
1 KB
Jarda Snajdr
Remove the wpcom.me() helpers (#102816)
29 апр 2025, 16:12
Не верифицирован
29 апр 2025, 16:12
0a3b909
Код
Авторство
О чём код?
import wpcom from 'calypso/lib/wp'; import { POSTS_REQUEST_FAILURE, POSTS_REQUEST_SUCCESS, POSTS_REQUEST, } from 'calypso/state/action-types'; import { receivePosts } from 'calypso/state/posts/actions/receive-posts'; import 'calypso/state/posts/init'; /** * Triggers a network request to fetch posts for the specified site and query. * @param {?number} siteId Site ID * @param {string} query Post query * @returns {Function} Action thunk */ export function requestPosts( siteId, query = {} ) { return ( dispatch ) => { dispatch( { type: POSTS_REQUEST, siteId, query, } ); const endpoint = siteId ? `/sites/${ siteId }/posts` : '/me/posts'; return wpcom.req .get( endpoint, { ...query } ) .then( ( { found, posts } ) => { dispatch( receivePosts( posts ) ); dispatch( { type: POSTS_REQUEST_SUCCESS, siteId, query, found, posts, } ); } ) .catch( ( error ) => { dispatch( { type: POSTS_REQUEST_FAILURE, siteId, query, error, } ); } ); }; }