MCPcopy Create free account
hub / github.com/error311/FileRise / ensureChildrenLoaded

Function ensureChildrenLoaded

public/js/folderManager.js:1383–1450  ·  view source on GitHub ↗
(folder, ulEl)

Source from the content-addressed store, hash-verified

1381 updateToggleForOption(folder, hasKids);
1382}
1383async function ensureChildrenLoaded(folder, ulEl) {
1384 let cached = _childCache.get(folder);
1385 if (cached && typeof cached.then === 'function') {
1386 cached = await cached;
1387 }
1388 let items, nextCursor;
1389 if (cached) { items = cached.items; nextCursor = cached.nextCursor; }
1390 else {
1391 const res = await fetchChildrenOnce(folder);
1392 items = res.items; nextCursor = res.nextCursor; _childCache.set(folder, { items, nextCursor });
1393 }
1394
1395 if (!ulEl._renderedOnce) {
1396 items.forEach(it => {
1397 const li = makeChildLi(folder, it);
1398 ulEl.appendChild(li);
1399 const full = (folder === 'root') ? it.name : `${folder}/${it.name}`;
1400 try { applyFolderColorToOption(full, (window.folderColorMap||{})[full] || ''); } catch (e) {}
1401 ensureFolderIcon(full);
1402 });
1403 ulEl._renderedOnce = true;
1404 }
1405
1406 let moreLi = ulEl.querySelector('.load-more');
1407 if (nextCursor && !moreLi) {
1408 moreLi = document.createElement('li');
1409 moreLi.className = 'load-more';
1410
1411 const btn = document.createElement('button');
1412 btn.type = 'button';
1413 btn.className = 'btn btn-ghost';
1414 btn.textContent = t('load_more') || 'Load more';
1415 btn.setAttribute('aria-label', t('load_more') || 'Load more');
1416 if (ulEl.id) btn.setAttribute('aria-controls', ulEl.id);
1417
1418 btn.addEventListener('click', async (e) => {
1419 const b = e.currentTarget;
1420 const prevText = b.textContent;
1421 b.disabled = true;
1422 b.setAttribute('aria-busy', 'true');
1423 b.textContent = t('loading') || 'Loading…';
1424
1425 try {
1426 await loadMoreChildren(folder, ulEl, moreLi);
1427 } finally {
1428 // If the "load more" node still exists (wasn't removed because we reached end),
1429 // restore the button state.
1430 if (moreLi.isConnected) {
1431 b.disabled = false;
1432 b.removeAttribute('aria-busy');
1433 b.textContent = t('load_more') || 'Load more';
1434 }
1435 }
1436 });
1437
1438 moreLi.appendChild(btn);
1439 ulEl.appendChild(moreLi);
1440

Callers 11

expandAncestorsFunction · 0.85
refreshFolderChildrenFunction · 0.85
makeChildLiFunction · 0.85
syncTreeAfterFolderMoveFunction · 0.85
selectFolderFunction · 0.85
expandAndLoadSavedStateFunction · 0.85
loadFolderTreeFunction · 0.85
renameFolderInlineFunction · 0.85
folderManager.jsFile · 0.85
expandTreePathAsyncFunction · 0.85

Calls 11

fetchChildrenOnceFunction · 0.85
makeChildLiFunction · 0.85
applyFolderColorToOptionFunction · 0.85
ensureFolderIconFunction · 0.85
tFunction · 0.85
loadMoreChildrenFunction · 0.85
primeChildTogglesFunction · 0.85
updateToggleForOptionFunction · 0.85
peekHasFoldersFunction · 0.85
setMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected