diff --git a/frontend/scenes/Dashboard/Dashboard.js b/frontend/scenes/Dashboard/Dashboard.js index 5eccaafca..c36f42391 100644 --- a/frontend/scenes/Dashboard/Dashboard.js +++ b/frontend/scenes/Dashboard/Dashboard.js @@ -6,7 +6,8 @@ import styled from 'styled-components'; import DocumentList from 'components/DocumentList'; import PageTitle from 'components/PageTitle'; import CenteredContent from 'components/CenteredContent'; -import RecentDocumentsStore from './RecentDocumentsStore'; +import ViewedDocumentsStore from './ViewedDocumentsStore'; +import EditedDocumentsStore from './EditedDocumentsStore'; const Subheading = styled.h3` font-size: 11px; @@ -16,21 +17,25 @@ const Subheading = styled.h3` letter-spacing: 0.04em; border-bottom: 1px solid #ddd; padding-bottom: 10px; + margin-top: 30px; `; type Props = {}; @observer class Dashboard extends React.Component { props: Props; - store: RecentDocumentsStore; + viewedStore: ViewedDocumentsStore; + editedStore: EditedDocumentsStore; constructor(props: Props) { super(props); - this.store = new RecentDocumentsStore(); + this.viewedStore = new ViewedDocumentsStore(); + this.editedStore = new EditedDocumentsStore(); } componentDidMount() { - this.store.fetchDocuments(); + this.viewedStore.fetchDocuments(); + this.editedStore.fetchDocuments(); } render() { @@ -39,8 +44,10 @@ type Props = {};

Home

Recently viewed - + + Recently edited + ); } diff --git a/frontend/scenes/Dashboard/EditedDocumentsStore.js b/frontend/scenes/Dashboard/EditedDocumentsStore.js new file mode 100644 index 000000000..477500e16 --- /dev/null +++ b/frontend/scenes/Dashboard/EditedDocumentsStore.js @@ -0,0 +1,29 @@ +// @flow +import { observable, action, runInAction } from 'mobx'; +import invariant from 'invariant'; +import { client } from 'utils/ApiClient'; +import type { Document } from 'types'; + +class EditedDocumentsStore { + @observable documents: Array = []; + @observable isFetching = false; + + @action fetchDocuments = async () => { + this.isFetching = true; + + try { + const res = await client.get('/documents.list'); + invariant(res && res.data, 'res or res.data missing'); + const { data } = res; + runInAction('update state after fetching data', () => { + this.documents = data; + }); + } catch (e) { + console.error('Something went wrong'); + } + + this.isFetching = false; + }; +} + +export default EditedDocumentsStore; diff --git a/frontend/scenes/Dashboard/RecentDocumentsStore.js b/frontend/scenes/Dashboard/ViewedDocumentsStore.js similarity index 91% rename from frontend/scenes/Dashboard/RecentDocumentsStore.js rename to frontend/scenes/Dashboard/ViewedDocumentsStore.js index 8b955bdcf..147c85a1c 100644 --- a/frontend/scenes/Dashboard/RecentDocumentsStore.js +++ b/frontend/scenes/Dashboard/ViewedDocumentsStore.js @@ -4,7 +4,7 @@ import invariant from 'invariant'; import { client } from 'utils/ApiClient'; import type { Document } from 'types'; -class RecentDocumentsStore { +class ViewedDocumentsStore { @observable documents: Array = []; @observable isFetching = false; @@ -26,4 +26,4 @@ class RecentDocumentsStore { }; } -export default RecentDocumentsStore; +export default ViewedDocumentsStore;