Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

Commit

Permalink
Add a prune button (fixes #6)
Browse files Browse the repository at this point in the history
  • Loading branch information
tdemin committed Sep 24, 2019
1 parent 7b5d761 commit ea2f620
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/views/assets/locales.ts
Expand Up @@ -13,6 +13,7 @@ export default new LocalizedStrings({
btns_refetch: "Update",
btns_addTask: "New task",
btns_deleteTask: "Delete",
btns_pruneTasks: "Prune",
btns_updateTask: "Save",
editor_statusTp: "Status:",
editor_completedTp: "Completed",
Expand Down
16 changes: 15 additions & 1 deletion src/views/mainView.tsx
Expand Up @@ -6,7 +6,7 @@ import { RouteComponentProps } from "react-router-dom";
import TaskList from "./components/taskList";

import { logout } from "../actions/auth";
import { refetchTasks } from "../actions/tasks";
import { refetchTasks, deleteTask } from "../actions/tasks";
import { AnyAction } from "../typings/actions";
import { Task } from "../typings/tasks";
import { Store } from "../typings/store";
Expand Down Expand Up @@ -36,6 +36,14 @@ class MainView extends React.Component<Props, State> {
};
logout = () => this.props.dispatch(logout());
refetch = () => this.props.dispatch(refetchTasks(this.props.tasks));
prune = () => {
const danglingTasks = this.state.tasks.filter(
(task) =>
this.state.tasks.filter((child) => child.PID === task.ID)
.length === 0 && task.Completed
);
danglingTasks.forEach((task) => this.props.dispatch(deleteTask(task)));
};
updateSearch = (event: React.FormEvent<HTMLInputElement>) =>
this.setState({
search: event.currentTarget.value,
Expand Down Expand Up @@ -71,6 +79,12 @@ class MainView extends React.Component<Props, State> {
onClick={this.refetch}
value={strings.btns_refetch}
/>
<input
type="button"
className="pruneBtn button level-item"
onClick={this.prune}
value={strings.btns_pruneTasks}
/>
<input
type="button"
className="logoutBtn button level-item"
Expand Down

0 comments on commit ea2f620

Please sign in to comment.