Spaces:
Running
Running
Update src/templates/dashboard/deep_diver.html
Browse files
src/templates/dashboard/deep_diver.html
CHANGED
|
@@ -167,14 +167,36 @@
|
|
| 167 |
height: 14px;
|
| 168 |
|
| 169 |
}
|
| 170 |
-
/*
|
| 171 |
-
.btn-action.active-watch {
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
}
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
/* Sub-Branding Colors */
|
| 179 |
#link-cg { border-color: rgba(140, 198, 63, 0.3); }
|
| 180 |
#link-tv { border-color: rgba(41, 98, 255, 0.3); }
|
|
@@ -447,12 +469,14 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
| 447 |
}
|
| 448 |
});
|
| 449 |
|
| 450 |
-
//
|
| 451 |
function updateWatchlistUI(isWatched) {
|
| 452 |
const btn = document.getElementById('btn-watchlist');
|
| 453 |
const text = document.getElementById('watchlist-text');
|
| 454 |
|
| 455 |
-
//
|
|
|
|
|
|
|
| 456 |
if (isWatched) {
|
| 457 |
btn.classList.add('active-watch');
|
| 458 |
text.innerText = "Watched";
|
|
@@ -465,31 +489,47 @@ function updateWatchlistUI(isWatched) {
|
|
| 465 |
async function toggleWatchlist() {
|
| 466 |
if (!currentCoinData) return;
|
| 467 |
|
| 468 |
-
const
|
|
|
|
|
|
|
| 469 |
const action = isCurrentlyWatched ? 'remove' : 'add';
|
| 470 |
|
| 471 |
-
|
| 472 |
-
|
| 473 |
-
|
| 474 |
-
|
| 475 |
-
|
| 476 |
-
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
|
| 480 |
-
|
| 481 |
-
|
| 482 |
-
|
| 483 |
-
|
| 484 |
-
|
| 485 |
-
|
| 486 |
-
|
| 487 |
-
|
| 488 |
-
|
| 489 |
-
|
| 490 |
-
|
| 491 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 492 |
}
|
| 493 |
-
|
|
|
|
| 494 |
</script>
|
| 495 |
{% endblock %}
|
|
|
|
| 167 |
height: 14px;
|
| 168 |
|
| 169 |
}
|
| 170 |
+
/* --- Enhanced Watchlist Toggle --- */
|
| 171 |
+
.btn-action.active-watch {
|
| 172 |
+
border-color: var(--accent-orange, #f59e0b) !important;
|
| 173 |
+
color: var(--accent-orange, #f59e0b) !important;
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
.btn-action.active-watch svg {
|
| 177 |
+
fill: var(--accent-orange, #f59e0b);
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
/* Hover effect to signal removal */
|
| 181 |
+
.btn-action.active-watch:hover {
|
| 182 |
+
background: rgba(239, 68, 68, 0.1) !important;
|
| 183 |
+
border-color: #ef4444 !important;
|
| 184 |
+
color: #ef4444 !important;
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
.btn-action.active-watch:hover svg {
|
| 188 |
+
fill: #ef4444;
|
| 189 |
+
stroke: #ef4444;
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
/* Swap text on hover */
|
| 193 |
+
.btn-action.active-watch:hover #watchlist-text {
|
| 194 |
+
display: none;
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
.btn-action.active-watch:hover::after {
|
| 198 |
+
content: "REMOVE";
|
| 199 |
+
}
|
| 200 |
/* Sub-Branding Colors */
|
| 201 |
#link-cg { border-color: rgba(140, 198, 63, 0.3); }
|
| 202 |
#link-tv { border-color: rgba(41, 98, 255, 0.3); }
|
|
|
|
| 469 |
}
|
| 470 |
});
|
| 471 |
|
| 472 |
+
// Sync UI based on backend state and set data attribute for logic
|
| 473 |
function updateWatchlistUI(isWatched) {
|
| 474 |
const btn = document.getElementById('btn-watchlist');
|
| 475 |
const text = document.getElementById('watchlist-text');
|
| 476 |
|
| 477 |
+
// Set state on the element itself (Senior Best Practice)
|
| 478 |
+
btn.setAttribute('data-is-watched', isWatched);
|
| 479 |
+
|
| 480 |
if (isWatched) {
|
| 481 |
btn.classList.add('active-watch');
|
| 482 |
text.innerText = "Watched";
|
|
|
|
| 489 |
async function toggleWatchlist() {
|
| 490 |
if (!currentCoinData) return;
|
| 491 |
|
| 492 |
+
const btn = document.getElementById('btn-watchlist');
|
| 493 |
+
// Read state from data attribute instead of parsing text
|
| 494 |
+
const isCurrentlyWatched = btn.getAttribute('data-is-watched') === 'true';
|
| 495 |
const action = isCurrentlyWatched ? 'remove' : 'add';
|
| 496 |
|
| 497 |
+
// Update immediately for a fast feel
|
| 498 |
+
updateWatchlistUI(!isCurrentlyWatched);
|
| 499 |
+
|
| 500 |
+
try {
|
| 501 |
+
const res = await fetch('/api/watchlist/toggle', {
|
| 502 |
+
method: 'POST',
|
| 503 |
+
headers: { 'Content-Type': 'application/json' },
|
| 504 |
+
body: JSON.stringify({
|
| 505 |
+
coin_id: currentCoinData.id,
|
| 506 |
+
symbol: currentCoinData.vitals.symbol,
|
| 507 |
+
name: currentCoinData.vitals.name,
|
| 508 |
+
price: currentCoinData.vitals.price,
|
| 509 |
+
vtmr: currentCoinData.ratios.vtmr,
|
| 510 |
+
mcap: currentCoinData.vitals.mcap,
|
| 511 |
+
chg_1y: currentCoinData.velocity.y1 || currentCoinData.velocity.yearly,
|
| 512 |
+
chg_24h: currentCoinData.velocity.h24,
|
| 513 |
+
chg_7d: currentCoinData.velocity.d7,
|
| 514 |
+
chg_30d: currentCoinData.velocity.m1,
|
| 515 |
+
action: action
|
| 516 |
+
})
|
| 517 |
+
});
|
| 518 |
+
|
| 519 |
+
const result = await res.json();
|
| 520 |
+
|
| 521 |
+
// Ensure UI matches actual server state
|
| 522 |
+
if (result.status === "success") {
|
| 523 |
+
updateWatchlistUI(result.is_watched);
|
| 524 |
+
} else {
|
| 525 |
+
updateWatchlistUI(isCurrentlyWatched);
|
| 526 |
+
console.error("Watchlist sync error:", result.message);
|
| 527 |
+
}
|
| 528 |
+
} catch (err) {
|
| 529 |
+
updateWatchlistUI(isCurrentlyWatched);
|
| 530 |
+
console.error("Watchlist toggle failed:", err);
|
| 531 |
}
|
| 532 |
+
}
|
| 533 |
+
|
| 534 |
</script>
|
| 535 |
{% endblock %}
|