Skip to content

Commit 5bdf01c

Browse files
Add Card.keys and sort cards by name in UI
1 parent e510791 commit 5bdf01c

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

heartbeat_monitor/KanbanBroFirebaseHeartbeatCardProviderPlugin.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export function apply() {
3535
console.log(`${name}`, settings);
3636

3737
return {
38+
keys: { name },
3839
image: (() => {
3940
return also(new Image(), img => {
4041
img.loading = 'lazy';

heartbeat_monitor/SampleCardProviderPlugin.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export function apply() {
1111
});
1212
signal.throwIfAborted();
1313
return {
14+
keys: { name: String(number) },
1415
image: (() => {
1516
return also(new Image(), img => {
1617
img.loading = "lazy";

heartbeat_monitor/index.html

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -410,12 +410,26 @@
410410

411411
document.getElementById("cards").innerHTML = "";
412412
for (const cardPromise of window.KanbanBro.cardProviders.flatMap(provider => provider(abortController.signal))) {
413-
document.getElementById("cards").append(
414-
also(document.createElement("div"), cardDiv => {
415-
cardDiv.className = "card";
413+
cardPromise.then(card => {
414+
abortController.signal.throwIfAborted();
415+
416+
const cardContainer = document.getElementById("cards");
417+
418+
let refNode = null;
419+
const newName = card.keys?.name ?? "";
420+
for (const child of Array.from(cardContainer.children)) {
421+
const existingName = child.card.keys?.name ?? "";
422+
if (existingName.localeCompare(newName) > 0) {
423+
refNode = child;
424+
break;
425+
}
426+
}
427+
428+
cardContainer.insertBefore(
429+
also(document.createElement("div"), cardDiv => {
430+
cardDiv.className = "card";
431+
cardDiv.card = card;
416432

417-
cardPromise.then(card => {
418-
abortController.signal.throwIfAborted();
419433
cardDiv.append(
420434
also(document.createElement("div"), screenshotDiv => {
421435
screenshotDiv.className = "screenshot";
@@ -454,9 +468,10 @@
454468
);
455469
}),
456470
);
457-
});
458-
}),
459-
);
471+
}),
472+
refNode,
473+
);
474+
});
460475
}
461476
}
462477

0 commit comments

Comments
 (0)