Skip to content
Open
Show file tree
Hide file tree
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
9 changes: 4 additions & 5 deletions web_app/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,10 @@ <h2 id="contentHeading">Lyrics</h2>
</div>
</div>

<button id="generateBtn" class="primary-btn">Generate Poster</button>
<button id="generateBtn" class="primary-btn">
<span class="btn-text">Generate Poster</span>
<div class="spinner"></div>
</button>
</div>
</div>

Expand All @@ -143,10 +146,6 @@ <h2>Poster</h2>
</main>
</div>
<div id="toastContainer" class="toast-container"></div>
<div id="loadingOverlay" class="loading-overlay" style="display: none;">
<div class="spinner"></div>
<p>Generating your masterpiece...</p>
</div>
<script src="/static/script.js?v=21"></script>
</body>

Expand Down
23 changes: 18 additions & 5 deletions web_app/static/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const startLineInput = document.getElementById('startLine');
const endLineInput = document.getElementById('endLine');
const themeInput = document.getElementById('themeInput');
const fontInput = document.getElementById('fontInput');
const loadingOverlay = document.getElementById('loadingOverlay');

let currentMetadata = null;
let searchDebounceTimer = null;
Expand Down Expand Up @@ -613,7 +612,15 @@ function handleLyricLineClick(lineNumber) {
async function generatePoster() {
if (!currentMetadata) return;

loadingOverlay.style.display = 'flex';
const btnText = generateBtn.querySelector('.btn-text');
if (!btnText) return;

// --- New Loading State Logic ---
const originalText = btnText.textContent;
generateBtn.classList.add('loading');
generateBtn.disabled = true;
btnText.textContent = 'Generating...';
generateBtn.setAttribute('aria-label', 'Generating poster, please wait.');

const indexingToggle = document.getElementById('indexingToggle');
const accentToggle = document.getElementById('accentToggle');
Expand All @@ -635,8 +642,10 @@ async function generatePoster() {
const end = endVal;

if (isNaN(start) || isNaN(end) || start >= end) {
loadingOverlay.style.display = 'none';
showToast("Please enter a valid range (Start must be less than End).", "error");
// --- Reset Loading State ---
generateBtn.classList.remove('loading');
generateBtn.disabled = false;
return;
}

Expand Down Expand Up @@ -669,13 +678,17 @@ async function generatePoster() {
posterContainer.innerHTML = '';
posterContainer.appendChild(img);
showDownloadButton(imageUrl, data.filename);
loadingOverlay.style.display = 'none';
};

} catch (error) {
console.error("Generation failed", error);
showToast(`Error: ${error.message}`, "error");
loadingOverlay.style.display = 'none';
} finally {
// --- Reset Loading State ---
generateBtn.classList.remove('loading');
generateBtn.disabled = false;
btnText.textContent = originalText;
generateBtn.removeAttribute('aria-label');
}
}

Expand Down
33 changes: 33 additions & 0 deletions web_app/static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,39 @@ header p {
background: var(--accent-color);
color: #1a1a1f;
width: 100%;
position: relative; /* For spinner placement */
}

.primary-btn .btn-text {
transition: opacity 0.2s ease-out;
}

/* Spinner is inside the button, inheriting from the main .spinner keyframes */
.primary-btn .spinner {
position: absolute;
width: 20px;
height: 20px;
border-width: 2px;
border-color: rgba(0, 0, 0, 0.2);
border-top-color: #1a1a1f; /* Match button text color */
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: none; /* Hidden by default */
}

.primary-btn.loading {
cursor: not-allowed;
pointer-events: none;
}

.primary-btn.loading .btn-text {
opacity: 0;
visibility: hidden; /* Hide from screen readers */
}

.primary-btn.loading .spinner {
display: block;
}

.primary-btn:hover {
Expand Down