Fixed flow errors and small refactor

This commit is contained in:
Jori Lallo 2017-07-09 11:26:17 -07:00
parent d72f73ab18
commit c4b41a9e07
12 changed files with 33 additions and 22 deletions

View File

@ -8,7 +8,7 @@ import PublishingInfo from 'components/PublishingInfo';
type Props = {
document: Document,
highlight?: string,
highlight?: ?string,
innerRef?: Function,
};

View File

@ -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;
}

View File

@ -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);
}

View File

@ -37,10 +37,10 @@ type Props = {
<PageTitle title="Home" />
<h1>Home</h1>
<Subheading>Recently viewed</Subheading>
<DocumentList documents={this.props.documents.getRecentlyViewed()} />
<DocumentList documents={this.props.documents.recentlyViewed} />
<Subheading>Recently edited</Subheading>
<DocumentList documents={this.props.documents.data.values()} />
<DocumentList documents={this.props.documents.recentlyEdited} />
</CenteredContent>
);
}

View File

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

View File

@ -20,7 +20,7 @@ import DocumentsStore from 'stores/DocumentsStore';
<CenteredContent column auto>
<PageTitle title="Starred" />
<h1>Starred</h1>
<DocumentList documents={this.props.documents.getStarred()} />
<DocumentList documents={this.props.documents.starred} />
</CenteredContent>
);
}

View File

@ -38,7 +38,7 @@ class CollectionsStore {
}
};
getById = (id: string): Collection => {
getById = (id: string): ?Collection => {
return _.find(this.data, { id });
};

View File

@ -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<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 */
@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);
};

View File

@ -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);

View File

@ -52,6 +52,7 @@ function generate(str, options) {
);
var toc = '';
// $FlowIssue invalid flow-typed
var tokens = marked.lexer(str);
var tocArray = [];

View File

@ -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']];

View File

@ -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, {