-
Notifications
You must be signed in to change notification settings - Fork 1.1k
EDU-135: Product details for all the frameworks #3948
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
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
bd65b40
vue product details
uttej-vsk c709bca
nuxt product details
uttej-vsk dc4ca93
vue fix
uttej-vsk d646adf
svelte product details
uttej-vsk a33eeb3
test cases for svelte
uttej-vsk 067411d
sveltekit
uttej-vsk 3b2e9fc
remove console.log
uttej-vsk 15efb92
qwik product details
uttej-vsk 4716084
nextjs app router
uttej-vsk 7a12e31
rename the route segment
uttej-vsk 14dfd9f
nextjs pages router
uttej-vsk 849cae7
remix and hydrogen
uttej-vsk b254d6e
cleanu[
uttej-vsk ed08b53
feedback comments for all frameworks
uttej-vsk 3d9fd8a
hydrogen feedback comments
uttej-vsk 4ab071b
.
uttej-vsk 46b1421
.
uttej-vsk ef5bbb0
merge from main
uttej-vsk e027ecc
assumption of timeout
uttej-vsk 9104de8
linting error
uttej-vsk e0d6b6a
fix typos
uttej-vsk caf9dab
conditional check
uttej-vsk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
packages/sdks/snippets/hydrogen/app/routes/category.$handle.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import {fetchOneEntry} from '@builder.io/sdk-react'; | ||
import type {LoaderFunctionArgs} from '@remix-run/node'; | ||
import {useLoaderData} from '@remix-run/react'; | ||
|
||
export const loader = async ({params}: LoaderFunctionArgs) => { | ||
const productDetails = await fetchOneEntry({ | ||
model: 'product-details', | ||
apiKey: 'ee9f13b4981e489a9a1209887695ef2b', | ||
query: { | ||
'data.handle': params.handle, | ||
}, | ||
}); | ||
|
||
return {productDetails}; | ||
}; | ||
|
||
export default function ProductDetailsPage() { | ||
const {productDetails} = useLoaderData<typeof loader>(); | ||
|
||
return ( | ||
productDetails && ( | ||
<div className="product-details-page"> | ||
<h1>{productDetails.data?.name}</h1> | ||
<img src={productDetails.data?.image} alt={productDetails.data?.name} /> | ||
<p>{productDetails.data?.collection.value.data.copy}</p> | ||
<p>Price: {productDetails.data?.collection.value.data.price}</p> | ||
</div> | ||
) | ||
); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
packages/sdks/snippets/nuxt/pages/product/category/[handle].vue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<script setup lang="ts"> | ||
import { useAsyncData } from '#app' | ||
import { fetchOneEntry } from '@builder.io/sdk-vue' | ||
import { useRoute } from 'nuxt/app' | ||
|
||
const route = useRoute(); | ||
const { data: productDetails, pending } = await useAsyncData('product-details', () => | ||
fetchOneEntry({ | ||
model: 'product-details', | ||
apiKey: 'ee9f13b4981e489a9a1209887695ef2b', | ||
query: { | ||
'data.handle': route.params.handle, | ||
}, | ||
}), | ||
) | ||
</script> | ||
|
||
<template> | ||
<div v-if="pending">Loading product details...</div> | ||
|
||
<div class="product-details-page" v-if="productDetails?.data"> | ||
<h1>{{ productDetails.data.name }}</h1> | ||
<img :src="productDetails.data.image" :alt="productDetails.data.name" /> | ||
<p>{{ productDetails.data.collection.value.data.copy }}</p> | ||
<p>Price: {{ productDetails.data.collection.value.data.price }}</p> | ||
</div> | ||
</template> |
31 changes: 31 additions & 0 deletions
31
packages/sdks/snippets/qwik-city/src/routes/product/category/[handle]/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { component$ } from '@builder.io/qwik'; | ||
import { routeLoader$ } from '@builder.io/qwik-city'; | ||
import { fetchOneEntry } from '@builder.io/sdk-qwik'; | ||
|
||
export const useProductDetails = routeLoader$(async ({ params }) => { | ||
return await fetchOneEntry({ | ||
model: 'product-details', | ||
apiKey: 'ee9f13b4981e489a9a1209887695ef2b', | ||
query: { | ||
'data.handle': params.handle, | ||
}, | ||
}); | ||
}); | ||
|
||
export default component$(() => { | ||
const productResource = useProductDetails(); | ||
|
||
return ( | ||
productResource.value && ( | ||
<div class="product-details-page"> | ||
<h1>{productResource.value.data?.name}</h1> | ||
<img | ||
src={productResource.value.data?.image} | ||
alt={productResource.value.data?.name} | ||
/> | ||
<p>{productResource.value.data?.collection.value.data.copy}</p> | ||
<p>Price: {productResource.value.data?.collection.value.data.price}</p> | ||
</div> | ||
) | ||
); | ||
}); |
31 changes: 31 additions & 0 deletions
31
...react-sdk-next-14-app/app/(blueprints-product-details)/product/category/[handle]/page.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { fetchOneEntry } from '@builder.io/sdk-react'; | ||
import Image from 'next/image'; | ||
|
||
export default async function ProductDetailsPage({ | ||
params, | ||
}: { | ||
params: { handle: string }; | ||
}) { | ||
const productDetails = await fetchOneEntry({ | ||
model: 'product-details', | ||
apiKey: 'ee9f13b4981e489a9a1209887695ef2b', | ||
query: { | ||
'data.handle': params.handle, | ||
}, | ||
}); | ||
|
||
return ( | ||
productDetails && ( | ||
<div className="product-details-page"> | ||
<h1>{productDetails.data?.name}</h1> | ||
<Image | ||
src={`${productDetails.data?.image}`} | ||
alt={productDetails.data?.name} | ||
priority={true} | ||
/> | ||
<p>{productDetails.data?.collection.value.data.copy}</p> | ||
<p>Price: {productDetails.data?.collection.value.data.price}</p> | ||
</div> | ||
) | ||
); | ||
} |
10 changes: 9 additions & 1 deletion
10
packages/sdks/snippets/react-sdk-next-14-app/next.config.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,12 @@ | ||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = {}; | ||
const nextConfig = { | ||
images: { | ||
remotePatterns: [ | ||
{ | ||
hostname: 'cdn.builder.io', | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
export default nextConfig; |
15 changes: 15 additions & 0 deletions
15
packages/sdks/snippets/react-sdk-next-pages/next.config.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,21 @@ | ||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = { | ||
reactStrictMode: true, | ||
async rewrites() { | ||
return [ | ||
{ | ||
source: '/product/category/:handle', | ||
destination: '/product-details/product/category/:handle', | ||
}, | ||
]; | ||
}, | ||
images: { | ||
remotePatterns: [ | ||
{ | ||
hostname: 'cdn.builder.io', | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
export default nextConfig; |
36 changes: 36 additions & 0 deletions
36
...dks/snippets/react-sdk-next-pages/src/pages/product-details/product/category/[handle].tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { fetchOneEntry, type BuilderContent } from '@builder.io/sdk-react'; | ||
import type { GetServerSideProps, InferGetServerSidePropsType } from 'next'; | ||
import Image from 'next/image'; | ||
|
||
export const getServerSideProps = (async ({ params }) => { | ||
const productDetails = await fetchOneEntry({ | ||
model: 'product-details', | ||
apiKey: 'ee9f13b4981e489a9a1209887695ef2b', | ||
query: { | ||
'data.handle': params?.handle, | ||
}, | ||
}); | ||
|
||
return { props: { productDetails } }; | ||
}) satisfies GetServerSideProps<{ | ||
productDetails: BuilderContent | null; | ||
}>; | ||
|
||
export default function ProductCategoryPage({ | ||
productDetails, | ||
}: InferGetServerSidePropsType<typeof getServerSideProps>) { | ||
return ( | ||
productDetails && ( | ||
<div className="product-details-page"> | ||
<h1>{productDetails.data?.name}</h1> | ||
<Image | ||
src={productDetails.data?.image} | ||
alt={productDetails.data?.name} | ||
priority={true} | ||
/> | ||
<p>{productDetails.data?.collection.value.data.copy}</p> | ||
<p>Price: {productDetails.data?.collection.value.data.price}</p> | ||
</div> | ||
) | ||
); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
packages/sdks/snippets/svelte/src/components/blueprints/ProductDetails.svelte
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<script lang="ts"> | ||
import { onMount } from 'svelte'; | ||
import { fetchOneEntry, type BuilderContent } from '@builder.io/sdk-svelte'; | ||
|
||
export let handle: string; | ||
let productDetails: BuilderContent | null = null; | ||
|
||
onMount(() => { | ||
fetchOneEntry({ | ||
model: 'product-details', | ||
apiKey: 'ee9f13b4981e489a9a1209887695ef2b', | ||
query: { 'data.handle': handle }, | ||
}).then((data) => (productDetails = data)); | ||
}); | ||
</script> | ||
|
||
{#if !productDetails} | ||
<p>Loading product details...</p> | ||
{:else} | ||
<div class="product-details-page"> | ||
<h1>{productDetails.data?.name}</h1> | ||
<img src={productDetails.data?.image} alt={productDetails.data?.name} /> | ||
<p>{productDetails.data?.collection.value.data.copy}</p> | ||
<p>Price: {productDetails.data?.collection.value.data.price}</p> | ||
</div> | ||
{/if} |
14 changes: 14 additions & 0 deletions
14
packages/sdks/snippets/sveltekit/src/routes/product/category/[handle]/+page.server.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { fetchOneEntry } from '@builder.io/sdk-svelte'; | ||
import type { PageServerLoad } from './$types'; | ||
|
||
export const load: PageServerLoad = async ({ params }) => { | ||
const productDetails = await fetchOneEntry({ | ||
model: 'product-details', | ||
apiKey: 'ee9f13b4981e489a9a1209887695ef2b', | ||
query: { | ||
'data.handle': params.handle, | ||
}, | ||
}); | ||
|
||
return { productDetails }; | ||
}; |
18 changes: 18 additions & 0 deletions
18
packages/sdks/snippets/sveltekit/src/routes/product/category/[handle]/+page.svelte
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<script lang="ts"> | ||
import type { PageData } from './$types'; | ||
export let data: PageData; | ||
</script> | ||
|
||
{#if !data.productDetails} | ||
<p>Loading product details...</p> | ||
{:else} | ||
<div class="product-details-page"> | ||
<h1>{data.productDetails.data?.name}</h1> | ||
<img | ||
src={data.productDetails.data?.image} | ||
alt={data.productDetails.data?.name} | ||
/> | ||
<p>{data.productDetails.data?.collection.value.data.copy}</p> | ||
<p>Price: {data.productDetails.data?.collection.value.data.price}</p> | ||
</div> | ||
{/if} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
packages/sdks/snippets/vue/src/views/blueprints/ProductDetails.vue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<template> | ||
<div v-if="!productDetails?.data"> | ||
<p>Loading product details...</p> | ||
</div> | ||
<div class="product-details-page" v-else> | ||
<h1>{{ productDetails.data.name }}</h1> | ||
<img | ||
:src="productDetails.data.image" | ||
:alt="productDetails.data.name" | ||
/> | ||
<p>{{ productDetails.data.collection.value.data.copy }}</p> | ||
<p>Price: {{ productDetails.data.collection.value.data.price }}</p> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { ref, onMounted } from 'vue' | ||
import { fetchOneEntry, type BuilderContent } from '@builder.io/sdk-vue' | ||
import { useRoute } from 'vue-router' | ||
|
||
const route = useRoute() | ||
const productDetails = ref<BuilderContent | null>(null); | ||
|
||
onMounted( () => { | ||
fetchOneEntry({ | ||
model: 'product-details', | ||
apiKey: 'ee9f13b4981e489a9a1209887695ef2b', | ||
query: { 'data.handle': route.params.handle }, | ||
}).then((data) => { | ||
productDetails.value = data | ||
}) | ||
}) | ||
</script> | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.