chore: Move to prettier standard double quotes (#1309)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// @flow
|
||||
import { observable, action, computed, runInAction } from 'mobx';
|
||||
import { observable, action, computed, runInAction } from "mobx";
|
||||
import {
|
||||
without,
|
||||
map,
|
||||
@@ -9,16 +9,16 @@ import {
|
||||
compact,
|
||||
omitBy,
|
||||
uniq,
|
||||
} from 'lodash';
|
||||
import { client } from 'utils/ApiClient';
|
||||
import naturalSort from 'shared/utils/naturalSort';
|
||||
import invariant from 'invariant';
|
||||
} from "lodash";
|
||||
import { client } from "utils/ApiClient";
|
||||
import naturalSort from "shared/utils/naturalSort";
|
||||
import invariant from "invariant";
|
||||
|
||||
import BaseStore from 'stores/BaseStore';
|
||||
import RootStore from 'stores/RootStore';
|
||||
import Document from 'models/Document';
|
||||
import Revision from 'models/Revision';
|
||||
import type { FetchOptions, PaginationParams, SearchResult } from 'types';
|
||||
import BaseStore from "stores/BaseStore";
|
||||
import RootStore from "stores/RootStore";
|
||||
import Document from "models/Document";
|
||||
import Revision from "models/Revision";
|
||||
import type { FetchOptions, PaginationParams, SearchResult } from "types";
|
||||
|
||||
export default class DocumentsStore extends BaseStore<Document> {
|
||||
@observable recentlyViewedIds: string[] = [];
|
||||
@@ -39,21 +39,21 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
get recentlyViewed(): Document[] {
|
||||
return orderBy(
|
||||
compact(this.recentlyViewedIds.map(id => this.data.get(id))),
|
||||
'updatedAt',
|
||||
'desc'
|
||||
"updatedAt",
|
||||
"desc"
|
||||
);
|
||||
}
|
||||
|
||||
@computed
|
||||
get recentlyUpdated(): Document[] {
|
||||
return orderBy(this.all, 'updatedAt', 'desc');
|
||||
return orderBy(this.all, "updatedAt", "desc");
|
||||
}
|
||||
|
||||
createdByUser(userId: string): Document[] {
|
||||
return orderBy(
|
||||
filter(this.all, d => d.createdBy.id === userId),
|
||||
'updatedAt',
|
||||
'desc'
|
||||
"updatedAt",
|
||||
"desc"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -77,23 +77,23 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
}
|
||||
|
||||
leastRecentlyUpdatedInCollection(collectionId: string): Document[] {
|
||||
return orderBy(this.inCollection(collectionId), 'updatedAt', 'asc');
|
||||
return orderBy(this.inCollection(collectionId), "updatedAt", "asc");
|
||||
}
|
||||
|
||||
recentlyUpdatedInCollection(collectionId: string): Document[] {
|
||||
return orderBy(this.inCollection(collectionId), 'updatedAt', 'desc');
|
||||
return orderBy(this.inCollection(collectionId), "updatedAt", "desc");
|
||||
}
|
||||
|
||||
recentlyPublishedInCollection(collectionId: string): Document[] {
|
||||
return orderBy(
|
||||
this.publishedInCollection(collectionId),
|
||||
'publishedAt',
|
||||
'desc'
|
||||
"publishedAt",
|
||||
"desc"
|
||||
);
|
||||
}
|
||||
|
||||
alphabeticalInCollection(collectionId: string): Document[] {
|
||||
return naturalSort(this.inCollection(collectionId), 'title');
|
||||
return naturalSort(this.inCollection(collectionId), "title");
|
||||
}
|
||||
|
||||
searchResults(query: string): SearchResult[] {
|
||||
@@ -108,7 +108,7 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
@computed
|
||||
get archived(): Document[] {
|
||||
return filter(
|
||||
orderBy(this.orderedData, 'archivedAt', 'desc'),
|
||||
orderBy(this.orderedData, "archivedAt", "desc"),
|
||||
d => d.archivedAt && !d.deletedAt
|
||||
);
|
||||
}
|
||||
@@ -116,20 +116,20 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
@computed
|
||||
get deleted(): Document[] {
|
||||
return filter(
|
||||
orderBy(this.orderedData, 'deletedAt', 'desc'),
|
||||
orderBy(this.orderedData, "deletedAt", "desc"),
|
||||
d => d.deletedAt
|
||||
);
|
||||
}
|
||||
|
||||
@computed
|
||||
get starredAlphabetical(): Document[] {
|
||||
return naturalSort(this.starred, 'title');
|
||||
return naturalSort(this.starred, "title");
|
||||
}
|
||||
|
||||
@computed
|
||||
get drafts(): Document[] {
|
||||
return filter(
|
||||
orderBy(this.all, 'updatedAt', 'desc'),
|
||||
orderBy(this.all, "updatedAt", "desc"),
|
||||
doc => !doc.publishedAt
|
||||
);
|
||||
}
|
||||
@@ -146,9 +146,9 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
const res = await client.post(`/documents.list`, {
|
||||
backlinkDocumentId: documentId,
|
||||
});
|
||||
invariant(res && res.data, 'Document list not available');
|
||||
invariant(res && res.data, "Document list not available");
|
||||
const { data } = res;
|
||||
runInAction('DocumentsStore#fetchBacklinks', () => {
|
||||
runInAction("DocumentsStore#fetchBacklinks", () => {
|
||||
data.forEach(this.add);
|
||||
this.backlinks.set(documentId, data.map(doc => doc.id));
|
||||
});
|
||||
@@ -158,8 +158,8 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
const documentIds = this.backlinks.get(documentId) || [];
|
||||
return orderBy(
|
||||
compact(documentIds.map(id => this.data.get(id))),
|
||||
'updatedAt',
|
||||
'desc'
|
||||
"updatedAt",
|
||||
"desc"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -168,24 +168,24 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
const res = await client.post(`/documents.list`, {
|
||||
parentDocumentId: documentId,
|
||||
});
|
||||
invariant(res && res.data, 'Document list not available');
|
||||
invariant(res && res.data, "Document list not available");
|
||||
const { data } = res;
|
||||
runInAction('DocumentsStore#fetchChildDocuments', () => {
|
||||
runInAction("DocumentsStore#fetchChildDocuments", () => {
|
||||
data.forEach(this.add);
|
||||
});
|
||||
};
|
||||
|
||||
@action
|
||||
fetchNamedPage = async (
|
||||
request: string = 'list',
|
||||
request: string = "list",
|
||||
options: ?PaginationParams
|
||||
): Promise<?(Document[])> => {
|
||||
this.isFetching = true;
|
||||
|
||||
try {
|
||||
const res = await client.post(`/documents.${request}`, options);
|
||||
invariant(res && res.data, 'Document list not available');
|
||||
runInAction('DocumentsStore#fetchNamedPage', () => {
|
||||
invariant(res && res.data, "Document list not available");
|
||||
runInAction("DocumentsStore#fetchNamedPage", () => {
|
||||
res.data.forEach(this.add);
|
||||
this.addPolicies(res.policies);
|
||||
this.isLoaded = true;
|
||||
@@ -198,24 +198,24 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
|
||||
@action
|
||||
fetchArchived = async (options: ?PaginationParams): Promise<*> => {
|
||||
return this.fetchNamedPage('archived', options);
|
||||
return this.fetchNamedPage("archived", options);
|
||||
};
|
||||
|
||||
@action
|
||||
fetchDeleted = async (options: ?PaginationParams): Promise<*> => {
|
||||
return this.fetchNamedPage('deleted', options);
|
||||
return this.fetchNamedPage("deleted", options);
|
||||
};
|
||||
|
||||
@action
|
||||
fetchRecentlyUpdated = async (options: ?PaginationParams): Promise<*> => {
|
||||
return this.fetchNamedPage('list', options);
|
||||
return this.fetchNamedPage("list", options);
|
||||
};
|
||||
|
||||
@action
|
||||
fetchAlphabetical = async (options: ?PaginationParams): Promise<*> => {
|
||||
return this.fetchNamedPage('list', {
|
||||
sort: 'title',
|
||||
direction: 'ASC',
|
||||
return this.fetchNamedPage("list", {
|
||||
sort: "title",
|
||||
direction: "ASC",
|
||||
...options,
|
||||
});
|
||||
};
|
||||
@@ -224,30 +224,30 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
fetchLeastRecentlyUpdated = async (
|
||||
options: ?PaginationParams
|
||||
): Promise<*> => {
|
||||
return this.fetchNamedPage('list', {
|
||||
sort: 'updatedAt',
|
||||
direction: 'ASC',
|
||||
return this.fetchNamedPage("list", {
|
||||
sort: "updatedAt",
|
||||
direction: "ASC",
|
||||
...options,
|
||||
});
|
||||
};
|
||||
|
||||
@action
|
||||
fetchRecentlyPublished = async (options: ?PaginationParams): Promise<*> => {
|
||||
return this.fetchNamedPage('list', {
|
||||
sort: 'publishedAt',
|
||||
direction: 'DESC',
|
||||
return this.fetchNamedPage("list", {
|
||||
sort: "publishedAt",
|
||||
direction: "DESC",
|
||||
...options,
|
||||
});
|
||||
};
|
||||
|
||||
@action
|
||||
fetchRecentlyViewed = async (options: ?PaginationParams): Promise<*> => {
|
||||
const data = await this.fetchNamedPage('viewed', options);
|
||||
const data = await this.fetchNamedPage("viewed", options);
|
||||
|
||||
runInAction('DocumentsStore#fetchRecentlyViewed', () => {
|
||||
runInAction("DocumentsStore#fetchRecentlyViewed", () => {
|
||||
// $FlowFixMe
|
||||
this.recentlyViewedIds.replace(
|
||||
uniq(this.recentlyViewedIds.concat(map(data, 'id')))
|
||||
uniq(this.recentlyViewedIds.concat(map(data, "id")))
|
||||
);
|
||||
});
|
||||
return data;
|
||||
@@ -255,22 +255,22 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
|
||||
@action
|
||||
fetchStarred = (options: ?PaginationParams): Promise<*> => {
|
||||
return this.fetchNamedPage('starred', options);
|
||||
return this.fetchNamedPage("starred", options);
|
||||
};
|
||||
|
||||
@action
|
||||
fetchDrafts = (options: ?PaginationParams): Promise<*> => {
|
||||
return this.fetchNamedPage('drafts', options);
|
||||
return this.fetchNamedPage("drafts", options);
|
||||
};
|
||||
|
||||
@action
|
||||
fetchPinned = (options: ?PaginationParams): Promise<*> => {
|
||||
return this.fetchNamedPage('pinned', options);
|
||||
return this.fetchNamedPage("pinned", options);
|
||||
};
|
||||
|
||||
@action
|
||||
fetchOwned = (options: ?PaginationParams): Promise<*> => {
|
||||
return this.fetchNamedPage('list', options);
|
||||
return this.fetchNamedPage("list", options);
|
||||
};
|
||||
|
||||
@action
|
||||
@@ -280,11 +280,11 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
): Promise<SearchResult[]> => {
|
||||
// $FlowFixMe
|
||||
const compactedOptions = omitBy(options, o => !o);
|
||||
const res = await client.get('/documents.search', {
|
||||
const res = await client.get("/documents.search", {
|
||||
...compactedOptions,
|
||||
query,
|
||||
});
|
||||
invariant(res && res.data, 'Search response should be available');
|
||||
invariant(res && res.data, "Search response should be available");
|
||||
|
||||
// add the documents and associated policies to the store
|
||||
res.data.forEach(result => this.add(result.document));
|
||||
@@ -335,16 +335,16 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
return doc;
|
||||
}
|
||||
|
||||
const res = await client.post('/documents.info', {
|
||||
const res = await client.post("/documents.info", {
|
||||
id,
|
||||
shareId: options.shareId,
|
||||
});
|
||||
invariant(res && res.data, 'Document not available');
|
||||
invariant(res && res.data, "Document not available");
|
||||
|
||||
this.addPolicies(res.policies);
|
||||
this.add(res.data);
|
||||
|
||||
runInAction('DocumentsStore#fetch', () => {
|
||||
runInAction("DocumentsStore#fetch", () => {
|
||||
this.isLoaded = true;
|
||||
});
|
||||
|
||||
@@ -360,12 +360,12 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
collectionId: string,
|
||||
parentDocumentId: ?string
|
||||
) => {
|
||||
const res = await client.post('/documents.move', {
|
||||
const res = await client.post("/documents.move", {
|
||||
id: document.id,
|
||||
collectionId,
|
||||
parentDocumentId,
|
||||
});
|
||||
invariant(res && res.data, 'Data not available');
|
||||
invariant(res && res.data, "Data not available");
|
||||
|
||||
res.data.documents.forEach(this.add);
|
||||
res.data.collections.forEach(this.rootStore.collections.add);
|
||||
@@ -373,14 +373,14 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
|
||||
@action
|
||||
duplicate = async (document: Document): * => {
|
||||
const res = await client.post('/documents.create', {
|
||||
const res = await client.post("/documents.create", {
|
||||
publish: !!document.publishedAt,
|
||||
parentDocumentId: document.parentDocumentId,
|
||||
collectionId: document.collectionId,
|
||||
title: `${document.title} (duplicate)`,
|
||||
text: document.text,
|
||||
});
|
||||
invariant(res && res.data, 'Data should be available');
|
||||
invariant(res && res.data, "Data should be available");
|
||||
|
||||
const collection = this.getCollectionForDocument(document);
|
||||
if (collection) collection.refresh();
|
||||
@@ -439,11 +439,11 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
|
||||
@action
|
||||
archive = async (document: Document) => {
|
||||
const res = await client.post('/documents.archive', {
|
||||
const res = await client.post("/documents.archive", {
|
||||
id: document.id,
|
||||
});
|
||||
runInAction('Document#archive', () => {
|
||||
invariant(res && res.data, 'Data should be available');
|
||||
runInAction("Document#archive", () => {
|
||||
invariant(res && res.data, "Data should be available");
|
||||
document.updateFromJson(res.data);
|
||||
this.addPolicies(res.policies);
|
||||
});
|
||||
@@ -454,12 +454,12 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
|
||||
@action
|
||||
restore = async (document: Document, revision?: Revision) => {
|
||||
const res = await client.post('/documents.restore', {
|
||||
const res = await client.post("/documents.restore", {
|
||||
id: document.id,
|
||||
revisionId: revision ? revision.id : undefined,
|
||||
});
|
||||
runInAction('Document#restore', () => {
|
||||
invariant(res && res.data, 'Data should be available');
|
||||
runInAction("Document#restore", () => {
|
||||
invariant(res && res.data, "Data should be available");
|
||||
document.updateFromJson(res.data);
|
||||
this.addPolicies(res.policies);
|
||||
});
|
||||
@@ -469,18 +469,18 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
};
|
||||
|
||||
pin = (document: Document) => {
|
||||
return client.post('/documents.pin', { id: document.id });
|
||||
return client.post("/documents.pin", { id: document.id });
|
||||
};
|
||||
|
||||
unpin = (document: Document) => {
|
||||
return client.post('/documents.unpin', { id: document.id });
|
||||
return client.post("/documents.unpin", { id: document.id });
|
||||
};
|
||||
|
||||
star = async (document: Document) => {
|
||||
this.starredIds.set(document.id, true);
|
||||
|
||||
try {
|
||||
return client.post('/documents.star', { id: document.id });
|
||||
return client.post("/documents.star", { id: document.id });
|
||||
} catch (err) {
|
||||
this.starredIds.set(document.id, false);
|
||||
}
|
||||
@@ -490,13 +490,13 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
this.starredIds.set(document.id, false);
|
||||
|
||||
try {
|
||||
return client.post('/documents.unstar', { id: document.id });
|
||||
return client.post("/documents.unstar", { id: document.id });
|
||||
} catch (err) {
|
||||
this.starredIds.set(document.id, false);
|
||||
}
|
||||
};
|
||||
|
||||
getByUrl = (url: string = ''): ?Document => {
|
||||
getByUrl = (url: string = ""): ?Document => {
|
||||
return find(this.orderedData, doc => url.endsWith(doc.urlId));
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user