diff --git a/frontend/components/DocumentPreview/DocumentPreview.js b/frontend/components/DocumentPreview/DocumentPreview.js
index c6d34b89..2acea89a 100644
--- a/frontend/components/DocumentPreview/DocumentPreview.js
+++ b/frontend/components/DocumentPreview/DocumentPreview.js
@@ -8,7 +8,7 @@ import PublishingInfo from 'components/PublishingInfo';
type Props = {
document: Document,
- highlight?: string,
+ highlight?: ?string,
innerRef?: Function,
};
diff --git a/frontend/components/Layout/components/Title/Title.js b/frontend/components/Layout/components/Title/Title.js
index f85548e4..532fe0e4 100644
--- a/frontend/components/Layout/components/Title/Title.js
+++ b/frontend/components/Layout/components/Title/Title.js
@@ -15,7 +15,7 @@ class Title extends React.Component {
render() {
let title;
if (this.props.truncate) {
- title = _.truncate(this.props.content, this.props.truncate);
+ title = _.truncate(this.props.content, { length: this.props.truncate });
} else {
title = this.props.content;
}
diff --git a/frontend/models/Document.js b/frontend/models/Document.js
index db35d742..bb117d6b 100644
--- a/frontend/models/Document.js
+++ b/frontend/models/Document.js
@@ -131,9 +131,9 @@ class Document {
title: this.title,
text: this.text,
};
- if (this.parentDocument) {
- data.parentDocument = this.parentDocument.id;
- }
+ // if (this.parentDocument) {
+ // data.parentDocument = this.parentDocument.id;
+ // }
res = await client.post('/documents.create', data);
}
diff --git a/frontend/scenes/Dashboard/Dashboard.js b/frontend/scenes/Dashboard/Dashboard.js
index 54410b2f..077b4b4f 100644
--- a/frontend/scenes/Dashboard/Dashboard.js
+++ b/frontend/scenes/Dashboard/Dashboard.js
@@ -37,10 +37,10 @@ type Props = {
Home
Recently viewed
-
+
Recently edited
-
+
);
}
diff --git a/frontend/scenes/Search/SearchStore.js b/frontend/scenes/Search/SearchStore.js
index 0800b34b..058ca774 100644
--- a/frontend/scenes/Search/SearchStore.js
+++ b/frontend/scenes/Search/SearchStore.js
@@ -2,7 +2,7 @@
import { observable, action, runInAction } from 'mobx';
import invariant from 'invariant';
import { client } from 'utils/ApiClient';
-import type { Document } from 'types';
+import Document from 'models/Document';
class SearchStore {
@observable documents: Array = [];
@@ -22,7 +22,7 @@ class SearchStore {
invariant(res && res.data, 'res or res.data missing');
const { data } = res;
runInAction('search document', () => {
- this.documents = data;
+ this.documents = data.map(documentData => new Document(documentData));
});
} catch (e) {
console.error('Something went wrong');
diff --git a/frontend/scenes/Starred/Starred.js b/frontend/scenes/Starred/Starred.js
index a0cbd919..a14b21e6 100644
--- a/frontend/scenes/Starred/Starred.js
+++ b/frontend/scenes/Starred/Starred.js
@@ -20,7 +20,7 @@ import DocumentsStore from 'stores/DocumentsStore';
Starred
-
+
);
}
diff --git a/frontend/stores/CollectionsStore.js b/frontend/stores/CollectionsStore.js
index ae8e2644..05712347 100644
--- a/frontend/stores/CollectionsStore.js
+++ b/frontend/stores/CollectionsStore.js
@@ -38,7 +38,7 @@ class CollectionsStore {
}
};
- getById = (id: string): Collection => {
+ getById = (id: string): ?Collection => {
return _.find(this.data, { id });
};
diff --git a/frontend/stores/DocumentsStore.js b/frontend/stores/DocumentsStore.js
index aaffa4b0..649f66ad 100644
--- a/frontend/stores/DocumentsStore.js
+++ b/frontend/stores/DocumentsStore.js
@@ -1,5 +1,5 @@
// @flow
-import { observable, action, ObservableMap, runInAction } from 'mobx';
+import { observable, action, computed, ObservableMap, runInAction } from 'mobx';
import { client } from 'utils/ApiClient';
import _ from 'lodash';
import invariant from 'invariant';
@@ -14,6 +14,23 @@ class DocumentsStore {
@observable isLoaded: boolean = false;
errors: ErrorsStore;
+ /* Computed */
+
+ @computed get recentlyViewed(): Array {
+ return _.filter(this.data.values(), ({ id }) =>
+ this.recentlyViewedIds.includes(id)
+ );
+ }
+
+ @computed get recentlyEdited(): Array {
+ // $FlowIssue
+ return this.data.values();
+ }
+
+ @computed get starred(): Array {
+ return _.filter(this.data.values(), 'starred');
+ }
+
/* Actions */
@action fetchAll = async (request: string = 'list'): Promise<*> => {
@@ -71,16 +88,6 @@ class DocumentsStore {
this.data.delete(id);
};
- getStarred = () => {
- return _.filter(this.data.values(), 'starred');
- };
-
- getRecentlyViewed = () => {
- return _.filter(this.data.values(), ({ id }) =>
- this.recentlyViewedIds.includes(id)
- );
- };
-
getById = (id: string): ?Document => {
return this.data.get(id);
};
diff --git a/frontend/utils/markdown.js b/frontend/utils/markdown.js
index ab4593a7..e5511c66 100644
--- a/frontend/utils/markdown.js
+++ b/frontend/utils/markdown.js
@@ -7,6 +7,7 @@ import _ from 'lodash';
import emojify from './emojify';
import toc from './toc';
+// $FlowIssue invalid flow-typed
slug.defaults.mode = 'rfc3986';
const Renderer = sanitizedRenderer(marked.Renderer);
diff --git a/frontend/utils/toc/index.js b/frontend/utils/toc/index.js
index c015cde2..8eaa5499 100644
--- a/frontend/utils/toc/index.js
+++ b/frontend/utils/toc/index.js
@@ -52,6 +52,7 @@ function generate(str, options) {
);
var toc = '';
+ // $FlowIssue invalid flow-typed
var tokens = marked.lexer(str);
var tocArray = [];
diff --git a/server/models/Collection.js b/server/models/Collection.js
index 382b5476..ab4222ed 100644
--- a/server/models/Collection.js
+++ b/server/models/Collection.js
@@ -5,6 +5,7 @@ import { DataTypes, sequelize } from '../sequelize';
import Document from './Document';
import _ from 'lodash';
+// $FlowIssue invalid flow-typed
slug.defaults.mode = 'rfc3986';
const allowedCollectionTypes = [['atlas', 'journal']];
diff --git a/server/models/Document.js b/server/models/Document.js
index 9e7c44a3..104275d7 100644
--- a/server/models/Document.js
+++ b/server/models/Document.js
@@ -11,6 +11,7 @@ import Revision from './Revision';
const URL_REGEX = /^[a-zA-Z0-9-]*-([a-zA-Z0-9]{10,15})$/;
+// $FlowIssue invalid flow-typed
slug.defaults.mode = 'rfc3986';
const slugify = text =>
slug(text, {