From 9ea66f439659c6851e789a0e5d98321b17e59640 Mon Sep 17 00:00:00 2001 From: Nikolaj Frey Date: Mon, 14 Aug 2023 12:58:50 +1000 Subject: [PATCH] feat: feature/mvp-sprint-1 Added type settings menu dropdown --- remix/app/components/Icon/Icon.tsx | 12 ++ .../app/components/Thingtime/SettingsMenu.tsx | 128 ++++++++++++++++++ remix/app/components/Thingtime/Thingtime.tsx | 35 +++++ 3 files changed, 175 insertions(+) create mode 100644 remix/app/components/Thingtime/SettingsMenu.tsx diff --git a/remix/app/components/Icon/Icon.tsx b/remix/app/components/Icon/Icon.tsx index 7a04ddd..073139b 100644 --- a/remix/app/components/Icon/Icon.tsx +++ b/remix/app/components/Icon/Icon.tsx @@ -18,6 +18,9 @@ export const Icon = (props) => { if (["sparke", "magic"]?.includes(name)) { return "✨" } + if (["wizard", "gandalf"]?.includes(name)) { + return "🧙‍♂️" + } if (["box", "thing", "object"]?.includes(name)) { return "📦" } @@ -30,6 +33,9 @@ export const Icon = (props) => { if (["book", "books"]?.includes(name)) { return "📚" } + if (["any", "magic wand"]?.includes(name)) { + return "🪄" + } if (["book-open", "books-open"]?.includes(name)) { return "📖" } @@ -39,6 +45,9 @@ export const Icon = (props) => { if (["number", "hundred"]?.includes(name)) { return "💯" } + if (["puzzle", "types"]?.includes(name)) { + return "🧩" + } if (["heart"]?.includes(name)) { return "❤️" } @@ -162,6 +171,9 @@ export const Icon = (props) => { if (["money bag"]?.includes(name)) { return "💰" } + if (["cyclone", "tornado"]?.includes(name)) { + return "🌀" + } if (["thingtime"]?.includes(name)) { if (Math.random() > 0.5) { return "🌳" diff --git a/remix/app/components/Thingtime/SettingsMenu.tsx b/remix/app/components/Thingtime/SettingsMenu.tsx new file mode 100644 index 0000000..3cdc21b --- /dev/null +++ b/remix/app/components/Thingtime/SettingsMenu.tsx @@ -0,0 +1,128 @@ +import React, { useState } from "react" +import { Center, Flex, Text } from "@chakra-ui/react" + +import { Icon } from "../Icon/Icon" + +export const SettingsMenu = (props) => { + const [show, setShow] = useState(false) + + const showMenu = React.useCallback(() => { + setShow(true) + }, []) + + const hideMenu = React.useCallback(() => { + setShow(false) + }, []) + + const basePadding = React.useMemo(() => { + return 4 + }, []) + + const types = React.useMemo(() => { + const ret = ["any", "object", "array", "string", "number", "boolean"] + return ret + }, []) + + const onChangeType = React.useCallback( + (type) => { + props?.onChangeType?.(type) + }, + [props?.onChangeType] + ) + + const iconSize = 10 + + return ( +
+ + + + + + + + + Types + + + + {types.map((type, idx) => { + const ret = ( + div": { + background: "greys.light", + }, + }} + onClick={() => onChangeType(type?.key || type)} + paddingY={1} + > + + + + {type?.label || type?.key || type} + + + + ) + return ret + })} + + + +
+ ) +} diff --git a/remix/app/components/Thingtime/Thingtime.tsx b/remix/app/components/Thingtime/Thingtime.tsx index d87e8cd..4c6196f 100644 --- a/remix/app/components/Thingtime/Thingtime.tsx +++ b/remix/app/components/Thingtime/Thingtime.tsx @@ -21,6 +21,7 @@ import { Commander } from "../Commander/Commander" import { Icon } from "../Icon/Icon" import { MagicInput } from "../MagicInput/MagicInput" import { Safe } from "../Safety/Safe" +import { SettingsMenu } from "./SettingsMenu" import { useThingtime } from "./useThingtime" import { getThing } from "~/smarts" @@ -370,6 +371,33 @@ export const Thingtime = (props) => { updateValue({ value: null }) }, [updateValue]) + const onChangeType = React.useCallback( + (type) => { + const newType = type?.key || type?.value || type + + if (newType === "object") { + updateValue({ value: {} }) + } else if (newType === "array") { + updateValue({ value: [] }) + } else if (newType === "string") { + updateValue({ value: "" }) + } else if (newType === "number") { + updateValue({ value: 0 }) + } else if (newType === "boolean") { + updateValue({ value: false }) + } else if (newType === "undefined") { + updateValue({ value: undefined }) + } else if (newType === "null") { + updateValue({ value: null }) + } else if (newType === "any") { + updateValue({ value: null }) + } else { + console.error("Unknown type", newType) + } + }, + [updateValue] + ) + const deleteValue = React.useCallback(() => { // use parent path to clone parent object but without this key const clone = { ...parent } @@ -659,6 +687,13 @@ export const Thingtime = (props) => { > +