33import React from 'react'
44
55import Post from '../components/post'
6+ import { Error } from '../pages/_error'
67import createPage from '../helpers/create-page'
78import { didFailPasswordAuthorization } from '../helpers/post-data'
89
9- const extractPostData = ( { postsData, revisionsData} : Object ) => Object . assign ( { } ,
10- Array . isArray ( postsData ) ? postsData [ 0 ] : postsData ,
11- revisionsData ? revisionsData [ 0 ] : { }
12- )
10+ export const Singular = ( { postData, revisionsData} : Object ) => {
11+ const postWithRevisionData = Object . assign ( { } , postData , revisionsData && revisionsData [ 0 ] )
1312
14- export const Singular = ( props : Object ) => {
15- const postData = extractPostData ( props )
16-
17- if ( ! Object . keys ( postData ) . length || didFailPasswordAuthorization ( postData ) ) {
18- return (
19- < div >
20- < hr />
21- < h2 className = 'center my3' > { "We couldn't find that page." } </ h2 >
22- < hr />
23- </ div >
24- )
13+ if ( ! Object . keys ( postWithRevisionData ) . length || didFailPasswordAuthorization ( postWithRevisionData ) ) {
14+ return < Error />
2515 }
2616
2717 return (
2818 < Post
29- key = { `Post${ postData . id } ` }
30- postData = { postData }
19+ key = { `Post${ postWithRevisionData . id } ` }
20+ postData = { postWithRevisionData }
3121 />
3222 )
3323}
@@ -39,8 +29,9 @@ export default createPage(Singular, {
3929 fullWidth : true ,
4030 maxWidth : 3 ,
4131 propPaths : ( { asPath, query : { p, password, page_id, preview, preview_id, type, slug} } ) => ( {
42- postsData : {
32+ postData : {
4333 authorize : ! ! preview ,
34+ makeSingle : true ,
4435 path : ( p || page_id ) ? `/wp/v2/${ type } s/${ p || page_id } /?_embed` : `/wp/v2/${ type } s?_embed&slug=${ slug } &password=${ password } `
4536 } ,
4637 revisionsData : preview ? {
0 commit comments