MCPcopy Index your code
hub / github.com/callumalpass/tasknotes / toggleSubtasksExpansion

Function toggleSubtasksExpansion

src/ui/taskCardRelationshipExpansion.ts:141–237  ·  view source on GitHub ↗
(
	context: TaskCardRelationshipExpansionContext,
	card: HTMLElement,
	task: TaskInfo,
	expanded: boolean
)

Source from the content-addressed store, hash-verified

139}
140
141export async function toggleSubtasksExpansion(
142 context: TaskCardRelationshipExpansionContext,
143 card: HTMLElement,
144 task: TaskInfo,
145 expanded: boolean
146): Promise<void> {
147 const { plugin } = context;
148 const logger = getTaskCardExpansionLogger(plugin);
149
150 try {
151 if (!expanded) {
152 removeRelationshipContainer(card, ".task-card__subtasks");
153 return;
154 }
155
156 const container = ensureRelationshipContainer(
157 card,
158 ".task-card__subtasks",
159 "task-card__subtasks"
160 );
161 clearContainer(container);
162
163 const loadingEl = container.createEl("div", {
164 cls: "task-card__subtasks-loading",
165 text: plugin.i18n.translate("contextMenus.task.subtasks.loading"),
166 });
167
168 try {
169 const file = plugin.app.vault.getAbstractFileByPath(task.path);
170 if (!(file instanceof TFile)) {
171 throw new Error("Task file not found");
172 }
173
174 if (!plugin.projectSubtasksService) {
175 throw new Error("projectSubtasksService not initialized");
176 }
177
178 const relationshipOptions = getRelationshipOptions(context, card);
179 const subtasks = filterExpandedRelationshipTasks(
180 await plugin.projectSubtasksService.getTasksLinkedToProject(file),
181 relationshipOptions
182 );
183
184 loadingEl.remove();
185
186 if (subtasks.length === 0) {
187 container.createEl("div", {
188 cls: "task-card__subtasks-loading",
189 text: plugin.i18n.translate("contextMenus.task.subtasks.noSubtasks"),
190 });
191 return;
192 }
193
194 const sortedSubtasks = sortExpandedRelationshipTasks(
195 subtasks,
196 relationshipOptions,
197 (tasks) => plugin.projectSubtasksService.sortTasks(tasks)
198 );

Calls 14

clearContainerFunction · 0.85
getRelationshipOptionsFunction · 0.85
buildParentTaskChainFunction · 0.85
getAbstractFileByPathMethod · 0.80
warnMethod · 0.80
errorMethod · 0.80

Tested by

no test coverage detected