Use the launch group catalog for shared projects
This commit is contained in:
+41
-22
@@ -1,6 +1,6 @@
|
||||
// A row identifies a folder accessible through the current launch's grants. Private
|
||||
// recents supply the activity order only, never the inventory or a grant.
|
||||
export function mountOverview(target, {client, extensionName, text, locale, onImport}) {
|
||||
export function mountOverview(target, {client, extensionName, text, locale, onImport, onOverview}) {
|
||||
const document = target.ownerDocument;
|
||||
function element(tag, label, className) {
|
||||
const node = document.createElement(tag);
|
||||
@@ -59,7 +59,7 @@ export function mountOverview(target, {client, extensionName, text, locale, onIm
|
||||
panel.append(heading,controls,alert,status,list);
|
||||
grid.append(activity,panel);
|
||||
const dialog = element('dialog');
|
||||
const title = element('h2', text.create);
|
||||
const title = element('h2', text.createTitle);
|
||||
title.id = 'project-create-' + crypto.randomUUID();
|
||||
dialog.setAttribute('aria-labelledby',title.id);
|
||||
const form = element('form');
|
||||
@@ -72,33 +72,47 @@ export function mountOverview(target, {client, extensionName, text, locale, onIm
|
||||
const footer = element('div', '', 'isa-project-toolbar'); footer.append(cancel,submit);
|
||||
form.append(label,formError,footer);
|
||||
dialog.append(title,form);
|
||||
root.append(header,grid,dialog);
|
||||
if (!onOverview) root.append(header);
|
||||
else root.classList.add('isa-group-home-embedded');
|
||||
root.append(grid,dialog);
|
||||
target.append(root);
|
||||
|
||||
let projects = [], recents = [], loading = true, failed = false, busy = false, alive = true, generation = 0;
|
||||
const date = new Intl.DateTimeFormat(locale,{dateStyle:'medium'});
|
||||
// The host focuses an extension iframe on pointer-down. Preserve matching
|
||||
// buttons through that refresh so the subsequent click reaches the same row.
|
||||
function updateRows(container, entries, detailed) {
|
||||
const existing = new Map([...container.children].map(node => [node.dataset.projectId, node]));
|
||||
entries.forEach((project, index) => {
|
||||
let row = existing.get(project.id);
|
||||
if (!row) {
|
||||
row = button();
|
||||
row.dataset.projectId = project.id;
|
||||
if (detailed) {
|
||||
const info = element('span');
|
||||
info.append(element('strong'), element('small'));
|
||||
row.append(info, element('time'));
|
||||
}
|
||||
}
|
||||
existing.delete(project.id);
|
||||
row.onclick = () => run(() => client.openListed(project));
|
||||
row.disabled = busy;
|
||||
if (detailed) {
|
||||
row.querySelector('strong').textContent = project.name;
|
||||
row.querySelector('small').textContent = project.path;
|
||||
row.querySelector('time').textContent = Number.isFinite(Date.parse(project.updatedAt)) ? date.format(new Date(project.updatedAt)) : '';
|
||||
} else row.textContent = project.name;
|
||||
if (container.children[index] !== row) container.insertBefore(row, container.children[index] ?? null);
|
||||
});
|
||||
for (const obsolete of existing.values()) obsolete.remove();
|
||||
}
|
||||
function draw() {
|
||||
const needle = search.value.trim().toLocaleLowerCase(locale);
|
||||
const visible = projects.filter(p => p.name.toLocaleLowerCase(locale).includes(needle));
|
||||
visible.sort((a,b) => (sort.value === 'updated' && (Date.parse(b.updatedAt) || 0) - (Date.parse(a.updatedAt) || 0)) || a.name.localeCompare(b.name,locale));
|
||||
list.replaceChildren();
|
||||
for (const project of visible) {
|
||||
const row = button('', () => run(() => client.openListed(project)));
|
||||
const info = element('span'); info.append(element('strong',project.name),element('small',project.path));
|
||||
row.append(info);
|
||||
if (Number.isFinite(Date.parse(project.updatedAt))) row.append(element('time',date.format(new Date(project.updatedAt))));
|
||||
row.disabled = busy;
|
||||
list.append(row);
|
||||
}
|
||||
updateRows(list, visible, true);
|
||||
status.textContent = loading ? text.loading : visible.length || failed ? '' : needle ? text.noMatches : text.noProjects;
|
||||
recent.replaceChildren();
|
||||
for (const item of recents) {
|
||||
const project = projects.find(p => p.id === item.id);
|
||||
if (project) {
|
||||
const row = button(project.name, () => run(() => client.openListed(project)));
|
||||
row.disabled = busy; recent.append(row);
|
||||
}
|
||||
}
|
||||
updateRows(recent, recents.map(item => projects.find(project => project.id === item.id)).filter(Boolean), false);
|
||||
if (!recent.childElementCount && !loading && !failed) recent.append(element('p',text.noActivity));
|
||||
pickFolder.disabled = busy; create.disabled = busy; importButton.disabled = busy; refreshButton.disabled = busy || loading;
|
||||
}
|
||||
@@ -109,7 +123,10 @@ export function mountOverview(target, {client, extensionName, text, locale, onIm
|
||||
const inventory = await client.list();
|
||||
if (alive && ticket === generation) projects = inventory.filter(p => !p.archived);
|
||||
} catch (error) {
|
||||
if (alive && ticket === generation) { failed = true; alert.textContent = String(error.message ?? error); }
|
||||
if (alive && ticket === generation) {
|
||||
if (client.sharedProjectsFolder) projects = [];
|
||||
failed = true; alert.textContent = error.code === 'SHARED_GROUP_PROJECTS_UNAVAILABLE' ? text.updateHost : String(error.message ?? error);
|
||||
}
|
||||
} finally {
|
||||
if (alive && ticket === generation) { loading = false; draw(); }
|
||||
}
|
||||
@@ -128,8 +145,10 @@ export function mountOverview(target, {client, extensionName, text, locale, onIm
|
||||
};
|
||||
search.oninput = sort.onchange = draw;
|
||||
const unsubscribe = client.subscribe(state => { recents = state.recents; draw(); });
|
||||
onOverview?.({refresh});
|
||||
void refresh();
|
||||
const onVisible = () => { if (!document.hidden && !busy) void refresh(); };
|
||||
document.addEventListener('visibilitychange',onVisible);
|
||||
return () => { alive = false; unsubscribe(); document.removeEventListener('visibilitychange',onVisible); root.remove(); };
|
||||
document.defaultView?.addEventListener('focus',onVisible);
|
||||
return () => { alive = false; onOverview?.(null); unsubscribe(); document.removeEventListener('visibilitychange',onVisible); document.defaultView?.removeEventListener('focus',onVisible); root.remove(); };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user