You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Nothing/src/app/_models/plan.ts

73 lines
1.6 KiB

import { invoke } from "@tauri-apps/api/tauri";
import { Subject, debounceTime, from } from "rxjs";
export interface PlanInterface {
plan: PlanElement[];
current: number;
stored_path?: string;
}
export class Plan {
plan: PlanElement[];
current: number;
private path?: string;
private saveSubject: Subject<void> = new Subject<void>();
constructor(plan: PlanInterface) {
this.plan = plan.plan;
this.current = plan.current;
if(plan.stored_path) {
this.path = plan.stored_path;
}
this.saveSubject.pipe(debounceTime(500)).subscribe(() => this.underlyingSave());
}
setPath(path: string) {
this.path = path;
}
next() {
if (this.current + 1 < this.plan!.length) {
this.current++;
this.save();
}
}
prev() {
if (this.current - 1 >= 0) {
this.current--;
this.save();
}
}
setPrevious(prev: string) {
from(invoke<string>('path_for_previous', { prev })).subscribe(path => {
if (path) {
this.setPath(path);
}
});
}
private save() {
if (this.path) {
this.saveSubject.next();
}
}
private underlyingSave() {
console.log("Underlying save");
invoke('save_plan', {
plan: {
plan: this.plan,
current: this.current
}, path: this.path
});
}
}
export interface PlanElement {
area_key: string;
notes?: string;
uuid?: string;
edited: boolean;
}