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;
|
return views;
|
||||||
}
|
}
|
||||||
|
|
||||||
parseFilter(json: any) {
|
static parseFilter(json: any) {
|
||||||
const filter = Filter.parse(json, this);
|
const filter = Filter.parse(json);
|
||||||
|
|
||||||
if (!filter) return;
|
if (!filter) return;
|
||||||
|
|
||||||
this._filters = [...this._filters, filter];
|
filter.view._filters = [...filter.view._filters, filter];
|
||||||
}
|
}
|
||||||
|
|
||||||
parseFilterUpdate(json: any) {
|
static parseFilterUpdate(json: any) {
|
||||||
const filter = this._filters.find((f) => f.id === json.id);
|
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;
|
if (!filter) return;
|
||||||
|
|
||||||
filter.parseUpdate(json);
|
filter.parseUpdate(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
parseFilterDelete(id: number) {
|
static parseFilterDelete(id: number) {
|
||||||
this._filters = this._filters.filter((f) => f.id !== id);
|
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 Card, { cards } from '$lib/types/Card';
|
||||||
import Project, { projects } from '$lib/types/Project';
|
import Project, { projects } from '$lib/types/Project';
|
||||||
import ProjectTag, { projectTags } from '$lib/types/ProjectTag';
|
import ProjectTag, { projectTags } from '$lib/types/ProjectTag';
|
||||||
|
@ -241,22 +242,17 @@ function applyProjectTagOption(data: any) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function applyFilter(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') {
|
if (data.action === 'create') {
|
||||||
view.parseFilter(data.data);
|
View.parseFilter(data.data);
|
||||||
} else if (data.action === 'update') {
|
} else if (data.action === 'update') {
|
||||||
view.parseFilterUpdate(data.changes);
|
View.parseFilterUpdate(data.changes);
|
||||||
} else if (data.action === 'delete') {
|
} else if (data.action === 'delete') {
|
||||||
view.parseFilterDelete(data.id);
|
View.parseFilterDelete(data.id);
|
||||||
} else {
|
} else {
|
||||||
toastWarning('Failed to parse filter update: unknown action');
|
toastWarning('Failed to parse filter update: unknown action');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
views.reload(view);
|
views.reload();
|
||||||
|
currentView.reload();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue