import React, { useCallback } from 'react';
import {Link} from 'react-router-dom';
import { withLeaflet } from 'react-leaflet';
import Annotation from 'types/Annotation';
import ReactMarkdown from 'react-markdown';
import cx from 'classnames';
import {
Box,
StretchedLayoutItem,
StretchedLayoutContainer,
Content,
Notification,
Button,
Icon,
Title,
} from 'quinoa-design-library';
import Slideshow from 'types/Slideshow';
import { List } from 'immutable';
import { annotationToBounds } from 'utils/geo';
import 'components/Sidebar/styles.css';
import { changeSelection, SureContextProps, SupportedShapes } from 'types';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
// import { faEye } from '@fortawesome/free-solid-svg-icons/faEye';
import { faPlay } from '@fortawesome/free-solid-svg-icons/faPlay';
import { faTimes } from '@fortawesome/free-solid-svg-icons/faTimes';
import { faCaretLeft } from '@fortawesome/free-solid-svg-icons/faCaretLeft';
import { faCaretRight } from '@fortawesome/free-solid-svg-icons/faCaretRight';
import Download from 'components/Download';
import DownloadModalHelp from '../../components/DownloadModalHelp';
import { useToggleBoolean } from 'utils/hooks';
import logo from '../../images/logo.svg';
import { useHowToModal } from 'components/HowToModal';
const Header: React.SFC<{
onButtonClick: () => void;
title: string;
minified: boolean;
viewerMode?: boolean;
allowPlay?: boolean;
}> = props => (
{
props.viewerMode ?
:
}
{props.title}
{
!!props.allowPlay &&
}
);
interface MenuItemProps {
children: React.ReactChild;
selected: boolean;
annotation: Annotation;
onGoTo: (annotation: Annotation) => void;
onClick: changeSelection;
}
const MenuItem: React.SFC = props => {
const onClick = useCallback((e) => {
props.onClick(props.annotation);
}, [props.annotation]);
const isInvisible = props.annotation.properties.type === SupportedShapes.invisible;
return (
{props.children}
);
};
const Control: React.SFC<{
selected: Annotation;
onPrev?: () => void;
onNext?: () => void;
}> = props => (
<>
{props.children}
>
);
interface SidebarProps {
readonly visible: boolean;
readonly onClose: () => void;
readonly onOpen: () => void;
readonly slideshow: Slideshow;
readonly selectedAnnotations: List;
readonly changeSelection: changeSelection;
readonly onPrev?: () => void;
readonly onNext?: () => void;
readonly viewerMode?: boolean;
}
const Sidebar = withLeaflet((props) => {
const selected = props.selectedAnnotations.first() as Annotation;
const onClickToggle = React.useCallback(() => {
props.visible ? props.onClose() : props.onOpen();
if (!selected) {
props.changeSelection(props.slideshow.annotations.first());
}
}, [props.visible, props.slideshow.annotations, selected]);
const onGoTo = useCallback((annotation: Annotation) => {
if (annotation.properties.type !== SupportedShapes.invisible) {
props.leaflet.map.fitBounds(
annotationToBounds(annotation),
{ animate: true },
);
}
}, [props.leaflet.map]);
const [isDownloadModalHelp, onCloseDownloadModalHelp, onOpenDownloadModalHelp] = useToggleBoolean(false);
const isEmpty = !props.slideshow.annotations.size;
const [modalButton, modal] = useHowToModal();
return (
0,
'empty': isEmpty,
'viewer-mode': props.viewerMode,
})}>
{props.visible ?
<>
{
isEmpty && !props.viewerMode ?
No annotations yet.
{`You can download this image as a simple viewer or add annotations in `}
edition mode.
:
props.slideshow.annotations.map((annotation: Annotation) =>
,
)
}
>
:
}
{
!props.viewerMode &&
}
{modal}
);
});
export default Sidebar;