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

Function selectiveUpdateForListView

src/utils/viewOptimizations.ts:131–196  ·  view source on GitHub ↗
(
	view: {
		taskElements?: Map<string, HTMLElement>;
		plugin: TaskNotesPlugin;
		getCurrentVisibleProperties?: () => string[];
		getVisibleProperties?: () => string[];
		getVisiblePropertyLabels?: () => Record<string, string>;
		refresh?: () => void | Promise<void>;
	},
	taskPath: string,
	operation: "update" | "delete" | "create"
)

Source from the content-addressed store, hash-verified

129 * This can be used by TaskListView, KanbanView, etc.
130 */
131export async function selectiveUpdateForListView(
132 view: {
133 taskElements?: Map<string, HTMLElement>;
134 plugin: TaskNotesPlugin;
135 getCurrentVisibleProperties?: () => string[];
136 getVisibleProperties?: () => string[];
137 getVisiblePropertyLabels?: () => Record<string, string>;
138 refresh?: () => void | Promise<void>;
139 },
140 taskPath: string,
141 operation: "update" | "delete" | "create"
142): Promise<void> {
143 if (!view.taskElements) {
144 // Fallback to full refresh if view doesn't have taskElements tracking
145 await view.refresh?.();
146 return;
147 }
148
149 const taskElement = view.taskElements.get(taskPath);
150
151 switch (operation) {
152 case "update":
153 if (taskElement) {
154 // Task is visible - update it in place
155 const updatedTask = await view.plugin.cacheManager.getTaskInfo(taskPath);
156 if (updatedTask) {
157 // Get visible properties from the view instead of extracting from DOM
158 const visibleProperties = view.getCurrentVisibleProperties?.() ||
159 view.getVisibleProperties?.() || [
160 "due",
161 "scheduled",
162 "projects",
163 "contexts",
164 "tags",
165 ];
166 const propertyLabels = view.getVisiblePropertyLabels?.();
167 await updateTaskElementInPlace(
168 taskElement,
169 updatedTask,
170 view.plugin,
171 visibleProperties,
172 propertyLabels
173 );
174 } else {
175 // Task was deleted, remove from view
176 taskElement.remove();
177 view.taskElements.delete(taskPath);
178 }
179 }
180 // If task not visible, no action needed
181 break;
182
183 case "delete":
184 if (taskElement) {
185 taskElement.remove();
186 view.taskElements.delete(taskPath);
187 }
188 break;

Callers

nothing calls this directly

Calls 5

updateTaskElementInPlaceFunction · 0.85
refreshMethod · 0.65
getMethod · 0.65
getTaskInfoMethod · 0.65
deleteMethod · 0.65

Tested by

no test coverage detected