From ee05b444a38ae06bd97467f14643973978f03975 Mon Sep 17 00:00:00 2001 From: Rascal_Two Date: Mon, 2 Nov 2020 19:14:03 -0500 Subject: [PATCH] Add timer reset command (#30) --- README.md | 1 + src/command.handler.ts | 26 +++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 73cf52a..ee030e7 100644 --- a/README.md +++ b/README.md @@ -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 : diff --git a/src/command.handler.ts b/src/command.handler.ts index 0dd2917..7ce1a49 100644 --- a/src/command.handler.ts +++ b/src/command.handler.ts @@ -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 @@ -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;