From 689fa46c63a783b6843c061b41b532668dd7a76f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=ADcholas=20Oliveira?= Date: Thu, 24 Aug 2023 22:34:34 -0300 Subject: [PATCH] refactor: remove unnecessary things --- .../wp-nextjs/src/pages/blog/[[...path]].js | 12 +---- .../wp-nextjs/src/pages/book/[...path].js | 36 ------------- .../wp-nextjs/src/pages/books/[[...path]].js | 50 ------------------- projects/wp-nextjs/src/params.js | 13 ----- 4 files changed, 2 insertions(+), 109 deletions(-) delete mode 100644 projects/wp-nextjs/src/pages/book/[...path].js delete mode 100644 projects/wp-nextjs/src/pages/books/[[...path]].js diff --git a/projects/wp-nextjs/src/pages/blog/[[...path]].js b/projects/wp-nextjs/src/pages/blog/[[...path]].js index 23adefce5..060edf831 100644 --- a/projects/wp-nextjs/src/pages/blog/[[...path]].js +++ b/projects/wp-nextjs/src/pages/blog/[[...path]].js @@ -22,11 +22,7 @@ import { resolveBatch } from '../../utils/promises'; import { PageContent } from '../../components/PageContent'; const Archive = () => { - const { data, loading } = usePosts(blogParams.archive); - - if (loading) { - return 'loading usePosts'; - } + const { data } = usePosts(blogParams.archive); return ( <> @@ -43,11 +39,7 @@ const Archive = () => { }; const BlogPage = () => { - const { isArchive, loading } = usePostOrPosts(blogParams); - - if (loading) { - return 'Loading usePostOrPosts'; - } + const { isArchive } = usePostOrPosts(blogParams); if (isArchive) { return ; diff --git a/projects/wp-nextjs/src/pages/book/[...path].js b/projects/wp-nextjs/src/pages/book/[...path].js deleted file mode 100644 index 6d775b8a8..000000000 --- a/projects/wp-nextjs/src/pages/book/[...path].js +++ /dev/null @@ -1,36 +0,0 @@ -/** - * This is just an example of a single page route for a CPT called 'book' - */ -import { - fetchHookData, - addHookData, - handleError, - usePost, - useAppSettings, -} from '@headstartwp/next'; -import { PageContent } from '../../components/PageContent'; -import { bookParams } from '../../params'; -import { resolveBatch } from '../../utils/promises'; - -const BookPage = () => { - const { data } = usePost(bookParams); - - return
{data ? : 'loading...'}
; -}; - -export default BookPage; - -export async function getServerSideProps(context) { - try { - const settledPromises = await resolveBatch([ - { - func: fetchHookData(usePost.fetcher(), context, { params: bookParams }), - }, - { func: fetchHookData(useAppSettings.fetcher(), context), throw: false }, - ]); - - return addHookData(settledPromises, {}); - } catch (e) { - return handleError(e, context); - } -} diff --git a/projects/wp-nextjs/src/pages/books/[[...path]].js b/projects/wp-nextjs/src/pages/books/[[...path]].js deleted file mode 100644 index 3f9f4ca6c..000000000 --- a/projects/wp-nextjs/src/pages/books/[[...path]].js +++ /dev/null @@ -1,50 +0,0 @@ -/** - * This is just an example of a archive page route for a CPT called 'book' - */ -import { - usePosts, - fetchHookData, - addHookData, - handleError, - useAppSettings, -} from '@headstartwp/next'; -import { booksParams } from '../../params'; -import { resolveBatch } from '../../utils/promises'; - -const BooksPage = () => { - const { data, error, loading } = usePosts(booksParams); - - if (error) { - return 'error'; - } - - if (loading) { - return 'Loading...'; - } - - return ( - - ); -}; - -export default BooksPage; - -export async function getServerSideProps(context) { - try { - // fetch batch of promises and throws errors selectively - const settledPromises = await resolveBatch([ - { - func: fetchHookData(usePosts.fetcher(), context, { params: booksParams }), - }, - { func: fetchHookData(useAppSettings.fetcher(), context), throw: false }, - ]); - - return addHookData(settledPromises, {}); - } catch (e) { - return handleError(e, context); - } -} diff --git a/projects/wp-nextjs/src/params.js b/projects/wp-nextjs/src/params.js index 90fd10269..432c5f897 100644 --- a/projects/wp-nextjs/src/params.js +++ b/projects/wp-nextjs/src/params.js @@ -31,19 +31,6 @@ export const blogParams = { routeMatchStrategy: 'single', }; -// The params below are just for the custom post type routes example -// remove them if you don't need them - -/** - * @type {import('@headstartwp/core').PostParams} - */ -export const bookParams = { postType: ['book'] }; - -/** - * @type {import('@headstartwp/core').PostsArchiveParams} - */ -export const booksParams = { postType: 'book' }; - /** * @type {import('@headstartwp/core').TaxonomyArchiveParams} */