From 6a14e3a509169c3afec8ff33f201d5bc6e974a98 Mon Sep 17 00:00:00 2001 From: Baptiste Arnaud Date: Thu, 28 Sep 2023 15:35:21 +0200 Subject: [PATCH] :children_crossing: (pictureChoice) Improve single picture choice with same titles Closes #859 --- .../pictureChoice/parsePictureChoicesReply.ts | 16 ++++++---------- packages/embeds/js/package.json | 2 +- .../inputs/pictureChoice/SinglePictureChoice.tsx | 6 +++--- packages/embeds/nextjs/package.json | 2 +- packages/embeds/react/package.json | 2 +- 5 files changed, 12 insertions(+), 16 deletions(-) diff --git a/packages/bot-engine/blocks/inputs/pictureChoice/parsePictureChoicesReply.ts b/packages/bot-engine/blocks/inputs/pictureChoice/parsePictureChoicesReply.ts index f98a4ff0e61..7271948d2e2 100644 --- a/packages/bot-engine/blocks/inputs/pictureChoice/parsePictureChoicesReply.ts +++ b/packages/bot-engine/blocks/inputs/pictureChoice/parsePictureChoicesReply.ts @@ -68,22 +68,18 @@ export const parsePictureChoicesReply = .join(', '), } } - if (state.whatsApp) { - const matchedItem = displayedItems.find((item) => item.id === inputValue) - if (!matchedItem) return { status: 'fail' } - return { - status: 'success', - reply: matchedItem.title ?? matchedItem.pictureSrc ?? '', - } - } const longestItemsFirst = [...displayedItems].sort( (a, b) => (b.title?.length ?? 0) - (a.title?.length ?? 0) ) const matchedItem = longestItemsFirst.find( (item) => - item.title && + item.id === inputValue || item.title - .toLowerCase() + ?.toLowerCase() + .trim() + .includes(inputValue.toLowerCase().trim()) || + item.pictureSrc + ?.toLowerCase() .trim() .includes(inputValue.toLowerCase().trim()) ) diff --git a/packages/embeds/js/package.json b/packages/embeds/js/package.json index 7b3e77b165e..776793453f1 100644 --- a/packages/embeds/js/package.json +++ b/packages/embeds/js/package.json @@ -1,6 +1,6 @@ { "name": "@typebot.io/js", - "version": "0.1.31", + "version": "0.1.32", "description": "Javascript library to display typebots on your website", "type": "module", "main": "dist/index.js", diff --git a/packages/embeds/js/src/features/blocks/inputs/pictureChoice/SinglePictureChoice.tsx b/packages/embeds/js/src/features/blocks/inputs/pictureChoice/SinglePictureChoice.tsx index 33c618665e1..0f4bc9a5e07 100644 --- a/packages/embeds/js/src/features/blocks/inputs/pictureChoice/SinglePictureChoice.tsx +++ b/packages/embeds/js/src/features/blocks/inputs/pictureChoice/SinglePictureChoice.tsx @@ -20,10 +20,10 @@ export const SinglePictureChoice = (props: Props) => { }) const handleClick = (itemIndex: number) => { - const pictureSrc = filteredItems()[itemIndex].pictureSrc - if (!pictureSrc) return + const item = filteredItems()[itemIndex] return props.onSubmit({ - value: filteredItems()[itemIndex].title ?? pictureSrc, + label: item.title ?? item.pictureSrc ?? item.id, + value: item.id, }) } diff --git a/packages/embeds/nextjs/package.json b/packages/embeds/nextjs/package.json index e5f3503d35c..b50ae0a5c14 100644 --- a/packages/embeds/nextjs/package.json +++ b/packages/embeds/nextjs/package.json @@ -1,6 +1,6 @@ { "name": "@typebot.io/nextjs", - "version": "0.1.31", + "version": "0.1.32", "description": "Convenient library to display typebots on your Next.js website", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/packages/embeds/react/package.json b/packages/embeds/react/package.json index eeaec2afc95..75630065c51 100644 --- a/packages/embeds/react/package.json +++ b/packages/embeds/react/package.json @@ -1,6 +1,6 @@ { "name": "@typebot.io/react", - "version": "0.1.31", + "version": "0.1.32", "description": "Convenient library to display typebots on your React app", "main": "dist/index.js", "types": "dist/index.d.ts",