feat: feature/mvp-sprint-1 Added delete functionality

This commit is contained in:
Nikolaj Frey 2023-08-13 18:30:34 +10:00
parent e8ec2b156b
commit c3804ef93f
2 changed files with 31 additions and 3 deletions

View File

@ -126,6 +126,13 @@ export const ThingtimeProvider = (props: any): JSX.Element => {
const setThingtime = React.useCallback(
(path, value) => {
if (["thingtime", "tt"]?.includes(path)) {
if (value) {
set(value)
return
}
}
const newThingtime = thingtime
const paths = smarts.parsePropertyPath(path)
@ -163,6 +170,8 @@ export const ThingtimeProvider = (props: any): JSX.Element => {
}
})
// TODO: make thingtime settable
newThingtime.thingtime = newThingtime
newThingtime.tt = newThingtime
@ -175,6 +184,8 @@ export const ThingtimeProvider = (props: any): JSX.Element => {
smarts.setsmart(newThingtime, path, value)
console.log("nik set(newThingtime)", newThingtime)
set(newThingtime)
},
[thingtime, set]

View File

@ -23,6 +23,8 @@ import { MagicInput } from "../MagicInput/MagicInput"
import { Safe } from "../Safety/Safe"
import { useThingtime } from "./useThingtime"
import { getThing } from "~/smarts"
export const Thingtime = (props) => {
// TODO: Add a circular reference seen prop check
// and add button to expand circular reference
@ -123,6 +125,20 @@ export const Thingtime = (props) => {
return ret
}, [props?.fullPath, props?.path, props?.thing])
const parentPath = React.useMemo(() => {
const parentPath = fullPath.split(".").slice(0, -1).join(".")
if (!parentPath) {
return "thingtime"
}
return parentPath
}, [fullPath])
const parent = React.useMemo(() => {
return getThingtime(parentPath)
}, [parentPath, getThingtime])
React.useEffect(() => {
console.log("thingtime changed in path", props?.fullPath)
createDependancies()
@ -356,14 +372,15 @@ export const Thingtime = (props) => {
const deleteValue = React.useCallback(() => {
// use parent path to clone parent object but without this key
const parentPath = fullPath.split(".").slice(0, -1).join(".")
const parent = getThingtime(parentPath)
const clone = { ...parent }
delete clone[path]
console.log("nik parentPath", parentPath)
console.log("nik clone", clone)
setThingtime(parentPath, clone)
}, [fullPath, path, getThingtime, setThingtime])
}, [path, parent, parentPath, setThingtime])
const atomicValue = React.useMemo(() => {
if (props?.edit) {