fix: Remove collections/document when removed elsewhere
This commit is contained in:
@ -41,7 +41,11 @@ class SocketProvider extends React.Component<Props> {
|
|||||||
this.socket.on('entities', event => {
|
this.socket.on('entities', event => {
|
||||||
if (event.documents) {
|
if (event.documents) {
|
||||||
event.documents.forEach(doc => {
|
event.documents.forEach(doc => {
|
||||||
documents.add(doc);
|
if (doc.deletedAt) {
|
||||||
|
documents.remove(doc.id);
|
||||||
|
} else {
|
||||||
|
documents.add(doc);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Move this to the document scene once data loading
|
// TODO: Move this to the document scene once data loading
|
||||||
// has been refactored to be friendlier there.
|
// has been refactored to be friendlier there.
|
||||||
@ -61,7 +65,14 @@ class SocketProvider extends React.Component<Props> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (event.collections) {
|
if (event.collections) {
|
||||||
event.collections.forEach(collections.add);
|
event.collections.forEach(collection => {
|
||||||
|
if (collection.deletedAt) {
|
||||||
|
collections.remove(collection.id);
|
||||||
|
documents.removeCollectionDocuments(collection.id);
|
||||||
|
} else {
|
||||||
|
collections.add(collection);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.socket.on('documents.star', event => {
|
this.socket.on('documents.star', event => {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// @flow
|
// @flow
|
||||||
import { computed, runInAction } from 'mobx';
|
import { computed } from 'mobx';
|
||||||
import { concat, filter, last } from 'lodash';
|
import { concat, filter, last } from 'lodash';
|
||||||
import { client } from 'utils/ApiClient';
|
import { client } from 'utils/ApiClient';
|
||||||
|
|
||||||
@ -100,10 +100,9 @@ export default class CollectionsStore extends BaseStore<Collection> {
|
|||||||
delete(collection: Collection) {
|
delete(collection: Collection) {
|
||||||
super.delete(collection);
|
super.delete(collection);
|
||||||
|
|
||||||
runInAction(() => {
|
this.rootStore.documents.removeCollectionDocuments(collection.id);
|
||||||
this.rootStore.documents.fetchRecentlyUpdated();
|
this.rootStore.documents.fetchRecentlyUpdated();
|
||||||
this.rootStore.documents.fetchRecentlyViewed();
|
this.rootStore.documents.fetchRecentlyViewed();
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export = () => {
|
export = () => {
|
||||||
|
@ -16,8 +16,8 @@ import invariant from 'invariant';
|
|||||||
|
|
||||||
import BaseStore from 'stores/BaseStore';
|
import BaseStore from 'stores/BaseStore';
|
||||||
import RootStore from 'stores/RootStore';
|
import RootStore from 'stores/RootStore';
|
||||||
import Document from '../models/Document';
|
import Document from 'models/Document';
|
||||||
import Revision from '../models/Revision';
|
import Revision from 'models/Revision';
|
||||||
import type { FetchOptions, PaginationParams, SearchResult } from 'types';
|
import type { FetchOptions, PaginationParams, SearchResult } from 'types';
|
||||||
|
|
||||||
export default class DocumentsStore extends BaseStore<Document> {
|
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[] {
|
pinnedInCollection(collectionId: string): Document[] {
|
||||||
return filter(
|
return filter(
|
||||||
this.recentlyUpdatedInCollection(collectionId),
|
this.recentlyUpdatedInCollection(collectionId),
|
||||||
@ -352,6 +356,14 @@ export default class DocumentsStore extends BaseStore<Document> {
|
|||||||
return 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
|
@action
|
||||||
async update(params: *) {
|
async update(params: *) {
|
||||||
const document = await super.update(params);
|
const document = await super.update(params);
|
||||||
|
Reference in New Issue
Block a user