import React, { useState } from 'react'; import classNames from 'classnames'; import { AttachmentSection } from './AttachmentSection'; import { EmptyState } from './EmptyState'; import { missingCaseError } from '../../../util/missingCaseError'; import { MediaItemType } from '../../LightboxGallery'; type Props = { documents: Array; media: Array; }; type TabType = 'media' | 'documents'; const Tab = ({ isSelected, label, onSelect, type, }: { isSelected: boolean; label: string; onSelect: () => void; type: TabType; }) => { return (
{label}
); }; const Sections = (props: Props & { selectedTab: TabType }) => { const { media, documents, selectedTab } = props; const mediaItems = selectedTab === 'media' ? media : documents; const type = selectedTab; if (!mediaItems || mediaItems.length === 0) { const label = (() => { switch (type) { case 'media': return window.i18n('mediaEmptyState'); case 'documents': return window.i18n('documentsEmptyState'); default: throw missingCaseError(type); } })(); return ; } return (
); }; export const MediaGallery = (props: Props) => { const [selectedTab, setSelectedTab] = useState('media'); const isDocumentSelected = selectedTab === 'documents'; const isMediaSelected = selectedTab === 'media'; return (
{ setSelectedTab('media'); }} /> { setSelectedTab('documents'); }} />
); };