Merge pull request #298 from jorilallo/issue-250
Dont wait for network requests on dashboard when we already have content
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
// @flow
|
// @flow
|
||||||
import React from 'react';
|
import React, { Component } from 'react';
|
||||||
import { observable } from 'mobx';
|
import { observable } from 'mobx';
|
||||||
import { observer, inject } from 'mobx-react';
|
import { observer, inject } from 'mobx-react';
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
@@ -26,9 +26,9 @@ type Props = {
|
|||||||
documents: DocumentsStore,
|
documents: DocumentsStore,
|
||||||
};
|
};
|
||||||
|
|
||||||
@observer class Dashboard extends React.Component {
|
@observer class Dashboard extends Component {
|
||||||
props: Props;
|
props: Props;
|
||||||
@observable isLoaded = false;
|
@observable isLoaded: boolean = false;
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.loadContent();
|
this.loadContent();
|
||||||
@@ -43,25 +43,27 @@ type Props = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
const { documents } = this.props;
|
||||||
|
const recentlyViewedLoaded = documents.recentlyViewed.length > 0;
|
||||||
|
const recentlyEditedLoaded = documents.recentlyEdited.length > 0;
|
||||||
|
const showContent =
|
||||||
|
this.isLoaded || (recentlyViewedLoaded && recentlyEditedLoaded);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<CenteredContent>
|
<CenteredContent>
|
||||||
<PageTitle title="Home" />
|
<PageTitle title="Home" />
|
||||||
<h1>Home</h1>
|
<h1>Home</h1>
|
||||||
{this.isLoaded
|
{showContent
|
||||||
? <Flex column>
|
? <Flex column>
|
||||||
{this.props.documents.recentlyViewed.length > 0 &&
|
{recentlyViewedLoaded &&
|
||||||
<Flex column>
|
<Flex column>
|
||||||
<Subheading>Recently viewed</Subheading>
|
<Subheading>Recently viewed</Subheading>
|
||||||
<DocumentList
|
<DocumentList documents={documents.recentlyViewed} />
|
||||||
documents={this.props.documents.recentlyViewed}
|
|
||||||
/>
|
|
||||||
</Flex>}
|
</Flex>}
|
||||||
{this.props.documents.recentlyEdited.length > 0 &&
|
{recentlyEditedLoaded &&
|
||||||
<Flex column>
|
<Flex column>
|
||||||
<Subheading>Recently edited</Subheading>
|
<Subheading>Recently edited</Subheading>
|
||||||
<DocumentList
|
<DocumentList documents={documents.recentlyEdited} />
|
||||||
documents={this.props.documents.recentlyEdited}
|
|
||||||
/>
|
|
||||||
</Flex>}
|
</Flex>}
|
||||||
</Flex>
|
</Flex>
|
||||||
: <ListPlaceholder count={5} />}
|
: <ListPlaceholder count={5} />}
|
||||||
|
|||||||
Reference in New Issue
Block a user