{"size": 1287, "ext": "js", "max_stars_repo_path": "src/components/Share/QueryParamHandler.js", "max_stars_repo_name": "adamjarling/loc-speculative-annotation", "max_stars_repo_stars_event_min_datetime": "2021-03-16T01:46:49.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-22T05:14:29.000Z", "max_issues_repo_path": "src/components/Share/QueryParamHandler.js", "max_issues_repo_name": "adamjarling/loc-speculative-annotation", "max_issues_repo_issues_event_min_datetime": "2020-12-08T00:26:04.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-08T19:41:41.000Z", "max_forks_repo_path": "src/components/Share/QueryParamHandler.js", "max_forks_repo_name": "adamjarling/loc-speculative-annotation", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 12, "max_issues_count": 160, "max_forks_count": null, "avg_line_length": 30.6428571429, "max_line_length": 85, "alphanum_fraction": 0.6177156177}
import React from 'react';
import { useLocation } from 'react-router-dom';
import { useFabricOverlayState } from 'context/fabric-overlay-context';
import { useToast } from '@chakra-ui/react';
var codec = require('json-url')('lzma');

function ShareQueryParamHandler() {
  const { fabricOverlay } = useFabricOverlayState();
  const toast = useToast();
  const location = useLocation();
  const sharedCanvasParam = location.search.split('sharedCanvas=')[1];

  React.useEffect(() => {
    if (!fabricOverlay) {
      return;
    }
    if (sharedCanvasParam) {
      // A Fabric JS canvas object query param is passed to the url
      // Decode the value and add objects to the Fabric canvas
      codec
        .decompress(sharedCanvasParam)
        .then(json => {
          fabricOverlay.fabricCanvas().loadFromJSON(json);
        })
        .catch(error => {
          console.error('error', error);
          toast({
            title: 'Error displaying annotations',
            description:
              'There was an error decoding the shared annotations query param value',
            status: 'error',
            duration: 9000,
            isClosable: true,
          });
        });
    }
  }, [fabricOverlay]);
  return <div></div>;
}

export default ShareQueryParamHandler;
