MCPcopy
hub / github.com/callumalpass/tasknotes / createStatusCycleHandler

Function createStatusCycleHandler

src/ui/taskCardActions.ts:33–80  ·  view source on GitHub ↗
(
	options: StatusCycleHandlerOptions
)

Source from the content-addressed store, hash-verified

31 * Creates a click handler for cycling task status.
32 */
33export 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.

Callers 3

createTaskCardFunction · 0.90
updateTaskCardFunction · 0.90

Calls 10

getEffectiveTaskStatusFunction · 0.90
getTaskCardActionLoggerFunction · 0.85
getPreviousStatusMethod · 0.80
getNextStatusMethod · 0.80
updateTaskPropertyMethod · 0.80
errorMethod · 0.80
getCompletedStatusesMethod · 0.65
isCompletedStatusMethod · 0.65
getTaskInfoMethod · 0.65

Tested by

no test coverage detected