Spaces:
Sleeping
Sleeping
Update static/app.js
Browse files- static/app.js +20 -17
static/app.js
CHANGED
|
@@ -1358,7 +1358,6 @@ async function generateCustomPose() {
|
|
| 1358 |
if (progressPct) progressPct.textContent = '50%';
|
| 1359 |
if (progressBar) progressBar.style.width = '50%';
|
| 1360 |
|
| 1361 |
-
// Use direct fetch, not apiRequest, to avoid overriding Content-Type
|
| 1362 |
const response = await fetch(`${CONFIG.API_BASE}/api/generate-pose`, {
|
| 1363 |
method: 'POST',
|
| 1364 |
body: formData,
|
|
@@ -1369,7 +1368,6 @@ async function generateCustomPose() {
|
|
| 1369 |
throw new Error(result.error || 'Generation failed');
|
| 1370 |
}
|
| 1371 |
|
| 1372 |
-
// Check for error from the generator
|
| 1373 |
if (result.error) {
|
| 1374 |
throw new Error(result.error);
|
| 1375 |
}
|
|
@@ -1378,7 +1376,6 @@ async function generateCustomPose() {
|
|
| 1378 |
if (progressPct) progressPct.textContent = '80%';
|
| 1379 |
if (progressBar) progressBar.style.width = '80%';
|
| 1380 |
|
| 1381 |
-
// Store the result only if generation succeeded
|
| 1382 |
STATE.generatedPose = result;
|
| 1383 |
showGenerationResults(result);
|
| 1384 |
|
|
@@ -1416,11 +1413,15 @@ async function generateCustomPose() {
|
|
| 1416 |
}
|
| 1417 |
}
|
| 1418 |
|
| 1419 |
-
// βββ UPDATED: showGenerationResults with
|
| 1420 |
function showGenerationResults(result) {
|
|
|
|
| 1421 |
const container = el('generation-results');
|
| 1422 |
const preview = el('generated-pose-preview');
|
| 1423 |
-
if (!container || !preview)
|
|
|
|
|
|
|
|
|
|
| 1424 |
|
| 1425 |
container.classList.remove('hidden');
|
| 1426 |
|
|
@@ -1447,10 +1448,18 @@ function showGenerationResults(result) {
|
|
| 1447 |
</div>
|
| 1448 |
</div>
|
| 1449 |
<div style="display:flex;gap:8px;">
|
| 1450 |
-
<button
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1451 |
πΎ Save Pose
|
| 1452 |
</button>
|
| 1453 |
-
<button
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1454 |
Discard
|
| 1455 |
</button>
|
| 1456 |
</div>
|
|
@@ -1467,12 +1476,13 @@ function showGenerationResults(result) {
|
|
| 1467 |
</div>
|
| 1468 |
`;
|
| 1469 |
|
| 1470 |
-
//
|
| 1471 |
preview.removeEventListener('click', handlePreviewClick);
|
| 1472 |
preview.addEventListener('click', handlePreviewClick);
|
|
|
|
| 1473 |
}
|
| 1474 |
|
| 1475 |
-
// βββ Event handler for preview buttons βββ
|
| 1476 |
function handlePreviewClick(e) {
|
| 1477 |
const target = e.target.closest('[data-action]');
|
| 1478 |
if (!target) return;
|
|
@@ -1490,12 +1500,12 @@ async function saveGeneratedPose() {
|
|
| 1490 |
|
| 1491 |
if (!STATE.generatedPose) {
|
| 1492 |
showToast('No pose to save', 'error');
|
|
|
|
| 1493 |
return;
|
| 1494 |
}
|
| 1495 |
|
| 1496 |
console.log('π¦ Pose data:', STATE.generatedPose);
|
| 1497 |
|
| 1498 |
-
// Find and disable the save button using data-action
|
| 1499 |
const saveBtn = document.querySelector('[data-action="save-pose"]');
|
| 1500 |
if (saveBtn) {
|
| 1501 |
saveBtn.disabled = true;
|
|
@@ -1522,11 +1532,7 @@ async function saveGeneratedPose() {
|
|
| 1522 |
|
| 1523 |
if (result.success) {
|
| 1524 |
showToast(`β
Pose "${STATE.generatedPose.pose_name}" saved!`, 'success', 4000);
|
| 1525 |
-
|
| 1526 |
-
// Reload poses and wait for completion
|
| 1527 |
await fetchPoses();
|
| 1528 |
-
|
| 1529 |
-
// Navigate to home and search
|
| 1530 |
goHome();
|
| 1531 |
const searchInput = el('home-search-input');
|
| 1532 |
if (searchInput && STATE.generatedPose) {
|
|
@@ -1542,16 +1548,13 @@ async function saveGeneratedPose() {
|
|
| 1542 |
} catch (error) {
|
| 1543 |
console.error('β Save error:', error);
|
| 1544 |
showToast(`β Save failed: ${error.message}`, 'error', 5000);
|
| 1545 |
-
// Re-enable button on error
|
| 1546 |
if (saveBtn) {
|
| 1547 |
saveBtn.disabled = false;
|
| 1548 |
saveBtn.textContent = 'πΎ Retry Save';
|
| 1549 |
}
|
| 1550 |
}
|
| 1551 |
-
// If successful, button will be removed by navigation; no need to re-enable
|
| 1552 |
}
|
| 1553 |
|
| 1554 |
-
// βββ discardGeneratedPose βββ
|
| 1555 |
function discardGeneratedPose() {
|
| 1556 |
STATE.generatedPose = null;
|
| 1557 |
const container = el('generation-results');
|
|
|
|
| 1358 |
if (progressPct) progressPct.textContent = '50%';
|
| 1359 |
if (progressBar) progressBar.style.width = '50%';
|
| 1360 |
|
|
|
|
| 1361 |
const response = await fetch(`${CONFIG.API_BASE}/api/generate-pose`, {
|
| 1362 |
method: 'POST',
|
| 1363 |
body: formData,
|
|
|
|
| 1368 |
throw new Error(result.error || 'Generation failed');
|
| 1369 |
}
|
| 1370 |
|
|
|
|
| 1371 |
if (result.error) {
|
| 1372 |
throw new Error(result.error);
|
| 1373 |
}
|
|
|
|
| 1376 |
if (progressPct) progressPct.textContent = '80%';
|
| 1377 |
if (progressBar) progressBar.style.width = '80%';
|
| 1378 |
|
|
|
|
| 1379 |
STATE.generatedPose = result;
|
| 1380 |
showGenerationResults(result);
|
| 1381 |
|
|
|
|
| 1413 |
}
|
| 1414 |
}
|
| 1415 |
|
| 1416 |
+
// βββ UPDATED: showGenerationResults with inline onclick + delegation βββ
|
| 1417 |
function showGenerationResults(result) {
|
| 1418 |
+
console.log('π’ showGenerationResults called with result:', result);
|
| 1419 |
const container = el('generation-results');
|
| 1420 |
const preview = el('generated-pose-preview');
|
| 1421 |
+
if (!container || !preview) {
|
| 1422 |
+
console.error('β Container or preview not found');
|
| 1423 |
+
return;
|
| 1424 |
+
}
|
| 1425 |
|
| 1426 |
container.classList.remove('hidden');
|
| 1427 |
|
|
|
|
| 1448 |
</div>
|
| 1449 |
</div>
|
| 1450 |
<div style="display:flex;gap:8px;">
|
| 1451 |
+
<button
|
| 1452 |
+
data-action="save-pose"
|
| 1453 |
+
onclick="saveGeneratedPose()"
|
| 1454 |
+
class="btn-primary"
|
| 1455 |
+
style="font-size:13px;padding:10px 28px;">
|
| 1456 |
πΎ Save Pose
|
| 1457 |
</button>
|
| 1458 |
+
<button
|
| 1459 |
+
data-action="discard-pose"
|
| 1460 |
+
onclick="discardGeneratedPose()"
|
| 1461 |
+
class="btn-outline"
|
| 1462 |
+
style="font-size:13px;padding:10px 20px;">
|
| 1463 |
Discard
|
| 1464 |
</button>
|
| 1465 |
</div>
|
|
|
|
| 1476 |
</div>
|
| 1477 |
`;
|
| 1478 |
|
| 1479 |
+
// Also attach the event delegation as a backup
|
| 1480 |
preview.removeEventListener('click', handlePreviewClick);
|
| 1481 |
preview.addEventListener('click', handlePreviewClick);
|
| 1482 |
+
console.log('β
Event listener attached to preview');
|
| 1483 |
}
|
| 1484 |
|
| 1485 |
+
// βββ Event handler for preview buttons (backup) βββ
|
| 1486 |
function handlePreviewClick(e) {
|
| 1487 |
const target = e.target.closest('[data-action]');
|
| 1488 |
if (!target) return;
|
|
|
|
| 1500 |
|
| 1501 |
if (!STATE.generatedPose) {
|
| 1502 |
showToast('No pose to save', 'error');
|
| 1503 |
+
console.warn('β οΈ STATE.generatedPose is null/undefined');
|
| 1504 |
return;
|
| 1505 |
}
|
| 1506 |
|
| 1507 |
console.log('π¦ Pose data:', STATE.generatedPose);
|
| 1508 |
|
|
|
|
| 1509 |
const saveBtn = document.querySelector('[data-action="save-pose"]');
|
| 1510 |
if (saveBtn) {
|
| 1511 |
saveBtn.disabled = true;
|
|
|
|
| 1532 |
|
| 1533 |
if (result.success) {
|
| 1534 |
showToast(`β
Pose "${STATE.generatedPose.pose_name}" saved!`, 'success', 4000);
|
|
|
|
|
|
|
| 1535 |
await fetchPoses();
|
|
|
|
|
|
|
| 1536 |
goHome();
|
| 1537 |
const searchInput = el('home-search-input');
|
| 1538 |
if (searchInput && STATE.generatedPose) {
|
|
|
|
| 1548 |
} catch (error) {
|
| 1549 |
console.error('β Save error:', error);
|
| 1550 |
showToast(`β Save failed: ${error.message}`, 'error', 5000);
|
|
|
|
| 1551 |
if (saveBtn) {
|
| 1552 |
saveBtn.disabled = false;
|
| 1553 |
saveBtn.textContent = 'πΎ Retry Save';
|
| 1554 |
}
|
| 1555 |
}
|
|
|
|
| 1556 |
}
|
| 1557 |
|
|
|
|
| 1558 |
function discardGeneratedPose() {
|
| 1559 |
STATE.generatedPose = null;
|
| 1560 |
const container = el('generation-results');
|