* Big upgrades * WIP: Stash * Stash, 30 flow errors left * Downgrade mobx * WIP * When I understand the difference between class and instance methods * 💚 * Fixes: File import Model saving edge cases pinning and starring docs Collection editing Upgrade mobx devtools * Notification settings saving works * Disabled settings * Document mailer * Working notifications * Colletion created notification Ensure not notified for own actions * Tidy up * Document updated event only for document creation Add indexes Notification setting on user creation * Commentary * Fixed: Notification setting on signup * Fix document move / duplicate stale data Add BaseModel.refresh method * Fixes: Title in sidebar not updated after editing document * 💚 * Improve / restore error handling Better handle offline errors * 👕
55 lines
1.3 KiB
JavaScript
55 lines
1.3 KiB
JavaScript
// @flow
|
|
import { Collection } from '../models';
|
|
import presentDocument from './document';
|
|
import naturalSort from '../../shared/utils/naturalSort';
|
|
|
|
type Document = {
|
|
children: Document[],
|
|
id: string,
|
|
title: string,
|
|
url: string,
|
|
};
|
|
|
|
const sortDocuments = (documents: Document[]): Document[] => {
|
|
const orderedDocs = naturalSort(documents, 'title');
|
|
|
|
return orderedDocs.map(document => ({
|
|
...document,
|
|
children: sortDocuments(document.children),
|
|
}));
|
|
};
|
|
|
|
async function present(ctx: Object, collection: Collection) {
|
|
ctx.cache.set(collection.id, collection);
|
|
|
|
const data = {
|
|
id: collection.id,
|
|
url: collection.url,
|
|
name: collection.name,
|
|
description: collection.description,
|
|
color: collection.color || '#4E5C6E',
|
|
type: collection.type,
|
|
createdAt: collection.createdAt,
|
|
updatedAt: collection.updatedAt,
|
|
recentDocuments: undefined,
|
|
documents: undefined,
|
|
};
|
|
|
|
if (collection.type === 'atlas') {
|
|
// Force alphabetical sorting
|
|
data.documents = sortDocuments(collection.documentStructure);
|
|
}
|
|
|
|
if (collection.documents) {
|
|
data.recentDocuments = await Promise.all(
|
|
collection.documents.map(
|
|
async document => await presentDocument(ctx, document)
|
|
)
|
|
);
|
|
}
|
|
|
|
return data;
|
|
}
|
|
|
|
export default present;
|