/** * * SlideshowCartouche * */ import * as React from 'react'; import { Button, Card, Content, Level, Column, Columns, Icon, Title, ModalCard, StretchedLayoutContainer, StretchedLayoutItem, } from 'quinoa-design-library'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faPencilAlt } from '@fortawesome/free-solid-svg-icons/faPencilAlt'; import { faCopy } from '@fortawesome/free-solid-svg-icons/faCopy'; import { faTrash } from '@fortawesome/free-solid-svg-icons/faTrash'; import { faEye } from '@fortawesome/free-solid-svg-icons/faEye'; import { FormattedMessage } from 'react-intl'; import Slideshow from 'types/Slideshow'; import { Link } from 'react-router-dom'; import { useDispatch } from 'react-redux'; import { useUrl } from 'utils/hooks'; import { displayDate } from 'utils/index'; import { push } from 'connected-react-router'; import messages from './messages'; import './style.css'; const InlineIcon = ({ children }) => ( {children} ); interface OwnProps { slideshow: Slideshow; onDelete: (toDelete) => void; onDuplicate: (toDuplicate: Slideshow) => void; } const useOnAction = ( slideshow: Slideshow, onDelete: (slideshow: Slideshow) => void, onDuplicate: (slideshow: Slideshow) => void, ) => { const dispatch = useDispatch(); const goToEditor = React.useCallback(() => dispatch(push(`/editor/${slideshow.id}`)), [slideshow]); const goToPlayer = React.useCallback(() => dispatch(push(`/player/${slideshow.id}`)), [slideshow]); const [removing, setRemoving] = React.useState(false); const [isPendingToDelete, setPendingToDelete] = React.useState(false); const onRemove = () => { setRemoving(true); onDelete(slideshow); setPendingToDelete(false); }; const onDeleteCancel = () => { setPendingToDelete(false); }; const onAction = React.useCallback( (id) => { switch (id) { case 'delete': return setPendingToDelete(true); case 'open': return goToEditor(); case 'read': return goToPlayer(); case 'duplicate': return onDuplicate(slideshow); } }, [slideshow], ); return { onAction: onAction, removing: removing, isPendingToDelete: isPendingToDelete, onDeleteCancel: onDeleteCancel, onRemove: onRemove, }; }; const SlideshowCartouche: React.SFC = (props: OwnProps) => { const { onAction, removing, isPendingToDelete, onDeleteCancel, onRemove, } = useOnAction(props.slideshow, props.onDelete, props.onDuplicate); const thumbnail = useUrl(props.slideshow.image.file); return ( edit ), isDisabled: removing, isColor: 'primary', id: 'open', }, { label: ( preview ), isDisabled: removing, id: 'read', }, { label: ( duplicate ), isDisabled: removing, id: 'duplicate', }, { label: ( delete ), isDisabled: removing, isColor: 'warning', id: 'delete', }, ]} bodyContent={ {props.slideshow.name} {props.slideshow.annotations.size} {' '} annotation {props.slideshow.annotations.size === 1 ? '' : 's'} {'creation '}{displayDate(props.slideshow.meta.createdAt)} {'last edition '}{displayDate(props.slideshow.meta.updatedAt)} } > Delete Cancel , ] } /> ); }; export default SlideshowCartouche;
{props.slideshow.annotations.size} {' '} annotation {props.slideshow.annotations.size === 1 ? '' : 's'}