// @flow import * as React from 'react'; import classnames from 'classnames'; import FileListItem from 'component/fileListItem'; import Spinner from 'component/spinner'; import { FormField } from 'component/common/form'; import usePersistedState from 'util/use-persisted-state'; const SORT_NEW = 'new'; const SORT_OLD = 'old'; type Props = { uris: Array, header: React.Node, headerAltControls: React.Node, injectedItem?: React.Node, loading: boolean, noHeader?: boolean, slim?: string, empty?: string, // If using the default header, this is a unique ID needed to persist the state of the filter setting persistedStorageKey?: string, }; export default function FileList(props: Props) { const { uris, header, headerAltControls, injectedItem, loading, persistedStorageKey, noHeader, slim, empty } = props; const [currentSort, setCurrentSort] = usePersistedState(persistedStorageKey || 'file-list-global-sort', SORT_NEW); const sortedUris = uris && currentSort === SORT_OLD ? uris.reverse() : uris; const hasUris = uris && !!uris.length; function handleSortChange() { setCurrentSort(currentSort === SORT_NEW ? SORT_OLD : SORT_NEW); } return (
{!noHeader && (
{header || ( )} {loading && }
{headerAltControls}
)} {hasUris && ( )} {!hasUris && !loading &&

{empty || __('No results')}

}
); }