Display document views (#849)

* Display who has viewed a document in the header

* Add overflow, display of WHEN last viewed
Cleanup old document attributes
Add firstViewedAt, lastViewedAt to API response

* Cleanup

* Added: API documentation for views endpoints

* Include views for deleted users
This commit is contained in:
Tom Moor
2019-01-08 22:49:20 -08:00
committed by GitHub
parent 11b0ac0c66
commit c78bf3c4bf
14 changed files with 216 additions and 123 deletions

View File

@ -13,7 +13,6 @@ import type { FetchOptions, PaginationParams, SearchResult } from 'types';
export default class DocumentsStore extends BaseStore<Document> {
@observable recentlyViewedIds: string[] = [];
@observable recentlyUpdatedIds: string[] = [];
constructor(rootStore: RootStore) {
super(rootStore, Document);
@ -30,11 +29,7 @@ export default class DocumentsStore extends BaseStore<Document> {
@computed
get recentlyUpdated(): * {
return orderBy(
compact(this.recentlyUpdatedIds.map(id => this.data.get(id))),
'updatedAt',
'desc'
);
return orderBy(Array.from(this.data.values()), 'updatedAt', 'desc');
}
createdByUser(userId: string): * {
@ -139,15 +134,7 @@ export default class DocumentsStore extends BaseStore<Document> {
@action
fetchRecentlyUpdated = async (options: ?PaginationParams): Promise<*> => {
const data = await this.fetchNamedPage('list', options);
runInAction('DocumentsStore#fetchRecentlyUpdated', () => {
// $FlowFixMe
this.recentlyUpdatedIds.replace(
uniq(this.recentlyUpdatedIds.concat(map(data, 'id')))
);
});
return data;
return this.fetchNamedPage('list', options);
};
@action
@ -308,7 +295,6 @@ export default class DocumentsStore extends BaseStore<Document> {
runInAction(() => {
this.recentlyViewedIds = without(this.recentlyViewedIds, document.id);
this.recentlyUpdatedIds = without(this.recentlyUpdatedIds, document.id);
});
const collection = this.getCollectionForDocument(document);