Recently edited

This commit is contained in:
Tom Moor
2017-06-25 20:42:04 -07:00
parent 86b0966703
commit db1d8c2258
3 changed files with 43 additions and 7 deletions

View File

@@ -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 = {};
<PageTitle title="Home" />
<h1>Home</h1>
<Subheading>Recently viewed</Subheading>
<DocumentList documents={this.store.documents} />
<DocumentList documents={this.viewedStore.documents} />
<Subheading>Recently edited</Subheading>
<DocumentList documents={this.editedStore.documents} />
</CenteredContent>
);
}

View File

@@ -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<Document> = [];
@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;

View File

@@ -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<Document> = [];
@observable isFetching = false;
@@ -26,4 +26,4 @@ class RecentDocumentsStore {
};
}
export default RecentDocumentsStore;
export default ViewedDocumentsStore;