Files

48 lines
1.4 KiB
TypeScript
Raw Permalink Normal View History

import {
Modal,
2021-02-01 01:11:23 -07:00
Skeleton,
ModalBody,
ModalHeader,
ModalOverlay,
ModalContent,
useDisclosure,
ModalCloseButton,
} from '@chakra-ui/react';
2021-01-02 12:54:41 -07:00
import { useColorValue, useBreakpointValue } from '~/context';
import { useLGState, useLGMethods } from '~/hooks';
import { PathButton } from './button';
import { Chart } from './chart';
import type { TPath } from './types';
2021-01-03 23:51:09 -07:00
export const Path: React.FC<TPath> = (props: TPath) => {
const { device } = props;
const { displayTarget } = useLGState();
const { getResponse } = useLGMethods();
const { isOpen, onClose, onOpen } = useDisclosure();
const response = getResponse(device);
const output = response?.output as TStructuredResponse;
2021-01-02 12:54:41 -07:00
const bg = useColorValue('light.50', 'dark.900');
const centered = useBreakpointValue({ base: false, lg: true }) ?? true;
return (
<>
<PathButton onOpen={onOpen} />
2021-01-02 12:54:41 -07:00
<Modal isOpen={isOpen} onClose={onClose} size="full" isCentered={centered}>
<ModalOverlay />
2021-01-02 12:54:41 -07:00
<ModalContent
bg={bg}
minH={{ lg: '80vh' }}
2021-01-02 12:54:41 -07:00
maxH={{ base: '80%', lg: '60%' }}
2021-01-03 23:51:09 -07:00
maxW={{ base: '100%', lg: '80%' }}
>
<ModalHeader>{`Path to ${displayTarget.value}`}</ModalHeader>
<ModalCloseButton />
<ModalBody>
{response !== null ? <Chart data={output} /> : <Skeleton w="500px" h="300px" />}
</ModalBody>
</ModalContent>
</Modal>
</>
);
};