From c3804ef93febd401c6246aaa4b00be21052d9ceb Mon Sep 17 00:00:00 2001 From: Nikolaj Frey Date: Sun, 13 Aug 2023 18:30:34 +1000 Subject: [PATCH] feat: feature/mvp-sprint-1 Added delete functionality --- remix/app/Providers/ThingtimeProvider.tsx | 11 ++++++++++ remix/app/components/Thingtime/Thingtime.tsx | 23 +++++++++++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/remix/app/Providers/ThingtimeProvider.tsx b/remix/app/Providers/ThingtimeProvider.tsx index d07c40e..0d1306c 100644 --- a/remix/app/Providers/ThingtimeProvider.tsx +++ b/remix/app/Providers/ThingtimeProvider.tsx @@ -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] diff --git a/remix/app/components/Thingtime/Thingtime.tsx b/remix/app/components/Thingtime/Thingtime.tsx index 823e764..512168b 100644 --- a/remix/app/components/Thingtime/Thingtime.tsx +++ b/remix/app/components/Thingtime/Thingtime.tsx @@ -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) {