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

Commit 184b7a9

Browse files
committed
Merge branch 'staging' into develop
2 parents 75b1685 + 36c8a43 commit 184b7a9

File tree

138 files changed

+5853
-529
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

138 files changed

+5853
-529
lines changed

.eslintrc.js

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,46 @@ module.exports = {
1616
'plugin:react/recommended',
1717
'plugin:react-hooks/recommended',
1818
'plugin:jsx-a11y/recommended',
19-
'prettier'
19+
'prettier',
20+
'plugin:jsdoc/recommended'
2021
],
2122
settings: {
2223
react: {
2324
version: 'detect'
25+
},
26+
jsdoc: {
27+
tagNamePreference: {
28+
returns: 'return'
29+
}
2430
}
2531
},
26-
plugins: ['react', 'react-hooks', 'jsx-a11y', 'prettier'],
32+
plugins: ['react', 'react-hooks', 'jsx-a11y', 'prettier', 'jsdoc'],
2733
rules: {
34+
'func-style': ['error', 'declaration'],
35+
'jsdoc/check-indentation': 'warn',
36+
'jsdoc/check-line-alignment': ['warn', 'always'],
37+
'jsdoc/require-param': [
38+
'warn',
39+
{
40+
checkRestProperty: true,
41+
unnamedRootBase: ['props']
42+
}
43+
],
44+
'jsdoc/check-values': [
45+
'warn',
46+
{
47+
allowedAuthors: ['WebDevStudios']
48+
}
49+
],
2850
'jsx-a11y/anchor-is-valid': 'off',
51+
'no-console': ['error', {allow: ['warn', 'error']}],
52+
'prettier/prettier': 'error',
2953
'react/react-in-jsx-scope': 'off',
3054
'react/jsx-filename-extension': [
31-
1,
55+
'warn',
3256
{
3357
extensions: ['.js', '.jsx']
3458
}
35-
],
36-
'prettier/prettier': 'error'
59+
]
3760
}
3861
}

.vscode/extensions.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"recommendations": [
3+
"esbenp.prettier-vscode",
4+
"editorconfig.editorconfig",
5+
"csstools.postcss",
6+
"silvenon.mdx",
7+
"stylelint.vscode-stylelint",
8+
"snipsnapdev.snipsnap-vscode",
9+
"bradlc.vscode-tailwindcss"
10+
]
11+
}

.vscode/settings.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
// Enable format with prettier on save, configure import organizing.
3+
"editor.formatOnSave": true,
4+
"[javascriptreact]": {
5+
"editor.defaultFormatter": "esbenp.prettier-vscode",
6+
"editor.codeActionsOnSave": {
7+
"source.organizeImports": true
8+
}
9+
},
10+
11+
// This will get emmet working in JSX.
12+
"emmet.includeLanguages": {
13+
"javascript": "javascriptreact"
14+
}
15+
}

.vscode/snipsnap.code-snippets

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

api/algolia/connector.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import algoliasearch from 'algoliasearch/lite'
2+
import getEnvVar from '@/functions/getEnvVar'
3+
4+
// Define env vars.
5+
export const algoliaIndexName = getEnvVar('ALGOLIA_INDEX_NAME', true)
6+
export const algoliaSearchKey = process.env.NEXT_PUBLIC_ALGOLIA_SEARCH_ONLY_KEY
7+
export const algoliaAppId = process.env.NEXT_PUBLIC_ALGOLIA_APPLICATION_ID
8+
9+
const algoliaClient = algoliasearch(algoliaAppId, algoliaSearchKey)
10+
11+
export const searchClient = {
12+
search(requests) {
13+
if (requests.every(({params}) => !params.query)) {
14+
return Promise.resolve({
15+
results: requests.map(() => ({
16+
hits: [],
17+
nbHits: 0,
18+
nbPages: 0,
19+
page: 0,
20+
processingTimeMS: 0
21+
}))
22+
})
23+
}
24+
25+
return algoliaClient.search(requests)
26+
}
27+
}
28+
29+
export const searchResultsClient = {
30+
search(requests) {
31+
return algoliaClient.search(requests)
32+
}
33+
}

api/apolloConfig.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ export const APOLLO_STATE_PROP_NAME = '__APOLLO_STATE__'
1010
* Init Apollo and merge with initial state.
1111
*
1212
* @author WebDevStudios
13-
* @param {Object} apolloClient Apollo client instance.
14-
* @param {mixed} initialState The initial state of things.
15-
* @return {Object} Apollo client instance.
13+
* @param {object} apolloClient Apollo client instance.
14+
* @param {*} initialState The initial state of things.
15+
* @return {object} Apollo client instance.
1616
*/
1717
export function initializeApollo(apolloClient, initialState = null) {
1818
// If a page has Next.js data fetching methods that
@@ -43,9 +43,9 @@ export function initializeApollo(apolloClient, initialState = null) {
4343
* Pass down Apollo state to page props.
4444
*
4545
* @author WebDevStudios
46-
* @param {Object} client Apollo Client props.
47-
* @param {Object} pageProps Props from getStaticProps().
48-
* @return {Object} Updated page props.
46+
* @param {object} client Apollo Client props.
47+
* @param {object} pageProps Props from getStaticProps().
48+
* @return {object} Updated page props.
4949
*/
5050
export function addApolloState(client, pageProps) {
5151
if (pageProps?.props) {
@@ -59,8 +59,8 @@ export function addApolloState(client, pageProps) {
5959
* Only update when the cache value has changed.
6060
*
6161
* @author WebDevStudios
62-
* @param {Object} pageProps Props from getStaticProps().
63-
* @return {Object} WP Apollo client instance.
62+
* @param {object} pageProps Props from getStaticProps().
63+
* @return {object} WP Apollo client instance.
6464
*/
6565
export function useApollo(pageProps) {
6666
const state = pageProps[APOLLO_STATE_PROP_NAME]

api/frontend/connector.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import {ApolloClient, InMemoryCache} from '@apollo/client'
2+
import {initializeApollo} from '../apolloConfig'
3+
import {RestLink} from 'apollo-link-rest'
4+
5+
let feApolloClient
6+
7+
// Define Frontend API endpoint.
8+
const restLink = new RestLink({
9+
uri: '/api'
10+
})
11+
12+
/**
13+
* Create a basic Apollo client for connecting to Frontend API.
14+
*
15+
* @see https://www.apollographql.com/docs/react/api/core/ApolloClient/
16+
*
17+
* @author WebDevStudios
18+
* @return {object} Apollo client instance.
19+
*/
20+
export function createFeApolloClient() {
21+
return new ApolloClient({
22+
ssrMode: false,
23+
link: restLink,
24+
cache: new InMemoryCache()
25+
})
26+
}
27+
28+
/**
29+
* Init Apollo for Frontend API and merge with initial state.
30+
*
31+
* @author WebDevStudios
32+
* @param {*} initialState Initial Apollo state.
33+
* @return {object} Frontend Apollo client instance.
34+
*/
35+
export function initializeFeApollo(initialState = null) {
36+
// Only run one instance of the Apollo client.
37+
const _apolloClient = feApolloClient ?? createFeApolloClient()
38+
39+
const newApolloClient = initializeApollo(_apolloClient, initialState)
40+
41+
// For SSG and SSR always create a new Apollo Client.
42+
if (typeof window === 'undefined') return newApolloClient
43+
44+
// Create the Apollo Client once in the client.
45+
if (!feApolloClient) feApolloClient = newApolloClient
46+
47+
return newApolloClient
48+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import queryArchivePosts from './queryArchivePosts'
2+
import {initializeFeApollo} from '../../connector'
3+
4+
/**
5+
* Retrieve next page of posts for post type archive.
6+
*
7+
* @author WebDevStudios
8+
* @param {string} postType WP post type.
9+
* @param {string} cursor Start cursor for pagination.
10+
* @param {string} orderBy Order by: field.
11+
* @param {string} order Order by: direction.
12+
* @return {object} Archive post and pagination data or error object.
13+
*/
14+
export default async function getArchivePosts(
15+
postType,
16+
cursor = null,
17+
orderBy = 'DATE',
18+
order = 'DESC'
19+
) {
20+
const apolloClient = initializeFeApollo()
21+
22+
return apolloClient
23+
.query({
24+
query: queryArchivePosts,
25+
variables: {
26+
postType,
27+
cursor,
28+
orderBy,
29+
order
30+
}
31+
})
32+
.then(
33+
(response) =>
34+
response?.data?.archive ?? {
35+
error: true,
36+
errorMessage: `An error occurred while trying to retrieve data for ${postType} archive.`
37+
}
38+
)
39+
.catch((error) => {
40+
return {
41+
error: true,
42+
errorMessage: error.message
43+
}
44+
})
45+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import {gql} from '@apollo/client'
2+
import {wpDataEndpoints} from '@/api/wordpress/connector'
3+
4+
// Query: retrieve archive posts by post type.
5+
const queryArchivePosts = gql`
6+
query GET_ARCHIVE_POSTS(
7+
$postType: String!
8+
$cursor: String!
9+
$orderBy: String = DATE
10+
$order: String = DESC
11+
) {
12+
archive(
13+
postType: $postType
14+
cursor: $cursor
15+
orderBy: $orderBy
16+
order: $order
17+
) @rest(type: "Archive", path: "${wpDataEndpoints.archive}?{args}") {
18+
pagination
19+
posts
20+
}
21+
}
22+
`
23+
24+
export default queryArchivePosts

api/wordpress/_global/getPostTypeArchive.js

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
import {initializeWpApollo} from '../connector'
22
import queryPostsArchive from '../posts/queryPostsArchive'
33
import {postTypes} from './postTypes'
4+
import queryEventsArchive from '../events/queryEventsArchive'
5+
import queryCareersArchive from '../careers/queryCareersArchive'
6+
import queryServicesArchive from '../services/queryServicesArchive'
7+
import queryTeamsArchive from '../teams/queryTeamsArchive'
8+
import queryPortfoliosArchive from '../portfolios/queryPortfoliosArchive'
9+
import queryTestimonialsArchive from '../testimonials/queryTestimonialsArchive'
410

511
/**
612
* Retrieve post archive.
713
*
814
* @author WebDevStudios
9-
* @param {string} postType WP post type.
10-
* @param {string} orderBy Order by: field.
11-
* @param {string} order Order by: direction.
12-
* @param {string} cursor Start/end cursor for pagination.
13-
* @param {bool} getNext Whether to retrieve next set of posts (true) or previous set (false).
14-
* @param {number} perPage Number of posts per page.
15-
* @return {Object} Object containing Apollo client instance and post archive data or error object.
15+
* @param {string} postType WP post type.
16+
* @param {string} orderBy Order by: field.
17+
* @param {string} order Order by: direction.
18+
* @param {string} cursor Start/end cursor for pagination.
19+
* @param {boolean} getNext Whether to retrieve next set of posts (true) or previous set (false).
20+
* @param {number} perPage Number of posts per page.
21+
* @return {object} Object containing Apollo client instance and post archive data or error object.
1622
*/
1723
export default async function getPostTypeArchive(
1824
postType,
@@ -24,7 +30,13 @@ export default async function getPostTypeArchive(
2430
) {
2531
// Define single post query based on post type.
2632
const postTypeQuery = {
27-
post: queryPostsArchive
33+
career: queryCareersArchive,
34+
event: queryEventsArchive,
35+
portfolio: queryPortfoliosArchive,
36+
post: queryPostsArchive,
37+
service: queryServicesArchive,
38+
team: queryTeamsArchive,
39+
testimonial: queryTestimonialsArchive
2840
}
2941

3042
// Retrieve post type query.
@@ -36,6 +48,8 @@ export default async function getPostTypeArchive(
3648
// Set up return object.
3749
const response = {
3850
apolloClient,
51+
posts: null,
52+
pagination: null,
3953
error: false,
4054
errorMessage: null
4155
}
@@ -60,27 +74,29 @@ export default async function getPostTypeArchive(
6074
}
6175

6276
// Execute query.
63-
response.posts = await apolloClient
77+
await apolloClient
6478
.query({query, variables})
65-
.then((posts) => {
79+
.then((archive) => {
6680
const pluralType = postTypes[postType] ?? postType
81+
const data = archive?.data?.[pluralType] ?? null
6782

6883
// Set error props if data not found.
69-
if (!posts?.data?.[pluralType]?.edges) {
84+
if (!data?.edges || !data?.pageInfo) {
7085
response.error = true
7186
response.errorMessage = `An error occurred while trying to retrieve data for ${pluralType} archive.`
7287

7388
return null
7489
}
7590

7691
// Flatten posts array to include inner node post data.
77-
return posts.data[pluralType].edges.map((post) => post.node)
92+
response.posts = data.edges.map((post) => post.node)
93+
94+
// Extract pagination data.
95+
response.pagination = data.pageInfo
7896
})
7997
.catch((error) => {
8098
response.error = true
8199
response.errorMessage = error.message
82-
83-
return null
84100
})
85101

86102
return response

0 commit comments

Comments
 (0)