Fixed flow errors and small refactor
This commit is contained in:
@ -8,7 +8,7 @@ import PublishingInfo from 'components/PublishingInfo';
|
|||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
document: Document,
|
document: Document,
|
||||||
highlight?: string,
|
highlight?: ?string,
|
||||||
innerRef?: Function,
|
innerRef?: Function,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ class Title extends React.Component {
|
|||||||
render() {
|
render() {
|
||||||
let title;
|
let title;
|
||||||
if (this.props.truncate) {
|
if (this.props.truncate) {
|
||||||
title = _.truncate(this.props.content, this.props.truncate);
|
title = _.truncate(this.props.content, { length: this.props.truncate });
|
||||||
} else {
|
} else {
|
||||||
title = this.props.content;
|
title = this.props.content;
|
||||||
}
|
}
|
||||||
|
@ -131,9 +131,9 @@ class Document {
|
|||||||
title: this.title,
|
title: this.title,
|
||||||
text: this.text,
|
text: this.text,
|
||||||
};
|
};
|
||||||
if (this.parentDocument) {
|
// if (this.parentDocument) {
|
||||||
data.parentDocument = this.parentDocument.id;
|
// data.parentDocument = this.parentDocument.id;
|
||||||
}
|
// }
|
||||||
res = await client.post('/documents.create', data);
|
res = await client.post('/documents.create', data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,10 +37,10 @@ type Props = {
|
|||||||
<PageTitle title="Home" />
|
<PageTitle title="Home" />
|
||||||
<h1>Home</h1>
|
<h1>Home</h1>
|
||||||
<Subheading>Recently viewed</Subheading>
|
<Subheading>Recently viewed</Subheading>
|
||||||
<DocumentList documents={this.props.documents.getRecentlyViewed()} />
|
<DocumentList documents={this.props.documents.recentlyViewed} />
|
||||||
|
|
||||||
<Subheading>Recently edited</Subheading>
|
<Subheading>Recently edited</Subheading>
|
||||||
<DocumentList documents={this.props.documents.data.values()} />
|
<DocumentList documents={this.props.documents.recentlyEdited} />
|
||||||
</CenteredContent>
|
</CenteredContent>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
import { observable, action, runInAction } from 'mobx';
|
import { observable, action, runInAction } from 'mobx';
|
||||||
import invariant from 'invariant';
|
import invariant from 'invariant';
|
||||||
import { client } from 'utils/ApiClient';
|
import { client } from 'utils/ApiClient';
|
||||||
import type { Document } from 'types';
|
import Document from 'models/Document';
|
||||||
|
|
||||||
class SearchStore {
|
class SearchStore {
|
||||||
@observable documents: Array<Document> = [];
|
@observable documents: Array<Document> = [];
|
||||||
@ -22,7 +22,7 @@ class SearchStore {
|
|||||||
invariant(res && res.data, 'res or res.data missing');
|
invariant(res && res.data, 'res or res.data missing');
|
||||||
const { data } = res;
|
const { data } = res;
|
||||||
runInAction('search document', () => {
|
runInAction('search document', () => {
|
||||||
this.documents = data;
|
this.documents = data.map(documentData => new Document(documentData));
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Something went wrong');
|
console.error('Something went wrong');
|
||||||
|
@ -20,7 +20,7 @@ import DocumentsStore from 'stores/DocumentsStore';
|
|||||||
<CenteredContent column auto>
|
<CenteredContent column auto>
|
||||||
<PageTitle title="Starred" />
|
<PageTitle title="Starred" />
|
||||||
<h1>Starred</h1>
|
<h1>Starred</h1>
|
||||||
<DocumentList documents={this.props.documents.getStarred()} />
|
<DocumentList documents={this.props.documents.starred} />
|
||||||
</CenteredContent>
|
</CenteredContent>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ class CollectionsStore {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
getById = (id: string): Collection => {
|
getById = (id: string): ?Collection => {
|
||||||
return _.find(this.data, { id });
|
return _.find(this.data, { id });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// @flow
|
// @flow
|
||||||
import { observable, action, ObservableMap, runInAction } from 'mobx';
|
import { observable, action, computed, ObservableMap, runInAction } from 'mobx';
|
||||||
import { client } from 'utils/ApiClient';
|
import { client } from 'utils/ApiClient';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import invariant from 'invariant';
|
import invariant from 'invariant';
|
||||||
@ -14,6 +14,23 @@ class DocumentsStore {
|
|||||||
@observable isLoaded: boolean = false;
|
@observable isLoaded: boolean = false;
|
||||||
errors: ErrorsStore;
|
errors: ErrorsStore;
|
||||||
|
|
||||||
|
/* Computed */
|
||||||
|
|
||||||
|
@computed get recentlyViewed(): Array<Document> {
|
||||||
|
return _.filter(this.data.values(), ({ id }) =>
|
||||||
|
this.recentlyViewedIds.includes(id)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@computed get recentlyEdited(): Array<Document> {
|
||||||
|
// $FlowIssue
|
||||||
|
return this.data.values();
|
||||||
|
}
|
||||||
|
|
||||||
|
@computed get starred(): Array<Document> {
|
||||||
|
return _.filter(this.data.values(), 'starred');
|
||||||
|
}
|
||||||
|
|
||||||
/* Actions */
|
/* Actions */
|
||||||
|
|
||||||
@action fetchAll = async (request: string = 'list'): Promise<*> => {
|
@action fetchAll = async (request: string = 'list'): Promise<*> => {
|
||||||
@ -71,16 +88,6 @@ class DocumentsStore {
|
|||||||
this.data.delete(id);
|
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 => {
|
getById = (id: string): ?Document => {
|
||||||
return this.data.get(id);
|
return this.data.get(id);
|
||||||
};
|
};
|
||||||
|
@ -7,6 +7,7 @@ import _ from 'lodash';
|
|||||||
import emojify from './emojify';
|
import emojify from './emojify';
|
||||||
import toc from './toc';
|
import toc from './toc';
|
||||||
|
|
||||||
|
// $FlowIssue invalid flow-typed
|
||||||
slug.defaults.mode = 'rfc3986';
|
slug.defaults.mode = 'rfc3986';
|
||||||
|
|
||||||
const Renderer = sanitizedRenderer(marked.Renderer);
|
const Renderer = sanitizedRenderer(marked.Renderer);
|
||||||
|
@ -52,6 +52,7 @@ function generate(str, options) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
var toc = '';
|
var toc = '';
|
||||||
|
// $FlowIssue invalid flow-typed
|
||||||
var tokens = marked.lexer(str);
|
var tokens = marked.lexer(str);
|
||||||
var tocArray = [];
|
var tocArray = [];
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import { DataTypes, sequelize } from '../sequelize';
|
|||||||
import Document from './Document';
|
import Document from './Document';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
|
||||||
|
// $FlowIssue invalid flow-typed
|
||||||
slug.defaults.mode = 'rfc3986';
|
slug.defaults.mode = 'rfc3986';
|
||||||
|
|
||||||
const allowedCollectionTypes = [['atlas', 'journal']];
|
const allowedCollectionTypes = [['atlas', 'journal']];
|
||||||
|
@ -11,6 +11,7 @@ import Revision from './Revision';
|
|||||||
|
|
||||||
const URL_REGEX = /^[a-zA-Z0-9-]*-([a-zA-Z0-9]{10,15})$/;
|
const URL_REGEX = /^[a-zA-Z0-9-]*-([a-zA-Z0-9]{10,15})$/;
|
||||||
|
|
||||||
|
// $FlowIssue invalid flow-typed
|
||||||
slug.defaults.mode = 'rfc3986';
|
slug.defaults.mode = 'rfc3986';
|
||||||
const slugify = text =>
|
const slugify = text =>
|
||||||
slug(text, {
|
slug(text, {
|
||||||
|
Reference in New Issue
Block a user