Refactor map item loading logic into a dedicated function
This commit is contained in:
23
src/main.js
23
src/main.js
@@ -358,6 +358,17 @@ async function pathToObjectUrl(path) {
|
||||
return convertFileSrc(path);
|
||||
}
|
||||
|
||||
function applyPromptFromMap(item) {
|
||||
promptInput.value = typeof item?.prompt === 'string' ? item.prompt : '';
|
||||
}
|
||||
|
||||
function loadMapItem(item, fileUrl, statusPrefix = 'Loaded') {
|
||||
currentMapPath = item.path;
|
||||
applyPromptFromMap(item);
|
||||
setSkyFromUrl(fileUrl);
|
||||
setStatus(`${statusPrefix} ${item.filename}`);
|
||||
}
|
||||
|
||||
function resetProgressState() {
|
||||
progressState = {
|
||||
upscale: null,
|
||||
@@ -468,23 +479,17 @@ async function refreshThumbnails(selectedPath, shouldLoadSelection = true) {
|
||||
el.title = item.filename;
|
||||
el.addEventListener('click', () => {
|
||||
if (fileUrl) {
|
||||
currentMapPath = item.path;
|
||||
setSkyFromUrl(fileUrl);
|
||||
setStatus(`Loaded ${item.filename}`);
|
||||
loadMapItem(item, fileUrl);
|
||||
}
|
||||
});
|
||||
thumbList.appendChild(el);
|
||||
|
||||
if (fileUrl) {
|
||||
if (shouldLoadSelection && idx === 0 && !selectedPath) {
|
||||
currentMapPath = item.path;
|
||||
setSkyFromUrl(fileUrl);
|
||||
setStatus(`Showing ${item.filename}`);
|
||||
loadMapItem(item, fileUrl, 'Showing');
|
||||
}
|
||||
if (shouldLoadSelection && selectedPath && selectedPath === item.path) {
|
||||
currentMapPath = item.path;
|
||||
setSkyFromUrl(fileUrl);
|
||||
setStatus(`Showing ${item.filename}`);
|
||||
loadMapItem(item, fileUrl, 'Showing');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user