/** * Whether or not the current user likes this post * * @param {object} state Global state tree * @param {number} siteId Site ID * @param {number} postId Post ID * @returns {boolean} Is the post liked */ export function isLikedPost( state, siteId, postId ) { return get( state.posts.likes.items, [ siteId, postId, 'iLike' ], false ); }
test('it should handle nested ordering with one ASC and one DESC', async t => { const query = makeQuery(false) const { data, errors } = await run(query) errCheck(t, errors) t.deepEqual( [{ id: 8 }, { id: 7 }, { id: 6 }, { id: 5 }, { id: 4 }], data.user.posts[0].comments ) t.deepEqual([{ id: 1 }, { id: 4 }, { id: 6 }, { id: 8 }], data.user.comments) })
/** * Returns a single post. * * @param {object} state Global state tree * @param {string} postGlobalId Post global ID * @returns {object} Post */ export function getPostById( state, postGlobalId ) { return state.reader.posts.items[ postGlobalId ]; }
// Set posts on page load (only if prop is populated, i.e. running on server) constructor(props) { super(props) this.state = { posts: props.posts || null, error: props.error || null } }
beforeEach( () => { selector = jest.fn( ( [ posts ], siteId ) => Object.values( posts ).filter( ( p ) => p.siteId === siteId ) ); getDependents = jest.fn( ( state ) => [ state.posts ] ); getSitePosts = treeSelect( getDependents, selector ); } );
async getPostTypes (actions) { const { data } = await this.fetch('wp/v2/types', {}, {}) const addCollection = actions.addCollection || actions.addContentType for (const type in data) { const options = data[type] this.restBases.posts[type] = trimStart(options.rest_base, '/') addCollection({ typeName: this.createTypeName(type), route: this.routes[type] }) } }
wpcom.freshlyPressed( function ( err, data ) { if ( err ) throw err; console.log( 'Freshly Pressed Posts:' ); data.posts.forEach( function ( post ) { console.log( ' %s - %s', post.title, post.short_URL ); } ); } );
/** * Returns true if post counts request is in progress, or false otherwise. * * @param {object} state Global state tree * @param {number} siteId Site ID * @param {string} postType Post type * @returns {boolean} Whether request is in progress */ export function isRequestingPostCounts( state, siteId, postType ) { return get( state.posts.counts.requesting, [ siteId, postType ], false ); }
/** * Returns the total of post likes for a given site ID, post ID. * * @param {object} state Global state tree * @param {number} siteId Site ID * @param {number} postId Post ID * @returns {Array} Post Likes */ export function countPostLikes( state, siteId, postId ) { return get( state.posts.likes.items, [ siteId, postId, 'found' ], null ); }
/** * Returns the post likes for a given site ID, post ID. * * @param {object} state Global state tree * @param {number} siteId Site ID * @param {number} postId Post ID * @returns {Array} Post Likes */ export function getPostLikes( state, siteId, postId ) { return get( state.posts.likes.items, [ siteId, postId, 'likes' ], null ); }
test('it should handle nested ordering with both ASC', async t => { const query = makeQuery(true) const { data, errors } = await run(query) errCheck(t, errors) t.deepEqual( [{ id: 4 }, { id: 5 }, { id: 6 }, { id: 7 }, { id: 8 }], data.user.posts[0].comments ) t.deepEqual([{ id: 1 }, { id: 4 }, { id: 6 }, { id: 8 }], data.user.comments) })