From 9387fb09778c6511625b77f7ac50d0a3e5d53404 Mon Sep 17 00:00:00 2001 From: Muness Castle <931+muness@users.noreply.github.com> Date: Sat, 23 Dec 2023 20:52:13 -0500 Subject: [PATCH 1/3] Fix dueOnDayEndpoint typo --- src/main.ts | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/main.ts b/src/main.ts index 4315d54..427759f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -48,14 +48,13 @@ const CONSTANTS = { categoriesEndpoint: '/api/categories', childrenEndpoint: '/api/children', scheduledOnDayEndpoint: '/api/todayItems', - dueOnDayEndpoint: '/api/dueItems,' + dueOnDayEndpoint: '/api/dueItems' } export default class AmazingMarvinPlugin extends Plugin { settings: AmazingMarvinPluginSettings; categories: Category[] = []; - markAsDoneAttempted: string[] = []; createFolder = async (path: string) => { try { @@ -135,10 +134,6 @@ export default class AmazingMarvinPlugin extends Plugin { } async markDone(taskId: string) { - if (this.markAsDoneAttempted.includes(taskId)) { - return; - } - const opt = this.settings; const requestBody = { itemId: taskId, @@ -146,7 +141,6 @@ export default class AmazingMarvinPlugin extends Plugin { }; try { - this.markAsDoneAttempted.push(taskId); const remoteResponse = await requestUrl({ url: `https://serv.amazingmarvin.com/api/markDone`, method: 'POST', From bd80840778ddd35ff343f9e17ef4c16638ec9f16 Mon Sep 17 00:00:00 2001 From: Muness Castle <931+muness@users.noreply.github.com> Date: Sat, 23 Dec 2023 22:00:00 -0500 Subject: [PATCH 2/3] Tighten up code to listen to checkmarks --- src/amTaskWatcher.ts | 47 ++++++++++++-------------------------------- 1 file changed, 13 insertions(+), 34 deletions(-) diff --git a/src/amTaskWatcher.ts b/src/amTaskWatcher.ts index 38ba5a9..c8380df 100644 --- a/src/amTaskWatcher.ts +++ b/src/amTaskWatcher.ts @@ -5,51 +5,30 @@ import { ViewPlugin, ViewUpdate, } from '@codemirror/view'; -import { RegExpCursor } from "./regexp-cursor"; +const COMPLETED_AM_TASK = /^\s*[-*+]\s\[[xX]\]\s\[⚓\]\(https:\/\/app\.amazingmarvin\.com\/#t=([^)\s]+)/; -export function amTaskWatcher(app: App, plugin: AmazingMarvinPlugin) { +export function amTaskWatcher(_app: App, plugin: AmazingMarvinPlugin) { return ViewPlugin.fromClass( class { constructor(public view: EditorView) { - this.updateDecorations(view); } update(update: ViewUpdate) { - if (update.docChanged || update.viewportChanged) { - this.updateDecorations(update.view); + if (!update.docChanged) { + return; } - } - - updateDecorations(view: EditorView) { - // Process only visible ranges - for (let part of view.visibleRanges) { - const taskCursor = new RegExpCursor(view.state.doc, - "^\\s*([-*+])\\s\\[(.)\\]", - {}, part.from, part.to); - - - while (!taskCursor.next().done) { - let { from, to } = taskCursor.value; - const line = view.state.doc.lineAt(from); - // Check if the task is marked as completed - if (line.text.match(/^\s*[-*+]\s\[[xX]\]\s\[⚓\]/)) { - // Logic for handling completed tasks with deep links - this.handleCompletedTask(line.text); + update.changes.iterChanges((fromA, _toA, _fromB, _toB, change) => { + //only match if the change is a single character and it's an X or x + if (change.length === 1 && (change.sliceString(0, 1) === "X" || change.sliceString(0, 1) === "x")) { + let line = update.state.doc.lineAt(fromA).text; + + const match = line.match(COMPLETED_AM_TASK); + if (match && match[1]) { + plugin.markDone(match[1]); } } - } - } - - handleCompletedTask(taskLine: string) { - const regex = /https:\/\/app\.amazingmarvin\.com\/#t=([^)\s]+)/; - const match = taskLine.match(regex); - - let itemId: string; - if (match && match[1]) { - itemId = match[1]; - plugin.markDone(itemId); - } + }); } }, { From 66c57b1932ed562439f4abcb9a8c54b68a58b7c7 Mon Sep 17 00:00:00 2001 From: Muness Castle <931+muness@users.noreply.github.com> Date: Sat, 23 Dec 2023 22:00:16 -0500 Subject: [PATCH 3/3] cleanup I noticed while working on mark as done --- src/main.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main.ts b/src/main.ts index 427759f..db56d1b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,10 +1,7 @@ import { - App, Notice, Plugin, - Tasks, normalizePath, - request, requestUrl, } from "obsidian"; @@ -83,6 +80,7 @@ export default class AmazingMarvinPlugin extends Plugin { id: 'am-import', name: 'Import Categories and Tasks', callback: () => { + animateNotice(new Notice('Importing from Amazing Marvin...')); this.sync().then(() => { new Notice('Amazing Marvin data imported successfully.'); }).catch((error) => { @@ -402,7 +400,7 @@ export default class AmazingMarvinPlugin extends Plugin { if (settings.showStartDate && task.startDate) { details += `Start Date:: [[${task.startDate}]] `; } - if (settings.showScheduledDate && task.day) { + if (settings.showScheduledDate && task.day && task.day !== 'unassigned') { details += `Scheduled Date:: [[${task.day}]] `; }