From cd828e95c5ad0d398ef8146efcb20addad03ea71 Mon Sep 17 00:00:00 2001 From: Michal Miszczyszyn Date: Tue, 2 May 2023 11:25:58 +0200 Subject: [PATCH] Fix missing block and functions --- app/sitemap.ts | 2 +- lib/saleor/editorjs.ts | 16 +++++++++++++++- lib/saleor/index.ts | 20 +++++++++++++++++++- package.json | 1 + pnpm-lock.yaml | 5 +++-- 5 files changed, 39 insertions(+), 5 deletions(-) diff --git a/app/sitemap.ts b/app/sitemap.ts index c205c55fb..16661cd25 100644 --- a/app/sitemap.ts +++ b/app/sitemap.ts @@ -5,7 +5,7 @@ const baseUrl = process.env.NEXT_PUBLIC_VERCEL_URL ? `https://${process.env.NEXT_PUBLIC_VERCEL_URL}` : 'http://localhost:3000'; -export default async function sitemap(): Promise>> { +export default async function sitemap(): Promise { const routesMap = ['', '/search'].map((route) => ({ url: `${baseUrl}${route}`, lastModified: new Date().toISOString() diff --git a/lib/saleor/editorjs.ts b/lib/saleor/editorjs.ts index 82c7dc948..a99e8de15 100644 --- a/lib/saleor/editorjs.ts +++ b/lib/saleor/editorjs.ts @@ -9,9 +9,17 @@ type EditorJsListBlock = { type: 'list'; data: { style: 'unordered' | 'ordered'; items: string[] }; }; +type EditorJsQuoteBlock = { + data: { text: string; caption: string; alignment: string }; + type: 'quote'; +}; type EditorJsBlockCommon = { id: string }; -type EditorJsBlocks = EditorJsHeaderBlock | EditorJsParagraphBlock | EditorJsListBlock; +type EditorJsBlocks = + | EditorJsHeaderBlock + | EditorJsParagraphBlock + | EditorJsListBlock + | EditorJsQuoteBlock; type EditorJsBlock = EditorJsBlocks & EditorJsBlockCommon; @@ -53,6 +61,8 @@ export const parseEditorJsToHtml = (content: string) => { return list(block.data); case 'paragraph': return paragraph(block.data); + case 'quote': + return quote(block.data); default: console.warn(`Unknown block type: ${JSON.stringify(block)}`); return ''; @@ -76,3 +86,7 @@ function paragraph({ text }: EditorJsParagraphBlock['data']): string { function header({ level, text }: EditorJsHeaderBlock['data']): string { return `${text}`; } + +function quote({ text, caption, alignment }: EditorJsQuoteBlock['data']): string { + return `

${text}

- ${caption}
`; +} diff --git a/lib/saleor/index.ts b/lib/saleor/index.ts index 5129dd6ad..3733a1638 100644 --- a/lib/saleor/index.ts +++ b/lib/saleor/index.ts @@ -385,7 +385,7 @@ export async function getProducts({ query: SearchProductsDocument, variables: { search: query || '', - sortBy: sortKey || ProductOrderField.Rank, + sortBy: sortKey || (query ? ProductOrderField.Rank : ProductOrderField.Rating), sortDirection: reverse ? OrderDirection.Desc : OrderDirection.Asc } }); @@ -487,3 +487,21 @@ export async function getProductRecommendations(productId: string): Promise { + // @todo + throw new Error(`Not implemented`); +} +export async function updateCart( + cartId: string, + lines: { id: string; merchandiseId: string; quantity: number }[] +): Promise { + // @todo + throw new Error(`Not implemented`); +} +export async function removeFromCart(cartId: string, lineIds: string[]): Promise { + // @todo + throw new Error(`Not implemented`); +} diff --git a/package.json b/package.json index 757145393..2781ba4d5 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "*": "prettier --write --ignore-unknown" }, "dependencies": { + "@graphql-typed-document-node/core": "3.2.0", "@headlessui/react": "^1.7.10", "@vercel/og": "^0.1.0", "clsx": "^1.2.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 00a1be9c0..96613c6e9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,6 +1,9 @@ lockfileVersion: '6.0' dependencies: + '@graphql-typed-document-node/core': + specifier: 3.2.0 + version: registry.npmjs.org/@graphql-typed-document-node/core@3.2.0(graphql@16.6.0) '@headlessui/react': specifier: ^1.7.10 version: 1.7.14(react-dom@18.2.0)(react@18.2.0) @@ -4917,7 +4920,6 @@ packages: graphql: ^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0 dependencies: graphql: registry.npmjs.org/graphql@16.6.0 - dev: true registry.npmjs.org/@jridgewell/gen-mapping@0.3.3: resolution: {integrity: sha512-HLhSWOLRi875zjjMG/r+Nv0oCW8umGb0BgEhyX3dDX3egwZtB8PqLnjz3yedt8R5StBrzcg4aBpnh8UA9D1BoQ==, registry: https://registry.npmjs.com/, tarball: https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.3.tgz} @@ -6075,7 +6077,6 @@ packages: name: graphql version: 16.6.0 engines: {node: ^12.22.0 || ^14.16.0 || ^16.0.0 || >=17.0.0} - dev: true registry.npmjs.org/has-flag@3.0.0: resolution: {integrity: sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==, registry: https://registry.npmjs.com/, tarball: https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz}