Skip to content

patch: apply menu updates for relevant types only #462

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions web/js/betterCombos.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,23 @@ function showImage(relativeToEl, imageEl) {
document.body.appendChild(imageEl);
}

let imagePromises = {};
let imagesByType = {};
const loadImageList = async (type) => {
imagesByType[type] = await (await api.fetchApi(`/pysssss/images/${type}`)).json();
if (!imagePromises[type]) {
imagePromises[type] = api.fetchApi(`/pysssss/images/${type}`)
.then(resp => resp.json())
.then(data => {
imagesByType[type] = data;
return data;
})
.catch(err => {
console.error(`Error loading images for ${type}:`, err);
imagesByType[type] = {};
return {};
});
}
return imagePromises[type];
};

app.registerExtension({
Expand Down Expand Up @@ -157,8 +171,6 @@ app.registerExtension({
`,
parent: document.body,
});
const p1 = loadImageList("checkpoints");
const p2 = loadImageList("loras");

const refreshComboInNodes = app.refreshComboInNodes;
app.refreshComboInNodes = async function () {
Expand Down Expand Up @@ -192,8 +204,7 @@ app.registerExtension({

const updateMenu = async (menu, type) => {
try {
await p1;
await p2;
await loadImageList(type);
} catch (error) {
console.error(error);
console.error("Error loading pysssss.betterCombos data");
Expand Down