feat: enhance image generation and model restoration functionality

This commit is contained in:
Yusuf İpek
2026-01-21 18:29:07 +03:00
parent 5a58582877
commit 7a688e2730
+17 -18
View File
@@ -552,6 +552,7 @@ async function generateImages() {
size: state.imageSize, size: state.imageSize,
quality: state.imageQuality, quality: state.imageQuality,
aspectRatio: state.aspectRatio, aspectRatio: state.aspectRatio,
references: state.references.length > 0 ? [...state.references] : [],
createdAt: new Date().toISOString() createdAt: new Date().toISOString()
}; };
newImages.push(imageData); newImages.push(imageData);
@@ -563,16 +564,13 @@ async function generateImages() {
}); });
if (successCount > 0) { if (successCount > 0) {
// Save to IndexedDB (no size limit!) // Render gallery immediately so user sees results
try {
for (const img of newImages) {
await ImagenDB.saveImage(img);
}
} catch (dbError) {
console.error('Failed to save to IndexedDB:', dbError);
}
renderGallery(); renderGallery();
showToast(`${successCount} image(s) generated!`, 'success'); showToast(`${successCount} image(s) generated!`, 'success');
// Save to IndexedDB in background (don't block UI)
Promise.all(newImages.map(img => ImagenDB.saveImage(img)))
.catch(dbError => console.error('Failed to save to IndexedDB:', dbError));
} else { } else {
showToast('Failed to generate images. Check console for details.', 'error'); showToast('Failed to generate images. Check console for details.', 'error');
} }
@@ -810,9 +808,15 @@ function recreateImage() {
elements.promptInput.value = state.currentImage.prompt; elements.promptInput.value = state.currentImage.prompt;
elements.charCount.textContent = `${state.currentImage.prompt.length} chars`; elements.charCount.textContent = `${state.currentImage.prompt.length} chars`;
// Restore model // Restore model using custom select
elements.modelSelect.value = state.currentImage.model;
state.selectedModel = state.currentImage.model; state.selectedModel = state.currentImage.model;
localStorage.setItem('imagen_model', state.selectedModel);
const modelOption = document.querySelector(`.custom-select-option[data-value="${state.currentImage.model}"]`);
if (modelOption) {
document.querySelectorAll('.custom-select-option').forEach(o => o.classList.remove('selected'));
modelOption.classList.add('selected');
elements.modelSelectValue.textContent = modelOption.textContent;
}
updateGeminiOptionsVisibility(); updateGeminiOptionsVisibility();
// Restore quality/size // Restore quality/size
@@ -835,14 +839,9 @@ function recreateImage() {
}); });
// Restore references // Restore references
if (state.currentImage.references) { if (state.currentImage.references && state.currentImage.references.length > 0) {
state.references = [null, null, null]; state.references = [...state.currentImage.references];
state.currentImage.references.forEach((ref, index) => { renderReferenceSlots();
if (index < 3) {
state.references[index] = ref;
updateReferenceSlot(index);
}
});
} }
closeModal(); closeModal();