deep-foundation / deep-memo-app

The Unlicense
11 stars 8 forks source link

Add client handler with timeline #142

Open FreePhoenix888 opened 11 months ago

FreePhoenix888 commented 11 months ago

https://www.npmjs.com/package/react-calendar-timeline https://www.npmjs.com/package/ymaps

FreePhoenix888 commented 10 months ago

Draft:

async ({ deep, require }) => {
  const React = require('react');
  const { YMaps, Map, Placemark } = require('@pbe/react-yandex-maps');
  const {default: Timeline} = require('react-calendar-timeline')
  const moment = require('moment')
  console.log({Timeline})

  const { Text, VStack, Box } = require('@chakra-ui/react');  

  return ({ fillSize, style, link }) => {
      const defaultState = {
    center: [55.751574, 37.573856],
    zoom: 5,
  };

  const groups = [{ id: 1, title: 'group 1' }, { id: 2, title: 'group 2' }]

const items = [
  {
    id: 1,
    group: 1,
    title: 'item 1',
    start_time: moment(),
    end_time: moment().add(1, 'hour')
  },
  {
    id: 2,
    group: 2,
    title: 'item 2',
    start_time: moment().add(-0.5, 'hour'),
    end_time: moment().add(0.5, 'hour')
  }, 
  {
    id: 3,
    group: 1,
    title: 'item 3',
    start_time: moment().add(2, 'hour'),
    end_time: moment().add(3, 'hour')
  }
]
  return <Box
      style={{ ...style,width: 800, height: 600 }}
      bg={'bgColor'}
      color={'text'}
      borderColor={'borderColor'}
      borderWidth='thin' borderRadius='lg'
      p={1}
  ><Timeline
      groups={groups}
      items={items}
      defaultTimeStart={moment().add(-12, 'hour')}
      defaultTimeEnd={moment().add(12, 'hour')}
    /></Box>
  // return (
  //   <VStack>
  //   <Timeline
  //     groups={groups}
  //     items={items}
  //     defaultTimeStart={moment().add(-12, 'hour')}
  //     defaultTimeEnd={moment().add(12, 'hour')}
  //   />
  //   <YMaps>
  //     <Map defaultState={defaultState}>
  //       <Placemark geometry={[55.684758, 37.738521]} />
  //     </Map>
  //   </YMaps>
  //   </VStack>
  // );
  //   return <Text>UI for {link.id} goes herse.</Text>;
  // }
}
FreePhoenix888 commented 10 months ago

Draft v2

async ({ deep, require }) => {
  const React = require('react');
  const { YMaps, Map, Placemark } = require('@pbe/react-yandex-maps');
  const { default: Timeline } = require('react-calendar-timeline')
  const moment = require('moment')
  console.log({ Timeline })

  const { Text, VStack, Box } = require('@chakra-ui/react');
  const containTreeLinkId = deep.idLocal("@deep-foundation/core", "containTree")
  const positionTypeLinkId = await deep.id("@deep-foundation/capacitor-geolocation", "Position")
  return ({ fillSize, style, link: deviceLink }) => {
    const deviceLinkId = 3088
    const { data: deviceLinkDataLinks } = deep.useDeepSubscription({
      up: {
        tree_id: { _eq: containTreeLinkId },
        parent_id: deviceLinkId
      },
      type_id: positionTypeLinkId
    })   
    console.log({ deviceLinkDataLinks })
    const positionLinks = deviceLinkDataLinks.filter(link => link.type_id === positionTypeLinkId)
    if(positionLinks.length > 0) {
positionLinks.push({
      ...positionLinks[0],
    }) 
    console.log('positionLinks[1].value.value.coords.latitude', positionLinks[1].value.value.coords.latitude)
    positionLinks[1].value.value.coords.latitude = positionLinks[1].value.value.coords.latitude+1
    console.log('positionLinks[1].value.value.coords.latitude after change', positionLinks[1].value.value.coords.latitude)
        positionLinks[1].value.value.coords.longitude = positionLinks[1].value.value.coords.longitude+1
    }

    console.log({ positionLinks })
    console.log(positionLinks[0]?.value.value.coords.latitude)
    console.log(positionLinks[0]?.value.value.coords.longitude)

    const defaultState = {
      center: [55.751574, 37.573856],
      zoom: 5,
    };

    const groups = [{ id: 1, title: 'group 1' }, { id: 2, title: 'group 2' }]

    const items = [
      {
        id: 1,
        group: 1,
        title: 'item 1',
        start_time: moment(),
        end_time: moment().add(1, 'hour')
      },
      {
        id: 2,
        group: 2,
        title: 'item 2',
        start_time: moment().add(-0.5, 'hour'),
        end_time: moment().add(0.5, 'hour')
      },
      {
        id: 3,
        group: 1,
        title: 'item 3',
        start_time: moment().add(2, 'hour'),
        end_time: moment().add(3, 'hour')
      }
    ]  
    return ( 
      <Box
  style={{ ...style, width: 800, height: 600 }}
  bg={"bgColor"}
  color={"text"}
  borderColor={"borderColor"}
  borderWidth="thin"
  borderRadius="lg"
  p={1}
  spacing={4}
  align="stretch"
>
  <Box flex={1}>
    <Timeline
      groups={groups}
      items={items}
      defaultTimeStart={moment().add(-12, "hour")}
      defaultTimeEnd={moment().add(12, "hour")}
      flex={1}
    />
  </Box>
  <Box flex={1}>
    <YMaps>
      <Map defaultState={defaultState}>
        {
          positionLinks.map(positionLink => (
            <Placemark geometry={[positionLink.value.value.coords.latitude, positionLink.value.value.coords.longitude]} />
          ))
        }
      </Map>
    </YMaps>
  </Box>
</Box>;

    )
  return <Text>U121435</Text>;
}
}
FreePhoenix888 commented 10 months ago

Not-Working Draft v3

async ({ deep, require }) => {
  const React = require("react");
  const { YMaps, Map, Placemark } = require("@pbe/react-yandex-maps");
  const { default: Timeline } = require("react-calendar-timeline");
  const moment = require("moment");
  const {
    FinderPopover,
  } = require("@deep-foundation/deepcase/imports/cyto/hooks");
  console.log({ FinderPopover });

  const { Text, VStack, Box, IconButton } = require("@chakra-ui/react");
  const containTreeLinkId = deep.idLocal(
    "@deep-foundation/core",
    "containTree"
  );
  const positionTypeLinkId = await deep.id(
    "@deep-foundation/capacitor-geolocation",
    "Position"
  );
  return ({ fillSize, style, link: deviceLink }) => {
    const deviceLinkId = 3088;
    const { data: deviceLinkDataLinks } = deep.useDeepSubscription({
      up: {
        tree_id: { _eq: containTreeLinkId },
        parent_id: deviceLinkId,
      },
      type_id: positionTypeLinkId,
    });
    console.log({ deviceLinkDataLinks });
    const positionLinks = deviceLinkDataLinks.filter(
      (link) => link.type_id === positionTypeLinkId
    );
    if (positionLinks.length > 0) {
      positionLinks.push({
        ...positionLinks[0],
      });
      console.log(
        "positionLinks[1].value.value.coords.latitude",
        positionLinks[1].value.value.coords.latitude
      );
      positionLinks[1].value.value.coords.latitude =
        positionLinks[1].value.value.coords.latitude + 1;
      console.log(
        "positionLinks[1].value.value.coords.latitude after change",
        positionLinks[1].value.value.coords.latitude
      );
      positionLinks[1].value.value.coords.longitude =
        positionLinks[1].value.value.coords.longitude + 1;
    }

    console.log({ positionLinks });
    console.log(positionLinks[0]?.value.value.coords.latitude);
    console.log(positionLinks[0]?.value.value.coords.longitude);

    const defaultState = {
      center: [55.751574, 37.573856],
      zoom: 5,
    };

    const groups = [
      { id: 1, title: "group 1" },
      { id: 2, title: "group 2" },
    ];

    const items = [
      {
        id: 1,
        group: 1,
        title: "item 1",
        start_time: moment(),
        end_time: moment().add(1, "hour"),
      },
      {
        id: 2,
        group: 2,
        title: "item 2",
        start_time: moment().add(-0.5, "hour"),
        end_time: moment().add(0.5, "hour"),
      },
      {
        id: 3,
        group: 1,
        title: "item 3",
        start_time: moment().add(2, "hour"),
        end_time: moment().add(3, "hour"),
      },
    ];
    const containerRef = React.useRef();
    return (
      <Box
        style={{ ...style, width: 800, height: 600 }}
        bg={"bgColor"}
        color={"text"}
        borderColor={"borderColor"}
        borderWidth="thin"
        borderRadius="lg"
        p={1}
        spacing={4}
        align="stretch"
      >
        <Box flex={1} ref={containerRef}>
          <Timeline
            groups={groups}
            items={items}
            defaultTimeStart={moment().add(-12, "hour")}
            defaultTimeEnd={moment().add(12, "hour")}
            flex={1}
          />
          <FinderPopover
            PortalProps={{
              containerRef: containerRef,
            }}
            link={3097}
          >
            <IconButton
              isRound
              aria-label="finder"
              size="sm"
              variant="ghost"
              icon={<>🪬</>}
              style={{
                position: "relative",
                top: -4,
              }}
            />
          </FinderPopover>
        </Box>
        <Box flex={1}>
          <YMaps>
            <Map defaultState={defaultState}>
              {positionLinks.map((positionLink) => (
                <Placemark
                  geometry={[
                    positionLink.value.value.coords.latitude,
                    positionLink.value.value.coords.longitude,
                  ]}
                />
              ))}
            </Map>
          </YMaps>
        </Box>
      </Box>
    );
    return <Text>U121435</Text>;
  };
};

Error

Warning: Cannot update a component (`Content`) while rendering a different component (`FinderPopover`). To locate the bad setState() call inside `FinderPopover`, follow the stack trace as described in https://reactjs.org/link/setstate-in-render
    at FinderPopover (webpack-internal:///../deepcase/imports/cyto/hooks.js:57:88)
    at div
    at eval (webpack-internal:///../../node_modules/@emotion/react/dist/emotion-element-c39617d8.browser.esm.js:60:66)
    at ChakraComponent (webpack-internal:///../../node_modules/@chakra-ui/system/dist/chunk-5PL47M24.mjs:50:102)
    at ButtonContent (webpack-internal:///../../node_modules/@chakra-ui/button/dist/chunk-UVUR7MCU.mjs:103:11)
    at button
    at eval (webpack-internal:///../../node_modules/@emotion/react/dist/emotion-element-c39617d8.browser.esm.js:60:66)
    at ChakraComponent (webpack-internal:///../../node_modules/@chakra-ui/system/dist/chunk-5PL47M24.mjs:50:102)
    at eval (webpack-internal:///../../node_modules/@chakra-ui/button/dist/chunk-UVUR7MCU.mjs:27:84)
    at Item (webpack-internal:///../deepcase/imports/cyto/editor.js:145:70)
    at div
    at CytoEditorNav (webpack-internal:///../deepcase/imports/cyto/editor.js:199:88)
    at div
    at MotionComponent (webpack-internal:///../../node_modules/framer-motion/dist/es/motion/index.mjs:49:65)
    at div
    at ResizeDetector (webpack-internal:///../../node_modules/react-resize-detector/build/index.esm.js:82:28)
    at VerticalSash (webpack-internal:///../deepcase/imports/editor/editor-grid.js:23:25)
    at div
    at eval (webpack-internal:///../../node_modules/@emotion/react/dist/emotion-element-c39617d8.browser.esm.js:60:66)
    at ChakraComponent (webpack-internal:///../../node_modules/@chakra-ui/system/dist/chunk-5PL47M24.mjs:50:102)
    at eval (webpack-internal:///../deepcase/imports/editor/editor-grid.js:16:63)
    at section
    at MotionComponent (webpack-internal:///../../node_modules/framer-motion/dist/es/motion/index.mjs:49:65)
    at eval (webpack-internal:///../../node_modules/@emotion/react/dist/emotion-element-c39617d8.browser.esm.js:60:66)
    at ChakraComponent (webpack-internal:///../../node_modules/@chakra-ui/system/dist/chunk-5PL47M24.mjs:50:102)
    at eval (webpack-internal:///../../node_modules/@chakra-ui/modal/dist/chunk-7NUJBCEL.mjs:47:13)
    at div
    at eval (webpack-internal:///../../node_modules/@emotion/react/dist/emotion-element-c39617d8.browser.esm.js:60:66)
    at ChakraComponent (webpack-internal:///../../node_modules/@chakra-ui/system/dist/chunk-5PL47M24.mjs:50:102)
    at eval (webpack-internal:///../../node_modules/react-remove-scroll/dist/es2015/UI.js:23:50)
    at div
    at FocusLockUI (webpack-internal:///../../node_modules/react-focus-lock/dist/es2015/Lock.js:23:60)
    at FocusLockUICombination
    at FocusLock (webpack-internal:///../../node_modules/@chakra-ui/focus-lock/dist/chunk-UU5OHSNF.mjs:21:5)
    at ModalFocusScope (webpack-internal:///../../node_modules/@chakra-ui/modal/dist/chunk-NABYTFTG.mjs:35:75)
    at eval (webpack-internal:///../../node_modules/@chakra-ui/modal/dist/chunk-EL2VKIZQ.mjs:23:7)
    at DefaultPortal (webpack-internal:///../../node_modules/@chakra-ui/portal/dist/chunk-34PD6CUK.mjs:43:11)
    at Portal
    at PresenceChild (webpack-internal:///../../node_modules/framer-motion/dist/es/components/AnimatePresence/PresenceChild.mjs:15:26)
    at AnimatePresence (webpack-internal:///../../node_modules/framer-motion/dist/es/components/AnimatePresence/index.mjs:72:28)
    at Modal (webpack-internal:///../../node_modules/@chakra-ui/modal/dist/chunk-MSA2NPQT.mjs:59:88)
    at CytoEditor (webpack-internal:///../deepcase/imports/cyto/editor.js:219:95)
    at div
    at eval (webpack-internal:///../../node_modules/@emotion/react/dist/emotion-element-c39617d8.browser.esm.js:60:66)
    at ChakraComponent (webpack-internal:///../../node_modules/@chakra-ui/system/dist/chunk-5PL47M24.mjs:50:102)
    at div
    at eval (webpack-internal:///../../node_modules/@emotion/react/dist/emotion-element-c39617d8.browser.esm.js:60:66)
    at ChakraComponent (webpack-internal:///../../node_modules/@chakra-ui/system/dist/chunk-5PL47M24.mjs:50:102)
    at CytoDropZone (webpack-internal:///../deepcase/imports/cyto/drop-zone.js:29:86)
    at div
    at CytoGraph (webpack-internal:///../deepcase/imports/cyto/graph.js:102:22)
    at Content (webpack-internal:///./pages/index.tsx:62:11)
    at AutoGuest (webpack-internal:///../deepcase/imports/auto-guest.js:31:80)
    at CatchErrors (webpack-internal:///../deepcase/imports/react-errors.js:11:9)
    at DeepProvider (webpack-internal:///../deeplinks/imports/client.js:891:39)
    at ProviderConnected (webpack-internal:///../deepcase/imports/provider.js:25:30)
    at ApolloProvider (webpack-internal:///../../node_modules/@apollo/client/react/context/ApolloProvider.js:14:21)
    at ApolloClientRegenerator (webpack-internal:///../../node_modules/@deep-foundation/react-hasura/apollo-client-regenerator.js:43:88)
    at ApolloClientTokenizedProvider (webpack-internal:///../../node_modules/@deep-foundation/react-hasura/apollo-client-tokenized-provider.js:30:100)
    at TokenProvider (webpack-internal:///../deeplinks/imports/react-token.js:23:26)
    at LocalStoreProvider (webpack-internal:///../../node_modules/@deep-foundation/store/local.js:43:31)
    at CookiesStoreProviderCore (webpack-internal:///../../node_modules/@deep-foundation/store/cookies.js:43:37)
    at CookiesProvider (webpack-internal:///../../node_modules/react-cookie/es6/CookiesProvider.js:25:28)
    at CookiesStoreProvider (webpack-internal:///../../node_modules/@deep-foundation/store/cookies.js:37:33)
    at QueryStoreProvider (webpack-internal:///../../node_modules/@deep-foundation/store/query.js:41:31)
    at EnvironmentProvider (webpack-internal:///../../node_modules/@chakra-ui/react-env/dist/chunk-VMD3UMGK.mjs:34:11)
    at ColorModeProvider (webpack-internal:///../../node_modules/@chakra-ui/color-mode/dist/chunk-AMBGAKG2.mjs:29:5)
    at ThemeProvider (webpack-internal:///../../node_modules/@emotion/react/dist/emotion-element-c39617d8.browser.esm.js:123:50)
    at ThemeProvider (webpack-internal:///../../node_modules/@chakra-ui/system/dist/chunk-MFVQSVQB.mjs:28:11)
    at ChakraProvider (webpack-internal:///../../node_modules/@chakra-ui/provider/dist/chunk-3DDHO3UN.mjs:20:5)
    at ChakraProvider2 (webpack-internal:///../../node_modules/@chakra-ui/react/dist/chunk-QAITB7GG.mjs:19:5)
    at Provider (webpack-internal:///../deepcase/imports/provider.js:29:21)
    at Page (webpack-internal:///./pages/index.tsx:190:11)
    at App (webpack-internal:///./pages/_app.js:13:11)
    at PathnameContextProviderAdapter (webpack-internal:///../../node_modules/next/dist/shared/lib/router/adapters.js:74:11)
    at ErrorBoundary (webpack-internal:///../../node_modules/next/dist/compiled/@next/react-dev-overlay/dist/client.js:303:63)
    at ReactDevOverlay (webpack-internal:///../../node_modules/next/dist/compiled/@next/react-dev-overlay/dist/client.js:852:919)
    at Container (webpack-internal:///../../node_modules/next/dist/client/index.js:77:1)
    at AppContainer (webpack-internal:///../../node_modules/next/dist/client/index.js:181:11)
    at Root (webpack-internal:///../../node_modules/next/dist/client/index.js:360:11)

What I see

image

What is changed

I have added portal, FinderPopover, imports, ref