Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ALT-1508] fix: react-router import in gatsby spa to match the docs #930

Merged
merged 1 commit into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions examples/gatsby/gatsby-spa/gatsby-browser.tsx

This file was deleted.

82 changes: 1 addition & 81 deletions examples/gatsby/gatsby-spa/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions examples/gatsby/gatsby-spa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
"gatsby": "^5.14.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-markdown": "^9.0.3",
"react-router": "^7.1.1"
"react-markdown": "^9.0.3"
},
"devDependencies": {
"@types/node": "^20.11.19",
Expand Down
26 changes: 0 additions & 26 deletions examples/gatsby/gatsby-spa/src/pages/StudioExperiencePage.tsx

This file was deleted.

30 changes: 30 additions & 0 deletions examples/gatsby/gatsby-spa/src/pages/[locale]/[slug].tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { useFetchBySlug, ExperienceRoot } from '@contentful/experiences-sdk-react';
import { PageProps } from 'gatsby';
import React from 'react';
import { useContentfulClient } from '../../utils/useContentfulClient';

type PathParams = {
locale: string;
slug: string,
isPreviewString: string;
};

const experienceTypeId = process.env.GATSBY_CTFL_EXPERIENCE_TYPE || '';

export default function StudioExperiencePage(pageProps: PageProps) {
const { locale = 'en-US', slug = 'home-page', } = pageProps.params as PathParams;
const isPreview = new URL(pageProps.location.href).searchParams.get('isPreview') === 'true';
const { client } = useContentfulClient({ isPreview });

const { experience, error, isLoading } = useFetchBySlug({
slug,
localeCode: locale,
client,
experienceTypeId,
});

if (isLoading) return <div>Loading...</div>;
if (error) return <div>{error.message}</div>;

return <ExperienceRoot experience={experience} locale={locale} />;
}
9 changes: 4 additions & 5 deletions examples/gatsby/gatsby-spa/src/utils/useContentfulClient.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { useMemo } from 'react';
import { createClient } from 'contentful';
import { useLocation } from 'react-router';
import '../studio-config'; // Update this file to set breakpoints, design tokens, and register components

export const useContentfulClient = () => {
const location = useLocation();
const queryParams = new URLSearchParams(location.search);
const isPreview = queryParams.get('isPreview') === 'true';
type Props = {
isPreview?: boolean;
}

export const useContentfulClient = ({isPreview}: Props) => {
const client = useMemo(() => {
const clientConfig = {
space: process.env.GATSBY_CTFL_SPACE || '',
Expand Down
Loading