This repository has been archived on 2022-08-14. You can view files and clone it, but cannot push or open issues or pull requests.
outline/app/scenes/Dashboard/Dashboard.js
2017-12-05 01:22:22 -08:00

71 lines
1.9 KiB
JavaScript

// @flow
import React, { Component } from 'react';
import { observable } from 'mobx';
import { observer, inject } from 'mobx-react';
import DocumentsStore from 'stores/DocumentsStore';
import CenteredContent from 'components/CenteredContent';
import DocumentList from 'components/DocumentList';
import PageTitle from 'components/PageTitle';
import Subheading from 'components/Subheading';
import { ListPlaceholder } from 'components/LoadingPlaceholder';
type Props = {
documents: DocumentsStore,
};
@observer
class Dashboard extends Component {
props: Props;
@observable isLoaded: boolean = false;
componentDidMount() {
this.loadContent();
}
loadContent = async () => {
await Promise.all([
this.props.documents.fetchRecentlyModified({ limit: 5 }),
this.props.documents.fetchRecentlyViewed({ limit: 5 }),
]);
this.isLoaded = true;
};
render() {
const { documents } = this.props;
const hasRecentlyViewed = documents.recentlyViewed.length > 0;
const hasRecentlyEdited = documents.recentlyEdited.length > 0;
const showContent =
this.isLoaded || (hasRecentlyViewed && hasRecentlyEdited);
return (
<CenteredContent>
<PageTitle title="Home" />
<h1>Home</h1>
{showContent ? (
<span>
{hasRecentlyViewed && [
<Subheading key="viewed">Recently viewed</Subheading>,
<DocumentList
key="viewedDocuments"
documents={documents.recentlyViewed}
/>,
]}
{hasRecentlyEdited && [
<Subheading key="edited">Recently edited</Subheading>,
<DocumentList
key="editedDocuments"
documents={documents.recentlyEdited}
/>,
]}
</span>
) : (
<ListPlaceholder count={5} />
)}
</CenteredContent>
);
}
}
export default inject('documents')(Dashboard);