( options: StatusCycleHandlerOptions )
| 31 | * Creates a click handler for cycling task status. |
| 32 | */ |
| 33 | export function createStatusCycleHandler( |
| 34 | options: StatusCycleHandlerOptions |
| 35 | ): (e: MouseEvent) => void { |
| 36 | const { task, plugin, targetDate, updateStatusVisuals } = options; |
| 37 | return (e: MouseEvent) => { |
| 38 | e.stopPropagation(); |
| 39 | void (async () => { |
| 40 | const logger = getTaskCardActionLogger(plugin); |
| 41 | try { |
| 42 | if (task.recurrence) { |
| 43 | const updatedTask = await plugin.toggleRecurringTaskComplete(task, targetDate); |
| 44 | const newEffectiveStatus = getEffectiveTaskStatus( |
| 45 | updatedTask, |
| 46 | targetDate, |
| 47 | plugin.statusManager.getCompletedStatuses()[0] |
| 48 | ); |
| 49 | const isNowCompleted = |
| 50 | plugin.statusManager.isCompletedStatus(newEffectiveStatus); |
| 51 | updateStatusVisuals(updatedTask, newEffectiveStatus, isNowCompleted); |
| 52 | return; |
| 53 | } |
| 54 | |
| 55 | const freshTask = await plugin.cacheManager.getTaskInfo(task.path); |
| 56 | if (!freshTask) { |
| 57 | new Notice("Task not found"); |
| 58 | return; |
| 59 | } |
| 60 | |
| 61 | const currentStatus = freshTask.status || plugin.settings.defaultTaskStatus; |
| 62 | const nextStatus = e.shiftKey |
| 63 | ? plugin.statusManager.getPreviousStatus(currentStatus) |
| 64 | : plugin.statusManager.getNextStatus(currentStatus); |
| 65 | const updatedTask = await plugin.updateTaskProperty(freshTask, "status", nextStatus); |
| 66 | const isNowCompleted = plugin.statusManager.isCompletedStatus(nextStatus); |
| 67 | updateStatusVisuals(updatedTask, nextStatus, isNowCompleted); |
| 68 | } catch (error) { |
| 69 | const errorMessage = error instanceof Error ? error.message : String(error); |
| 70 | logger.error("Error cycling task status", { |
| 71 | category: "persistence", |
| 72 | operation: "cycle-status", |
| 73 | details: { taskPath: task.path, errorMessage }, |
| 74 | error, |
| 75 | }); |
| 76 | new Notice(`Failed to update task status: ${errorMessage}`); |
| 77 | } |
| 78 | })(); |
| 79 | }; |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Creates a click handler for priority indicators. |
no test coverage detected