diff --git a/app/components/FeaturedSection.tsx b/app/components/FeaturedSection.tsx index fb0cc04..3f9b452 100644 --- a/app/components/FeaturedSection.tsx +++ b/app/components/FeaturedSection.tsx @@ -13,7 +13,7 @@ export function FeaturedSection() { useEffect(() => { load(path); - }, [load, path]); + }, [path]); if (!data) return null; diff --git a/app/routes/($locale).$.tsx b/app/routes/($locale).$.tsx new file mode 100644 index 0000000..0e4b9f6 --- /dev/null +++ b/app/routes/($locale).$.tsx @@ -0,0 +1,17 @@ +import {WeaverseContent} from '~/weaverse'; +import {type LoaderFunctionArgs} from '@shopify/remix-oxygen'; +export async function loader({context}: LoaderFunctionArgs) { + let weaverseData = await context.weaverse.loadPage({ + type: 'CUSTOM', + }); + if (!weaverseData) { + return new Response(null, {status: 404}); + } + return { + weaverseData, + }; +} + +export default function Component() { + return ; +} diff --git a/app/routes/($locale)._index.tsx b/app/routes/($locale)._index.tsx index 81860f6..bc21b4c 100644 --- a/app/routes/($locale)._index.tsx +++ b/app/routes/($locale)._index.tsx @@ -1,24 +1,27 @@ import {AnalyticsPageType} from '@shopify/hydrogen'; import {defer} from '@shopify/remix-oxygen'; -import {type RouteLoaderArgs} from '@weaverse/hydrogen'; import {routeHeaders} from '~/data/cache'; import {SHOP_QUERY} from '~/data/queries'; import {seoPayload} from '~/lib/seo.server'; import {WeaverseContent} from '~/weaverse'; +import {type LoaderFunctionArgs} from '@shopify/remix-oxygen'; +import type {PageType} from '@weaverse/hydrogen'; export const headers = routeHeaders; -export async function loader(args: RouteLoaderArgs) { +export async function loader(args: LoaderFunctionArgs) { let {params, context} = args; let {language, country} = context.storefront.i18n; + let pageType: PageType = 'INDEX'; if ( params.locale && params.locale.toLowerCase() !== `${language}-${country}`.toLowerCase() ) { // If the locale URL param is defined, yet we still are on `EN-US` - // the the locale param must be invalid, send to the 404 page - throw new Response(null, {status: 404}); + // the locale param must be invalid + // Update for Weaverse: if it not locale, it probably is a custom page handle + pageType = 'CUSTOM'; } let {shop} = await context.storefront.query(SHOP_QUERY); @@ -26,7 +29,9 @@ export async function loader(args: RouteLoaderArgs) { return defer({ shop, - weaverseData: await context.weaverse.loadPage(), + weaverseData: await context.weaverse.loadPage({ + type: pageType, + }), analytics: { pageType: AnalyticsPageType.home, }, diff --git a/app/routes/($locale).blogs.$blogHandle.$articleHandle.tsx b/app/routes/($locale).blogs.$blogHandle.$articleHandle.tsx index 0b97642..bf28f24 100644 --- a/app/routes/($locale).blogs.$blogHandle.$articleHandle.tsx +++ b/app/routes/($locale).blogs.$blogHandle.$articleHandle.tsx @@ -58,7 +58,10 @@ export async function loader(args: RouteLoaderArgs) { relatedArticles, formattedDate, seo, - weaverseData: await context.weaverse.loadPage(), + weaverseData: await context.weaverse.loadPage({ + type: 'ARTICLE', + handle: params.articleHandle, + }), }); } diff --git a/app/routes/($locale).blogs.$blogHandle._index.tsx b/app/routes/($locale).blogs.$blogHandle._index.tsx index 375532a..fe9c2f5 100644 --- a/app/routes/($locale).blogs.$blogHandle._index.tsx +++ b/app/routes/($locale).blogs.$blogHandle._index.tsx @@ -47,7 +47,10 @@ export const loader = async (args: RouteLoaderArgs) => { blog, articles, seo, - weaverseData: await context.weaverse.loadPage(), + weaverseData: await context.weaverse.loadPage({ + type: 'BLOG', + handle: params.blogHandle, + }), }); }; diff --git a/app/routes/($locale).collections.$collectionHandle.tsx b/app/routes/($locale).collections.$collectionHandle.tsx index fa99866..0caf97e 100644 --- a/app/routes/($locale).collections.$collectionHandle.tsx +++ b/app/routes/($locale).collections.$collectionHandle.tsx @@ -125,7 +125,10 @@ export async function loader(args: RouteLoaderArgs) { resourceId: collection.id, }, seo, - weaverseData: await context.weaverse.loadPage(), + weaverseData: await context.weaverse.loadPage({ + type: 'COLLECTION', + handle: collectionHandle, + }), }); } diff --git a/app/routes/($locale).collections._index.tsx b/app/routes/($locale).collections._index.tsx index 70af15f..2817d82 100644 --- a/app/routes/($locale).collections._index.tsx +++ b/app/routes/($locale).collections._index.tsx @@ -32,7 +32,9 @@ export const loader = async (args: RouteLoaderArgs) => { return json({ collections, seo, - weaverseData: await weaverse.loadPage(), + weaverseData: await weaverse.loadPage({ + type: 'COLLECTION_LIST' + }), }); }; diff --git a/app/routes/($locale).pages.$pageHandle.tsx b/app/routes/($locale).pages.$pageHandle.tsx index 40d61a4..3d4a618 100644 --- a/app/routes/($locale).pages.$pageHandle.tsx +++ b/app/routes/($locale).pages.$pageHandle.tsx @@ -27,7 +27,10 @@ export async function loader({request, params, context}: RouteLoaderArgs) { return json({ page, seo, - weaverseData: await context.weaverse.loadPage(), + weaverseData: await context.weaverse.loadPage({ + type: 'PAGE', + handle: params.pageHandle, + }), }); } diff --git a/app/routes/($locale).products.$productHandle.tsx b/app/routes/($locale).products.$productHandle.tsx index 288cac4..d76ec5e 100644 --- a/app/routes/($locale).products.$productHandle.tsx +++ b/app/routes/($locale).products.$productHandle.tsx @@ -48,7 +48,7 @@ export async function loader({params, request, context}: LoaderFunctionArgs) { // In order to show which variants are available in the UI, we need to query // all of them. But there might be a *lot*, so instead separate the variants - // into it's own separate query that is deferred. So there's a brief moment + // into its own separate query that is deferred. So there's a brief moment // where variant options might show as available when they're not, but after // this deferred query resolves, the UI will update. const variants = await context.storefront.query(VARIANTS_QUERY, { @@ -105,7 +105,10 @@ export async function loader({params, request, context}: LoaderFunctionArgs) { totalValue: parseFloat(selectedVariant.price.amount), }, seo, - weaverseData: await context.weaverse.loadPage(), + weaverseData: await context.weaverse.loadPage({ + type: 'PRODUCT', + handle: productHandle + }), judgemeReviews, }); } diff --git a/app/routes/($locale).products._index.tsx b/app/routes/($locale).products._index.tsx index 799661c..d31303c 100644 --- a/app/routes/($locale).products._index.tsx +++ b/app/routes/($locale).products._index.tsx @@ -1,11 +1,11 @@ import {getPaginationVariables} from '@shopify/hydrogen'; import {json} from '@shopify/remix-oxygen'; -import {type RouteLoaderArgs} from '@weaverse/hydrogen'; import invariant from 'tiny-invariant'; import {routeHeaders} from '~/data/cache'; import {ALL_PRODUCTS_QUERY} from '~/data/queries'; import {seoPayload} from '~/lib/seo.server'; import {WeaverseContent} from '~/weaverse'; +import type {LoaderFunctionArgs} from '@shopify/remix-oxygen'; const PAGE_BY = 8; @@ -14,7 +14,7 @@ export const headers = routeHeaders; export async function loader({ request, context: {storefront, weaverse}, -}: RouteLoaderArgs) { +}: LoaderFunctionArgs) { const variables = getPaginationVariables(request, {pageBy: PAGE_BY}); const data = await storefront.query(ALL_PRODUCTS_QUERY, { @@ -48,7 +48,9 @@ export async function loader({ return json({ products: data.products, seo, - weaverseData: await weaverse.loadPage(), + weaverseData: await weaverse.loadPage({ + type: 'ALL_PRODUCTS' + }), }); }