MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / appendEntry

Method appendEntry

src/components/fileTree/index.js:375–407  ·  view source on GitHub ↗

* Append a new entry to the tree * @param {string} name * @param {string} url * @param {boolean} isDirectory

(name, url, isDirectory)

Source from the content-addressed store, hash-verified

373 * @param {boolean} isDirectory
374 */
375 appendEntry(name, url, isDirectory) {
376 const entry = { name, url, isDirectory, isFile: !isDirectory };
377
378 // Insert in sorted position
379 if (isDirectory) {
380 // Find first file or end of dirs
381 const insertIndex = this.entries.findIndex((e) => !e.isDirectory);
382 if (insertIndex === -1) {
383 this.entries.push(entry);
384 } else {
385 this.entries.splice(insertIndex, 0, entry);
386 }
387 } else {
388 this.entries.push(entry);
389 }
390
391 // Re-sort entries
392 this.entries = helpers.sortDir(this.entries, {
393 sortByName: true,
394 showHiddenFiles: true,
395 });
396
397 // Update rendering based on mode
398 if (this.virtualList) {
399 // Virtual list mode: update items
400 this.virtualList.setItems(this.entries);
401 } else {
402 // Fragment mode: re-render
403 this.destroyChildTrees();
404 this.container.innerHTML = "";
405 this.renderWithFragment();
406 }
407 }
408
409 /**
410 * Remove an entry from the tree

Callers 1

appendEntryToOpenFolderFunction · 0.80

Calls 3

destroyChildTreesMethod · 0.95
renderWithFragmentMethod · 0.95
setItemsMethod · 0.80

Tested by

no test coverage detected