fix: Flash of documents on home if drafts load before main request

fix: Drafts loading placeholder misplaced
This commit is contained in:
Tom Moor
2019-08-06 23:46:27 -07:00
parent c18e4cd43e
commit 0f028812e1
2 changed files with 8 additions and 6 deletions

View File

@ -19,12 +19,14 @@ type Props = {
@observer
class PaginatedDocumentList extends React.Component<Props> {
isInitiallyLoaded: boolean = false;
@observable isLoaded: boolean = false;
@observable isFetching: boolean = false;
@observable offset: number = 0;
@observable allowLoadMore: boolean = true;
componentDidMount() {
this.isInitiallyLoaded = !!this.props.documents.length;
this.fetchResults();
}
@ -66,14 +68,14 @@ class PaginatedDocumentList extends React.Component<Props> {
render() {
const { empty, heading, documents, fetch, options, ...rest } = this.props;
const showLoading = !this.isLoaded && this.isFetching && !documents.length;
const showEmpty = this.isLoaded && !documents.length;
const showLoading = this.isFetching && !this.isInitiallyLoaded;
const showEmpty = !documents.length || showLoading;
const showList = (this.isLoaded || this.isInitiallyLoaded) && !showLoading;
return (
<React.Fragment>
{showEmpty ? (
empty
) : (
{showEmpty && empty}
{showList && (
<React.Fragment>
{heading}
<DocumentList documents={documents} {...rest} />

View File

@ -32,13 +32,13 @@ class Drafts extends React.Component<Props> {
<CenteredContent column auto>
<PageTitle title="Drafts" />
<Heading>Drafts</Heading>
{showLoading && <ListPlaceholder />}
{showEmpty ? (
<Empty>Youve not got any drafts at the moment.</Empty>
) : (
<React.Fragment>
<Subheading>Documents</Subheading>
<DocumentList documents={drafts} showCollection />
{showLoading && <ListPlaceholder />}
</React.Fragment>
)}
<Actions align="center" justify="flex-end">