fix: Remove collections/document when removed elsewhere
This commit is contained in:
@ -16,8 +16,8 @@ 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 Document from 'models/Document';
|
||||
import Revision from 'models/Revision';
|
||||
import type { FetchOptions, PaginationParams, SearchResult } from 'types';
|
||||
|
||||
export default class DocumentsStore extends BaseStore<Document> {
|
||||
@ -56,6 +56,10 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
);
|
||||
}
|
||||
|
||||
inCollection(collectionId: string): Document[] {
|
||||
return filter(this.all, document => document.collectionId === collectionId);
|
||||
}
|
||||
|
||||
pinnedInCollection(collectionId: string): Document[] {
|
||||
return filter(
|
||||
this.recentlyUpdatedInCollection(collectionId),
|
||||
@ -352,6 +356,14 @@ export default class DocumentsStore extends BaseStore<Document> {
|
||||
return document;
|
||||
};
|
||||
|
||||
@action
|
||||
removeCollectionDocuments(collectionId: string) {
|
||||
const documents = this.inCollection(collectionId);
|
||||
const documentIds = documents.map(doc => doc.id);
|
||||
this.recentlyViewedIds = without(this.recentlyViewedIds, ...documentIds);
|
||||
documentIds.forEach(id => this.data.delete(id));
|
||||
}
|
||||
|
||||
@action
|
||||
async update(params: *) {
|
||||
const document = await super.update(params);
|
||||
|
Reference in New Issue
Block a user