Fix real-time sync for filters
This commit is contained in:
parent
77a0c33c18
commit
7770d3b6cc
|
@ -285,23 +285,27 @@ export default class View {
|
|||
return views;
|
||||
}
|
||||
|
||||
parseFilter(json: any) {
|
||||
const filter = Filter.parse(json, this);
|
||||
|
||||
static parseFilter(json: any) {
|
||||
const filter = Filter.parse(json);
|
||||
if (!filter) return;
|
||||
|
||||
this._filters = [...this._filters, filter];
|
||||
filter.view._filters = [...filter.view._filters, filter];
|
||||
}
|
||||
|
||||
parseFilterUpdate(json: any) {
|
||||
const filter = this._filters.find((f) => f.id === json.id);
|
||||
static parseFilterUpdate(json: any) {
|
||||
const view = get(views).find((v) => v._filters.map((f) => f.id).includes(json.id));
|
||||
if (!view) return;
|
||||
|
||||
const filter = view._filters.find((f) => f.id === json.id);
|
||||
if (!filter) return;
|
||||
|
||||
filter.parseUpdate(json);
|
||||
}
|
||||
|
||||
parseFilterDelete(id: number) {
|
||||
this._filters = this._filters.filter((f) => f.id !== id);
|
||||
static parseFilterDelete(id: number) {
|
||||
const view = get(views).find((v) => v._filters.map((f) => f.id).includes(id));
|
||||
if (!view) return;
|
||||
|
||||
view._filters = view._filters.filter((f) => f.id !== id);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import currentView from '$lib/stores/currentView';
|
||||
import Card, { cards } from '$lib/types/Card';
|
||||
import Project, { projects } from '$lib/types/Project';
|
||||
import ProjectTag, { projectTags } from '$lib/types/ProjectTag';
|
||||
|
@ -241,22 +242,17 @@ function applyProjectTagOption(data: any) {
|
|||
}
|
||||
|
||||
function applyFilter(data: any) {
|
||||
const view = View.fromId(data.view_id);
|
||||
if (!view) {
|
||||
toastWarning('Failed to parse filter update: view not found');
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.action === 'create') {
|
||||
view.parseFilter(data.data);
|
||||
View.parseFilter(data.data);
|
||||
} else if (data.action === 'update') {
|
||||
view.parseFilterUpdate(data.changes);
|
||||
View.parseFilterUpdate(data.changes);
|
||||
} else if (data.action === 'delete') {
|
||||
view.parseFilterDelete(data.id);
|
||||
View.parseFilterDelete(data.id);
|
||||
} else {
|
||||
toastWarning('Failed to parse filter update: unknown action');
|
||||
return;
|
||||
}
|
||||
|
||||
views.reload(view);
|
||||
views.reload();
|
||||
currentView.reload();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue