From 4784daad80cdf3543f9c6599d7ecc6411d9787e3 Mon Sep 17 00:00:00 2001 From: Bel Curcio Date: Fri, 11 Jun 2021 13:50:37 -0300 Subject: [PATCH] Working view of a LocalProvider --- .../api/operations/get-all-product-paths.ts | 4 +- .../local/api/operations/get-all-products.ts | 1 - framework/local/api/operations/get-product.ts | 18 +- framework/local/data.json | 195 +++++++++++++++++- framework/local/product/use-search.tsx | 6 +- 5 files changed, 213 insertions(+), 11 deletions(-) diff --git a/framework/local/api/operations/get-all-product-paths.ts b/framework/local/api/operations/get-all-product-paths.ts index a9b7671e7..fff24e791 100644 --- a/framework/local/api/operations/get-all-product-paths.ts +++ b/framework/local/api/operations/get-all-product-paths.ts @@ -1,3 +1,5 @@ +import data from '../../data.json' + export type GetAllProductPathsResult = { products: Array<{ path: string }> } @@ -5,7 +7,7 @@ export type GetAllProductPathsResult = { export default function getAllProductPathsOperation() { function getAllProductPaths(): Promise { return Promise.resolve({ - products: [].map((p) => ({ path: `/hello` })), + products: data.products.map(({ path }) => ({ path })), }) } diff --git a/framework/local/api/operations/get-all-products.ts b/framework/local/api/operations/get-all-products.ts index bc3f21826..8605b833d 100644 --- a/framework/local/api/operations/get-all-products.ts +++ b/framework/local/api/operations/get-all-products.ts @@ -17,7 +17,6 @@ export default function getAllProductsOperation({ config?: Partial preview?: boolean } = {}): Promise<{ products: Product[] | any[] }> { - console.log(data.products[0]) return Promise.resolve({ products: data.products, }) diff --git a/framework/local/api/operations/get-product.ts b/framework/local/api/operations/get-product.ts index 67385cabc..a098ae9fd 100644 --- a/framework/local/api/operations/get-product.ts +++ b/framework/local/api/operations/get-product.ts @@ -1,8 +1,22 @@ +import type { LocalConfig } from '../index' import { Product } from '@commerce/types/product' +import data from '../../data.json' export default function getProductOperation() { - async function getProduct(): Promise { - return {} + async function getProduct({ + query = '', + variables, + config, + }: { + query?: string + variables?: T['variables'] + config?: Partial + preview?: boolean + } = {}): Promise { + return Promise.resolve({ + product: data.products[0], + }) } + return getProduct } diff --git a/framework/local/data.json b/framework/local/data.json index aa1e3b57a..6b25e6aa5 100644 --- a/framework/local/data.json +++ b/framework/local/data.json @@ -7,16 +7,77 @@ "path": "/new-short-sleeve-t-shirt", "slug": "new-short-sleeve-t-shirt", "price": { "value": 25, "currencyCode": "USD" }, + "descriptionHtml": "

Show off your love for Next.js and Vercel with this unique, limited edition t-shirt. This design is part of a limited run, numbered drop at the June 2021 Next.js Conf. It features a unique, handcrafted triangle design. Get it while supplies last – only 200 of these shirts will be made! All proceeds will be donated to charity.

", "images": [ { "url": "/assets/drop-shirt-0.png", "altText": "Shirt", "width": 1000, "height": 1000 + }, + { + "url": "/assets/drop-shirt-1.png", + "altText": "Shirt", + "width": 1000, + "height": 1000 + }, + { + "url": "/assets/drop-shirt-2.png", + "altText": "Shirt", + "width": 1000, + "height": 1000 + }, + { + "url": "/assets/drop-shirt-3.png", + "altText": "Shirt", + "width": 1000, + "height": 1000 } ], - "variants": [], - "options": [] + "variants": [ + { + "id": "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0LzU0NDczMjUwMjQ0MjAss=", + "options": [ + { + "__typename": "MultipleChoiceOption", + "id": "asd", + "displayName": "Size", + "values": [ + { + "label": "XL" + } + ] + } + ] + } + ], + "options": [ + { + "id": "option-color", + "displayName": "Color", + "values": [ + { + "label": "color", + "hexColors": ["#222"] + } + ] + }, + { + "id": "option-size", + "displayName": "Size", + "values": [ + { + "label": "S" + }, + { + "label": "M" + }, + { + "label": "L" + } + ] + } + ] }, { "id": "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0LzU0NDczMjUwMjQ0MjA=", @@ -25,16 +86,77 @@ "path": "/new-short-sleeve-t-shirt", "slug": "new-short-sleeve-t-shirt", "price": { "value": 25, "currencyCode": "USD" }, + "descriptionHtml": "

Show off your love for Next.js and Vercel with this unique, limited edition t-shirt. This design is part of a limited run, numbered drop at the June 2021 Next.js Conf. It features a unique, handcrafted triangle design. Get it while supplies last – only 200 of these shirts will be made! All proceeds will be donated to charity.

", "images": [ { "url": "/assets/drop-shirt-0.png", "altText": "Shirt", "width": 1000, "height": 1000 + }, + { + "url": "/assets/drop-shirt-1.png", + "altText": "Shirt", + "width": 1000, + "height": 1000 + }, + { + "url": "/assets/drop-shirt-2.png", + "altText": "Shirt", + "width": 1000, + "height": 1000 + }, + { + "url": "/assets/drop-shirt-3.png", + "altText": "Shirt", + "width": 1000, + "height": 1000 } ], - "variants": [], - "options": [] + "variants": [ + { + "id": "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0LzU0NDczMjUwMjQ0MjAss=", + "options": [ + { + "__typename": "MultipleChoiceOption", + "id": "asd", + "displayName": "Size", + "values": [ + { + "label": "XL" + } + ] + } + ] + } + ], + "options": [ + { + "id": "option-color", + "displayName": "Color", + "values": [ + { + "label": "color", + "hexColors": ["#222"] + } + ] + }, + { + "id": "option-size", + "displayName": "Size", + "values": [ + { + "label": "S" + }, + { + "label": "M" + }, + { + "label": "L" + } + ] + } + ] }, { "id": "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0LzU0NDczMjUwMjQ0MjA=", @@ -43,16 +165,77 @@ "path": "/new-short-sleeve-t-shirt", "slug": "new-short-sleeve-t-shirt", "price": { "value": 25, "currencyCode": "USD" }, + "descriptionHtml": "

Show off your love for Next.js and Vercel with this unique, limited edition t-shirt. This design is part of a limited run, numbered drop at the June 2021 Next.js Conf. It features a unique, handcrafted triangle design. Get it while supplies last – only 200 of these shirts will be made! All proceeds will be donated to charity.

", "images": [ { "url": "/assets/drop-shirt-0.png", "altText": "Shirt", "width": 1000, "height": 1000 + }, + { + "url": "/assets/drop-shirt-1.png", + "altText": "Shirt", + "width": 1000, + "height": 1000 + }, + { + "url": "/assets/drop-shirt-2.png", + "altText": "Shirt", + "width": 1000, + "height": 1000 + }, + { + "url": "/assets/drop-shirt-3.png", + "altText": "Shirt", + "width": 1000, + "height": 1000 } ], - "variants": [], - "options": [] + "variants": [ + { + "id": "Z2lkOi8vc2hvcGlmeS9Qcm9kdWN0LzU0NDczMjUwMjQ0MjAss=", + "options": [ + { + "__typename": "MultipleChoiceOption", + "id": "asd", + "displayName": "Size", + "values": [ + { + "label": "XL" + } + ] + } + ] + } + ], + "options": [ + { + "id": "option-color", + "displayName": "Color", + "values": [ + { + "label": "color", + "hexColors": ["#222"] + } + ] + }, + { + "id": "option-size", + "displayName": "Size", + "values": [ + { + "label": "S" + }, + { + "label": "M" + }, + { + "label": "L" + } + ] + } + ] } ] } diff --git a/framework/local/product/use-search.tsx b/framework/local/product/use-search.tsx index 058b614da..30e699537 100644 --- a/framework/local/product/use-search.tsx +++ b/framework/local/product/use-search.tsx @@ -8,6 +8,10 @@ export const handler: SWRHook = { }, async fetcher({ input, options, fetch }) {}, useHook: () => () => { - return {} + return { + data: { + products: [], + }, + } }, }