diff --git a/remix/app/components/Thingtime/Thingtime.tsx b/remix/app/components/Thingtime/Thingtime.tsx
index b2801b4..1c8c599 100644
--- a/remix/app/components/Thingtime/Thingtime.tsx
+++ b/remix/app/components/Thingtime/Thingtime.tsx
@@ -1,7 +1,13 @@
import React from 'react'
import { Box, Flex } from '@chakra-ui/react'
+import { safe } from '~/functions/safe'
export const Thingtime = props => {
+ // const cuid = React.useMemo(() => {
+ // return Math.random().toString(36).substring(7)
+ // }, [])
+ const cuid = React.useRef(Math.random().toString(36).substring(7))
+
const thing = React.useMemo(() => {
return props.thing
}, [props.thing])
@@ -90,20 +96,8 @@ export const Thingtime = props => {
return ret
}, [thing])
- // do not render more than the limit of things to prevent infinite loops
- try {
- if (
- typeof window?.thingtime?.things?.count === 'number' &&
- window?.thingtime?.things?.count > window?.thingtime?.things?.limit
- ) {
- console.error('Maximum things reached')
- return null
- }
- } catch (err) {
- // console.error('Error in Thingtime.tsx checking maximum things', err)
- }
-
- let ret = null
+ let value = null
+ let editableValue = null
const keysToUse = keys
// const keysToUse = flattenedKeys
@@ -113,7 +107,7 @@ export const Thingtime = props => {
if (template1Modes?.includes(mode)) {
console.log('nik keys', keys)
if (keys?.length) {
- ret = (
+ value = (
{
)
} else {
- ret = (
-
- {props?.key?.human}
-
- {renderableValue}
-
-
+ editableValue = (
+
+ {renderableValue}
+
)
}
}
const contextMenu = (
-
+
Settings
)
const [showContextMenu, setShowContextMenu] = React.useState(false)
- return (
+ const path = React.useMemo(() => {
+ return {props?.path?.human}
+ }, [props?.path])
+
+ const handleMouseEvent = React.useCallback(
+ e => {
+ const target = e?.target
+ // extract cuid from className
+ console.log('nik eh', target?.className, cuid)
+ const className = target?.className
+ if (className?.includes(cuid?.current)) {
+ setShowContextMenu(e?.type === 'mouseenter')
+ }
+ },
+ [cuid]
+ )
+
+ console.log('nik cuid', cuid)
+
+ return safe(
setShowContextMenu(true)}
- onMouseLeave={() => setShowContextMenu(false)}
+ onMouseEnter={handleMouseEvent}
+ onMouseLeave={handleMouseEvent}
position='relative'
+ flexDir='column'
+ py={3}
{...props}
+ className={`thing-${cuid?.current}`}
>
+ {cuid?.current}
+ {path}
{showContextMenu && contextMenu}
- {ret}
+ {editableValue}
+ {value}
)
}
diff --git a/remix/app/components/Thingtime/ThingtimeDemo.tsx b/remix/app/components/Thingtime/ThingtimeDemo.tsx
index 6da1060..68cb15d 100644
--- a/remix/app/components/Thingtime/ThingtimeDemo.tsx
+++ b/remix/app/components/Thingtime/ThingtimeDemo.tsx
@@ -1,8 +1,7 @@
-import React from "react"
-import { Thingtime } from "./Thingtime"
+import React from 'react'
+import { Thingtime } from './Thingtime'
export const ThingtimeDemo = props => {
-
const thing = {
name: 'thing',
description: 'thing description',
@@ -20,8 +19,10 @@ export const ThingtimeDemo = props => {
}
const [demoThing, setDemoThing] = React.useState(thing)
-
-
- return
-}
\ No newline at end of file
+ const debug = {
+ test: 'hey'
+ }
+
+ return
+}
diff --git a/remix/app/functions/safe.tsx b/remix/app/functions/safe.tsx
new file mode 100644
index 0000000..4d5dbf6
--- /dev/null
+++ b/remix/app/functions/safe.tsx
@@ -0,0 +1,16 @@
+export const safe = response => {
+ // do not render more than the limit of things to prevent infinite loops
+ try {
+ if (
+ typeof window?.thingtime?.things?.count === 'number' &&
+ window?.thingtime?.things?.count > window?.thingtime?.things?.limit
+ ) {
+ console.error('Maximum things reached')
+ return null
+ }
+ } catch (err) {
+ // console.error('Error in Thingtime.tsx checking maximum things', err)
+ }
+
+ return response
+}