// @flow import type { Node } from 'react'; import React from 'react'; import classnames from 'classnames'; import ClaimPreview from 'component/claimPreview'; 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: Node | boolean, headerAltControls: Node, injectedItem?: Node, loading: boolean, type: string, empty?: string, meta?: Node, // If using the default header, this is a unique ID needed to persist the state of the filter setting persistedStorageKey?: string, }; export default function ClaimList(props: Props) { const { uris, headerAltControls, injectedItem, loading, persistedStorageKey, empty, meta, type, header } = props; const [currentSort, setCurrentSort] = usePersistedState(persistedStorageKey, SORT_NEW); const hasUris = uris && !!uris.length; const sortedUris = (hasUris && (currentSort === SORT_NEW ? uris : uris.slice().reverse())) || []; function handleSortChange() { setCurrentSort(currentSort === SORT_NEW ? SORT_OLD : SORT_NEW); } return (
{header !== false && (
{header || ( )} {loading && }
{headerAltControls}
)} {meta &&
{meta}
} {hasUris && ( )} {!hasUris && !loading &&

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

}
); }