From 1ff1c5be6420d5088a94285bad2faf4258de42e4 Mon Sep 17 00:00:00 2001 From: AUTOMATIC1111 <16777216c@gmail.com> Date: Fri, 2 Feb 2024 20:51:54 +0300 Subject: [PATCH] fix refresh button forgetting sort order for extra networks #14588 --- javascript/extraNetworks.js | 18 ++++++++++++------ javascript/ui.js | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/javascript/extraNetworks.js b/javascript/extraNetworks.js index f96af4475..9a3a23926 100644 --- a/javascript/extraNetworks.js +++ b/javascript/extraNetworks.js @@ -48,7 +48,7 @@ function setupExtraNetworksForTab(tabname) { return; // `return` is equivalent of `continue` but for forEach loops. } - var applyFilter = function() { + var applyFilter = function(force) { var searchTerm = search.value.toLowerCase(); gradioApp().querySelectorAll('#' + tabname + '_extra_tabs div.card').forEach(function(elem) { var searchOnly = elem.querySelector('.search_only'); @@ -67,17 +67,17 @@ function setupExtraNetworksForTab(tabname) { } }); - applySort(); + applySort(force); }; - var applySort = function() { + var applySort = function(force) { var cards = gradioApp().querySelectorAll('#' + tabname + '_extra_tabs div.card'); var reverse = sort_dir.dataset.sortdir == "Descending"; var sortKey = sort_mode.dataset.sortmode.toLowerCase().replace("sort", "").replaceAll(" ", "_").replace(/_+$/, "").trim() || "name"; sortKey = "sort" + sortKey.charAt(0).toUpperCase() + sortKey.slice(1); var sortKeyStore = sortKey + "-" + (reverse ? "Descending" : "Ascending") + "-" + cards.length; - if (sortKeyStore == sort_mode.dataset.sortkey) { + if (sortKeyStore == sort_mode.dataset.sortkey && !force) { return; } sort_mode.dataset.sortkey = sortKeyStore; @@ -167,11 +167,17 @@ function extraNetworksTabSelected(tabname, id, showPrompt, showNegativePrompt, t } function applyExtraNetworkFilter(tabname_full) { - setTimeout(extraNetworksApplyFilter[tabname_full], 1); + var doFilter = function() { + extraNetworksApplyFilter[tabname_full](true); + }; + setTimeout(doFilter, 1); } function applyExtraNetworkSort(tabname_full) { - setTimeout(extraNetworksApplySort[tabname_full], 1); + var doSort = function() { + extraNetworksApplySort[tabname_full](true); + }; + setTimeout(doSort, 1); } var extraNetworksApplyFilter = {}; diff --git a/javascript/ui.js b/javascript/ui.js index d5d85bb67..9e66cd245 100644 --- a/javascript/ui.js +++ b/javascript/ui.js @@ -126,7 +126,7 @@ function setSubmitButtonsVisibility(tabname, showInterrupt, showSkip, showInterr } function showSubmitButtons(tabname, show) { - setSubmitButtonsVisibility(tabname, ! show, !show, false); + setSubmitButtonsVisibility(tabname, !show, !show, false); } function showSubmitInterruptingPlaceholder(tabname) {