🚸 (pictureChoice) Improve single picture choice with same titles
Closes #859
This commit is contained in:
@@ -68,22 +68,18 @@ export const parsePictureChoicesReply =
|
|||||||
.join(', '),
|
.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(
|
const longestItemsFirst = [...displayedItems].sort(
|
||||||
(a, b) => (b.title?.length ?? 0) - (a.title?.length ?? 0)
|
(a, b) => (b.title?.length ?? 0) - (a.title?.length ?? 0)
|
||||||
)
|
)
|
||||||
const matchedItem = longestItemsFirst.find(
|
const matchedItem = longestItemsFirst.find(
|
||||||
(item) =>
|
(item) =>
|
||||||
item.title &&
|
item.id === inputValue ||
|
||||||
item.title
|
item.title
|
||||||
.toLowerCase()
|
?.toLowerCase()
|
||||||
|
.trim()
|
||||||
|
.includes(inputValue.toLowerCase().trim()) ||
|
||||||
|
item.pictureSrc
|
||||||
|
?.toLowerCase()
|
||||||
.trim()
|
.trim()
|
||||||
.includes(inputValue.toLowerCase().trim())
|
.includes(inputValue.toLowerCase().trim())
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@typebot.io/js",
|
"name": "@typebot.io/js",
|
||||||
"version": "0.1.31",
|
"version": "0.1.32",
|
||||||
"description": "Javascript library to display typebots on your website",
|
"description": "Javascript library to display typebots on your website",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
|||||||
@@ -20,10 +20,10 @@ export const SinglePictureChoice = (props: Props) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const handleClick = (itemIndex: number) => {
|
const handleClick = (itemIndex: number) => {
|
||||||
const pictureSrc = filteredItems()[itemIndex].pictureSrc
|
const item = filteredItems()[itemIndex]
|
||||||
if (!pictureSrc) return
|
|
||||||
return props.onSubmit({
|
return props.onSubmit({
|
||||||
value: filteredItems()[itemIndex].title ?? pictureSrc,
|
label: item.title ?? item.pictureSrc ?? item.id,
|
||||||
|
value: item.id,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@typebot.io/nextjs",
|
"name": "@typebot.io/nextjs",
|
||||||
"version": "0.1.31",
|
"version": "0.1.32",
|
||||||
"description": "Convenient library to display typebots on your Next.js website",
|
"description": "Convenient library to display typebots on your Next.js website",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@typebot.io/react",
|
"name": "@typebot.io/react",
|
||||||
"version": "0.1.31",
|
"version": "0.1.32",
|
||||||
"description": "Convenient library to display typebots on your React app",
|
"description": "Convenient library to display typebots on your React app",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
|
|||||||
Reference in New Issue
Block a user