Skip to content

Commit

Permalink
🚸 (pictureChoice) Improve single picture choice with same titles
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno authored and jmgoncalves97 committed Jan 17, 2025
1 parent 1b4dce9 commit 6a14e3a
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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())
)
Expand Down
2 changes: 1 addition & 1 deletion packages/embeds/js/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
}

Expand Down
2 changes: 1 addition & 1 deletion packages/embeds/nextjs/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/embeds/react/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 6a14e3a

Please sign in to comment.