Skip to content
This repository has been archived by the owner on Feb 27, 2024. It is now read-only.

Commit

Permalink
jsdocs; rmoved console logs
Browse files Browse the repository at this point in the history
  • Loading branch information
johnrobertmcc authored and gregrickaby committed Mar 2, 2022
1 parent 5977eb9 commit a7f9e01
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 23 deletions.
1 change: 0 additions & 1 deletion functions/wordpress/postTypes/getPostTypeById.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export default async function getPostTypeById(
postTypeQuery[postType] = constructCPTQuery(postType)
}

// console.log('jr postType query', postTypeQuery)
// Fix default ID type for hierarchical posts.
idType = !isHierarchical || 'SLUG' !== idType ? idType : 'URI'

Expand Down
12 changes: 0 additions & 12 deletions functions/wordpress/postTypes/getPostTypeStaticProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export default async function getPostTypeStaticProps(
}
}

// console.log('--------line 37---------------')
/* -- Handle Frontend-only routes. -- */
if (Object.keys(frontendPageSeo).includes(postType)) {
const {apolloClient, ...routeData} = await getFrontendPage(postType)
Expand Down Expand Up @@ -62,7 +61,6 @@ export default async function getPostTypeStaticProps(
}
}

// console.log('--------line 68---------------')
// /* -- Handle dynamic archive display. -- */
if (!Object.keys(params).length) {
const {apolloClient, ...archiveData} = await getPostTypeArchive(postType)
Expand All @@ -78,7 +76,6 @@ export default async function getPostTypeStaticProps(
})
}

// console.log('--------line 81---------------')
/* -- Handle date-based archives. -- */
const year =
Array.isArray(params?.slug) &&
Expand All @@ -98,8 +95,6 @@ export default async function getPostTypeStaticProps(
!isNaN(params?.slug?.[2]) &&
parseInt(params?.slug?.[2], 10)
const isDateArchive = postType === 'page' && (year || month || day)
// console.log('--------line 101---------------')
// console.log('postType', postType)

if (isDateArchive) {
const {apolloClient, ...archiveData} = await getPostsDateArchive(
Expand All @@ -108,9 +103,6 @@ export default async function getPostTypeStaticProps(
month ?? null,
day ?? null
)
// console.log('--------line 110---------------')
// console.log('archiveData', archiveData)
// console.log('sharedProps', sharedProps)

// Merge in query results as Apollo state.
return addApolloState(apolloClient, {
Expand All @@ -125,7 +117,6 @@ export default async function getPostTypeStaticProps(
revalidate
})
}
// console.log('--------line 124---------------')

/* -- Handle individual posts. -- */

Expand Down Expand Up @@ -154,13 +145,11 @@ export default async function getPostTypeStaticProps(
revalidate
})
}
// console.log('--------line 151---------------')

/* -- Handle dynamic posts. -- */

// Get post identifier (ID or slug).
const postId = Number.isInteger(Number(slug)) ? Number(slug) : slug

// Check if preview mode is active and valid for current post (preview and post IDs or slugs match).
const isCurrentPostPreview =
preview &&
Expand All @@ -171,7 +160,6 @@ export default async function getPostTypeStaticProps(

// Check if viewing a draft post.
const isDraft = isCurrentPostPreview && 'draft' === previewData?.post?.status
// console.log('--------line 168---------------')

// Set query variables.
const id = isDraft ? previewData.post.id : slug
Expand Down
2 changes: 0 additions & 2 deletions functions/wordpress/postTypes/processPostTypeQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ export default async function processPostTypeQuery(
}
}

// console.log('preview', preview)

// Execute query.
response.post = await apolloClient
.query({query, variables})
Expand Down
5 changes: 4 additions & 1 deletion lib/wordpress/posts/queryCPTById.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import {gql} from '@apollo/client'
// Query: retrieve post by specified identifier.

/**
* @param postType
* Function used to contruct an Apollo query based on CPT.
*
* @param {string} postType The post type to return.
* @return {string} Returns the Apollo gql query.
*/
export default function constructCPTQuery(postType) {
const queryCPTById = gql`
Expand Down
14 changes: 7 additions & 7 deletions pages/api/preview.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import getPostTypeById from '@/functions/wordpress/postTypes/getPostTypeById'
import {wpPreviewSecret} from '@/lib/wordpress/connector'
import {postTypes} from '@/lib/wordpress/_config/postTypes'

/**
* Provide post preview functionality.
Expand Down Expand Up @@ -41,23 +40,24 @@ export default async function preview(req, res) {
throw new Error(errorMessage)
}

// Set page preview data and enable preview mode.
res.setPreviewData({
const previewData = {
post: {
id: post.databaseId,
slug: post.slug,
status: post.status,
uri: post.uri
uri: post.uri,
postType: postType
}
})
}

const baseRoute = postTypes?.[postType]?.route ?? ''
// Set page preview data and enable preview mode.
res.setPreviewData(previewData)

// Redirect to post dynamic route.
res.redirect(
post.slug && post.uri && post.uri.indexOf('?page_id=') === -1
? post.uri
: `${baseRoute ? `/${baseRoute}` : ''}/${post.databaseId}`
: `../../../preview/${post.databaseId}`
)
} catch (error) {
return res.status(error?.status || 401).json({
Expand Down
105 changes: 105 additions & 0 deletions pages/preview/[...slug].js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import Container from '@/components/atoms/Container'
import RichText from '@/components/atoms/RichText'
import Layout from '@/components/common/Layout'
import Blocks from '@/components/molecules/Blocks'
import Archive from '@/components/organisms/Archive'
import getPagePropTypes from '@/functions/getPagePropTypes'
import getPostTypeStaticPaths from '@/functions/wordpress/postTypes/getPostTypeStaticPaths'
import getPostTypeStaticProps from '@/functions/wordpress/postTypes/getPostTypeStaticProps'
import {PropTypes} from 'prop-types'

/**
* Render the Page component.
*
* @author WebDevStudios
* @param {object} props The component attributes as props.
* @param {boolean} props.archive Whether displaying single post (false) or archive (true).
* @param {boolean} props.dateArchive Whether displaying single post (false) or date-based archive (true).
* @param {string} props.day Date query: day.
* @param {string} props.month Date query: month.
* @param {object} props.pagination Archive pagination data from WordPress.
* @param {object} props.post Post data from WordPress.
* @param {Array} props.posts Array of post data from WordPress.
* @param {string} props.year Date query: year.
* @return {Element} The Page component.
*/
export default function Page({
archive,
dateArchive,
day,
month,
pagination,
post,
posts,
year
}) {
if (archive) {
return (
<Layout seo={{...post?.seo}}>
<Container>
<Archive posts={posts} postType="post" pagination={pagination} />
</Container>
</Layout>
)
} else if (dateArchive) {
return (
<Layout seo={{...post?.seo}}>
<Container>
<RichText tag="h1">{post?.title}</RichText>
<Archive
date={{
day,
month,
year
}}
posts={posts}
postType="post"
pagination={pagination}
/>
</Container>
</Layout>
)
}

return (
<Layout seo={{...post?.seo}}>
<Container>
<article className="innerWrap">
<RichText tag="h1">{post?.title}</RichText>
<Blocks blocks={post?.blocks} />
</article>
</Container>
</Layout>
)
}

/**
* Get post static paths.
*
* @author WebDevStudios
* @return {object} Object consisting of array of paths and fallback setting.
*/
export async function getStaticPaths() {
return await getPostTypeStaticPaths('page')
}

/**
* Get post static props.
*
* @author WebDevStudios
* @param {object} context Context for current post.
* @return {object} Post props.
*/
export async function getStaticProps(context) {
const {params, preview, previewData} = context
const pT = preview ? previewData?.post?.postType : null
return getPostTypeStaticProps(params, pT, preview, previewData)
}

Page.propTypes = {
...getPagePropTypes('page'),
dateArchive: PropTypes.bool,
day: PropTypes.string,
month: PropTypes.string,
year: PropTypes.string
}

0 comments on commit a7f9e01

Please sign in to comment.