fix: Flash of documents on home if drafts load before main request
fix: Drafts loading placeholder misplaced
This commit is contained in:
@@ -19,12 +19,14 @@ type Props = {
|
|||||||
|
|
||||||
@observer
|
@observer
|
||||||
class PaginatedDocumentList extends React.Component<Props> {
|
class PaginatedDocumentList extends React.Component<Props> {
|
||||||
|
isInitiallyLoaded: boolean = false;
|
||||||
@observable isLoaded: boolean = false;
|
@observable isLoaded: boolean = false;
|
||||||
@observable isFetching: boolean = false;
|
@observable isFetching: boolean = false;
|
||||||
@observable offset: number = 0;
|
@observable offset: number = 0;
|
||||||
@observable allowLoadMore: boolean = true;
|
@observable allowLoadMore: boolean = true;
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
|
this.isInitiallyLoaded = !!this.props.documents.length;
|
||||||
this.fetchResults();
|
this.fetchResults();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,14 +68,14 @@ class PaginatedDocumentList extends React.Component<Props> {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { empty, heading, documents, fetch, options, ...rest } = this.props;
|
const { empty, heading, documents, fetch, options, ...rest } = this.props;
|
||||||
const showLoading = !this.isLoaded && this.isFetching && !documents.length;
|
const showLoading = this.isFetching && !this.isInitiallyLoaded;
|
||||||
const showEmpty = this.isLoaded && !documents.length;
|
const showEmpty = !documents.length || showLoading;
|
||||||
|
const showList = (this.isLoaded || this.isInitiallyLoaded) && !showLoading;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
{showEmpty ? (
|
{showEmpty && empty}
|
||||||
empty
|
{showList && (
|
||||||
) : (
|
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
{heading}
|
{heading}
|
||||||
<DocumentList documents={documents} {...rest} />
|
<DocumentList documents={documents} {...rest} />
|
||||||
|
|||||||
@@ -32,13 +32,13 @@ class Drafts extends React.Component<Props> {
|
|||||||
<CenteredContent column auto>
|
<CenteredContent column auto>
|
||||||
<PageTitle title="Drafts" />
|
<PageTitle title="Drafts" />
|
||||||
<Heading>Drafts</Heading>
|
<Heading>Drafts</Heading>
|
||||||
{showLoading && <ListPlaceholder />}
|
|
||||||
{showEmpty ? (
|
{showEmpty ? (
|
||||||
<Empty>You’ve not got any drafts at the moment.</Empty>
|
<Empty>You’ve not got any drafts at the moment.</Empty>
|
||||||
) : (
|
) : (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
<Subheading>Documents</Subheading>
|
<Subheading>Documents</Subheading>
|
||||||
<DocumentList documents={drafts} showCollection />
|
<DocumentList documents={drafts} showCollection />
|
||||||
|
{showLoading && <ListPlaceholder />}
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
)}
|
)}
|
||||||
<Actions align="center" justify="flex-end">
|
<Actions align="center" justify="flex-end">
|
||||||
|
|||||||
Reference in New Issue
Block a user