feat: main Added click away logic to commander

This commit is contained in:
Nikolaj Frey 2023-07-02 00:49:01 +10:00
parent a95e6833fb
commit 0a99a50746
3 changed files with 125 additions and 103 deletions

View File

@ -3,6 +3,7 @@ import { Center, Box, Flex, Input } from '@chakra-ui/react'
import { useThingtime } from '../Thingtime/useThingtime'
import { Thingtime } from '../Thingtime/Thingtime'
import { sanitise } from '~/functions/path'
import ClickAwayListener from 'react-click-away-listener'
export const Commander = props => {
const { thingtime, setThingtime, getThingtime, thingtimeRef } = useThingtime()
@ -175,7 +176,12 @@ export const Commander = props => {
const fn = `() => { return ${escapedCommandValue} }`
const evalFn = eval(fn)
const realVal = evalFn()
const prevVal = getThingtime(commandPath)
setThingtime(commandPath, realVal)
if (!prevVal) {
setContextPath(commandPath)
setShowContext(true, 'commandIsAction check')
}
} catch (err) {
console.log('setThingtime errored in Commander', err)
}
@ -277,6 +283,7 @@ export const Commander = props => {
}, [])
return (
<ClickAwayListener onClickAway={closeCommander}>
<Flex
id='commander'
// display={['flex', showCommander ? 'flex' : 'none']}
@ -395,5 +402,6 @@ export const Commander = props => {
></Input>
</Center>
</Flex>
</ClickAwayListener>
)
}

View File

@ -15,6 +15,7 @@
"isbot": "latest",
"lodash-es": "^4.17.21",
"react": "^18.2.0",
"react-click-away-listener": "^2.2.3",
"react-dom": "^18.2.0",
"uuid": "^9.0.0"
},

View File

@ -32,6 +32,9 @@ dependencies:
react:
specifier: ^18.2.0
version: 18.2.0
react-click-away-listener:
specifier: ^2.2.3
version: 2.2.3(react-dom@18.2.0)(react@18.2.0)
react-dom:
specifier: ^18.2.0
version: 18.2.0(react@18.2.0)
@ -7644,6 +7647,16 @@ packages:
iconv-lite: 0.4.24
unpipe: 1.0.0
/react-click-away-listener@2.2.3(react-dom@18.2.0)(react@18.2.0):
resolution: {integrity: sha512-p63JRQtK9d085+QHUJ2Pje22P/N4tEaXsS2x7tbbptriQqZ9o8xEk7G1JrxwND5YmEVc/VO4fC3+cSBsqqgLUQ==}
peerDependencies:
react: ^16.8.0 || ^17.0.0 || ^18.0.0
react-dom: ^16.8.0 || ^17.0.0 || ^18.0.0
dependencies:
react: 18.2.0
react-dom: 18.2.0(react@18.2.0)
dev: false
/react-clientside-effect@1.2.6(react@18.2.0):
resolution: {integrity: sha512-XGGGRQAKY+q25Lz9a/4EPqom7WRjz3z9R2k4jhVKA/puQFH/5Nt27vFZYql4m4NVNdUvX8PS3O7r/Zzm7cjUlg==}
peerDependencies: