Skip to content
This repository was archived by the owner on Dec 26, 2022. It is now read-only.

Commit 96b83f0

Browse files
author
Dmitry Yadrikhinsky
committed
Delete task, rename
1 parent 818eb6a commit 96b83f0

File tree

7 files changed

+39
-12
lines changed

7 files changed

+39
-12
lines changed

src/base/TreeModelStoreHelper.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,18 @@ export default abstract class TreeModelStoreHelper {
3434
}
3535
return result;
3636
}
37+
38+
static deleteItems<T extends ITreeItem<any>>(
39+
tasks: T[],
40+
condition: (task: T) => boolean
41+
): T[] {
42+
const result = tasks.filter((t) => !condition(t));
43+
for (let i = 0; i < result.length; i++) {
44+
const task = tasks[i];
45+
if (Array.isArray(task.children)) {
46+
tasks[i].children = this.deleteItems(task.children, condition);
47+
}
48+
}
49+
return result;
50+
}
3751
}

src/components/PlayStopButton/PlayStopButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export default function PlayStopButton({
2525
if (!task?.active) {
2626
tasksStore.startTimer(task);
2727
} else {
28-
tasksStore.endTimer(task);
28+
tasksStore.stopTimer(task);
2929
}
3030
}
3131
}

src/models/TaskModel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export default class TaskModel extends AbstractModel {
7777
setTitle: action,
7878
setDetails: action,
7979
start: action,
80-
end: action,
80+
stop: action,
8181
});
8282
}
8383

@@ -115,7 +115,7 @@ export default class TaskModel extends AbstractModel {
115115
});
116116
}
117117

118-
end() {
118+
stop() {
119119
if (this.active) {
120120
this.active = false;
121121
const range = this.time[this.time.length - 1];

src/screens/projects/components/TaskControl/TaskControl.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export default observer(function TaskControl() {
2626
<span>{task.title}</span>
2727
</div>
2828
<span className="task-control__duration">{duration}</span>
29-
<CircleButton onClick={() => tasksStore.endTimer(task)}>
29+
<CircleButton onClick={() => tasksStore.stopTimer(task)}>
3030
<PauseOutlined />
3131
</CircleButton>
3232
</span>

src/screens/projects/components/TaskNode/TaskNode.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export default function TaskNode({ model }: TaskNodeProps) {
3838
/>
3939
) : (
4040
<PauseOutlined
41-
onClick={preventDefault(() => tasksStore.endTimer(model))}
41+
onClick={preventDefault(() => tasksStore.stopTimer(model))}
4242
/>
4343
)}
4444
<DeleteOutlined

src/services/RootStore.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ class RootStore {
99
restore() {
1010
this.tasksStore.restore();
1111
this.projectStore.restore();
12-
console.log(toJS(this.projectStore.projects));
13-
console.log(toJS(this.tasksStore.tasks));
1412
}
1513
}
1614

src/services/tasks/TaskStore.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export default class TaskStore {
2626

2727
deleteTime(task: TaskModel, timeIndex: number) {
2828
if (!task.time[timeIndex].end) {
29-
task.end();
29+
task.stop();
3030
}
3131
task.time.splice(timeIndex, 1);
3232
this.tasksService.save(this.tasks);
@@ -74,22 +74,37 @@ export default class TaskStore {
7474
}
7575

7676
delete(task: TaskModel) {
77-
task.setDeleted();
77+
function condition(_task: TaskModel) {
78+
return _task.key === task.key;
79+
}
80+
81+
if (task.active) {
82+
this.stopTimer(task);
83+
}
84+
85+
for (const projectKey in this.tasks) {
86+
if (this.tasks.hasOwnProperty(projectKey)) {
87+
this.tasks[projectKey] = TreeModelStoreHelper.deleteItems(
88+
this.tasks[projectKey],
89+
condition
90+
);
91+
}
92+
}
7893
this.tasksService.save(this.tasks);
7994
}
8095

8196
startTimer(task: TaskModel) {
8297
if (this.activeTask) {
83-
this.endTimer(this.activeTask);
98+
this.stopTimer(this.activeTask);
8499
}
85100
this.activeTask = task;
86101
task.start();
87102
this.tasksService.save(this.tasks);
88103
}
89104

90-
endTimer(task: TaskModel) {
105+
stopTimer(task: TaskModel) {
91106
this.activeTask = undefined;
92-
task.end();
107+
task.stop();
93108
this.tasksService.save(this.tasks);
94109
}
95110

0 commit comments

Comments
 (0)