Recently edited
This commit is contained in:
@@ -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>
|
||||
);
|
||||
}
|
||||
|
||||
29
frontend/scenes/Dashboard/EditedDocumentsStore.js
Normal file
29
frontend/scenes/Dashboard/EditedDocumentsStore.js
Normal 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;
|
||||
@@ -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;
|
||||
Reference in New Issue
Block a user