Skip to content

Commit

Permalink
Add timer reset command (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
RascalTwo authored Nov 3, 2020
1 parent 466c355 commit ee05b44
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Syntax for all other commands: `!COMMAND SUBCOMMAND [ID / TEXT]`
|`highlight POSITION`|`hl`|Changes all other than `POSITION` to a lower opacity|
|`start POSITION`||Starts a timer at `POSITION`|
|`stop [POSITION]`|| Stops the current timer, or optionally at `POSITION`|
|`reset [POSITION]`|| Resets the current timer, or optionally at `POSITION`|
|`cleanup`||Removes all "done" entries|

## Protips :
Expand Down
26 changes: 25 additions & 1 deletion src/command.handler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { TodoItem } from "./types/item";
import type { Writable } from "svelte/store";
import { get, Writable } from "svelte/store";
import type { TodoList } from "./types/list";

// todo tests
Expand Down Expand Up @@ -232,6 +232,30 @@ export function handleCommand(message: string,
break;
}

case "reset": {
const [targetIndexStr, ...rest] = realContent.split(' ');

const targetIndex = stringIdToIndexId(targetIndexStr);

let currentItemIndex = get(currentTimer);
if (currentItemIndex == -1) {
currentItemIndex = targetIndex;
}

items.update(curItems => {
const currentItem = curItems[currentItemIndex];

currentItem.spentTime = 0;
if (currentItem.startTime) {
currentItem.startTime = Date.now();
}

return curItems;
});

break;
}

case "name": {
taskListOptions.update(curObj => {
curObj.name = realContent;
Expand Down

0 comments on commit ee05b44

Please sign in to comment.