Skip to content

Commit

Permalink
🐛 (condition) Greater and Less should compare list length when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Apr 20, 2023
1 parent 4d1fe4c commit c77b8e7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 18 deletions.
32 changes: 16 additions & 16 deletions apps/viewer/src/features/blocks/logic/condition/executeCondition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,24 +63,24 @@ const executeComparison =
return compare((a, b) => a !== b, inputValue, value)
}
case ComparisonOperators.GREATER: {
return compare(
(a, b) =>
isDefined(a) && isDefined(b)
? parseFloat(a) > parseFloat(b)
: false,
inputValue,
value
)
if (typeof inputValue === 'string') {
if (typeof value === 'string')
return parseFloat(inputValue) > parseFloat(value)
return parseFloat(inputValue) > value.length
}
if (typeof value === 'string')
return inputValue.length > parseFloat(value)
return inputValue.length > value.length
}
case ComparisonOperators.LESS: {
return compare(
(a, b) =>
isDefined(a) && isDefined(b)
? parseFloat(a) < parseFloat(b)
: false,
inputValue,
value
)
if (typeof inputValue === 'string') {
if (typeof value === 'string')
return parseFloat(inputValue) < parseFloat(value)
return parseFloat(inputValue) < value.length
}
if (typeof value === 'string')
return inputValue.length < parseFloat(value)
return inputValue.length < value.length
}
case ComparisonOperators.IS_SET: {
return isDefined(inputValue) && inputValue.length > 0
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.0.37",
"version": "0.0.38",
"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 @@ -29,6 +29,11 @@ export const TextInput = (props: Props) => {
if (e.key === 'Enter') submit()
}

const submitIfCtrlEnter = (e: KeyboardEvent) => {
if (!props.block.options.isLong) return
if (e.key === 'Enter' && (e.metaKey || e.ctrlKey)) submit()
}

onMount(() => {
if (!isMobile() && inputRef) inputRef.focus()
})
Expand All @@ -46,6 +51,7 @@ export const TextInput = (props: Props) => {
<Textarea
ref={inputRef as HTMLTextAreaElement}
onInput={handleInput}
onKeyDown={submitIfCtrlEnter}
value={inputValue()}
placeholder={
props.block.options?.labels?.placeholder ?? 'Type your answer...'
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.0.37",
"version": "0.0.38",
"description": "React library to display typebots on your website",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down

0 comments on commit c77b8e7

Please sign in to comment.