forked from Yadro/time-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskModel.ts
More file actions
45 lines (41 loc) · 1.1 KB
/
TaskModel.ts
File metadata and controls
45 lines (41 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import AbstractModel from '../base/AbstractModel';
import { ITreeItem } from '../types/ITreeItem';
import { computed, makeObservable, observable } from 'mobx';
interface ITaskModel extends ITreeItem<ITaskModel> {
projectId: string;
checked: boolean;
time: number[][];
active: boolean;
}
export default class TaskModel extends AbstractModel implements ITaskModel {
key: string = '';
title: string = '';
children: TaskModel[] = [];
projectId: string = '';
checked: boolean = false;
active: boolean = false;
time: number[][] = [];
constructor(props: ITaskModel) {
super();
this.load(props);
makeObservable(this, {
key: observable,
title: observable,
children: observable,
projectId: observable,
checked: observable,
active: observable,
time: observable,
duration: computed,
});
}
get duration() {
return this.time.reduce((prev: number, range: number[]) => {
if (range.length > 0) {
const duration = (range[1] ? range[1] : Date.now()) - range[0];
return prev + duration;
}
return 0;
}, 0);
}
}