|
1 | 1 | (function () { |
2 | 2 | 'use strict'; |
3 | 3 |
|
4 | | - var APP_VERSION = '0.5.0'; |
| 4 | + var APP_VERSION = '0.6.0'; |
5 | 5 | var DEMO_MODE = new URLSearchParams(location.search).get('demo') === '1' || location.pathname.replace(/\/+$/, '').endsWith('/demo'); |
6 | 6 | var STORAGE = DEMO_MODE ? 'ote-reader-demo-state-v1' : 'ote-reader-state-v1'; |
7 | 7 | var INSTALL_DISMISSED = 'ote-reader-install-dismissed-v1'; |
|
1158 | 1158 | $('result-count').textContent = sourceLabel() + ' · ' + events.length + (events.length === 1 ? ' evento' : ' eventos'); |
1159 | 1159 | if (!events.length) { |
1160 | 1160 | widget.events = []; |
1161 | | - widget.setAttribute('empty-message', 'No hay eventos con esos filtros.'); |
| 1161 | + widget.style.display = 'none'; |
1162 | 1162 | if (previewMode) showMessage('Este feed no tiene eventos.', 'warn', true); |
1163 | 1163 | else if (!state.feeds.length) showEmptyState(); |
1164 | | - else showMessage('No hay eventos con esos filtros.', 'warn', true); |
| 1164 | + else showFilteredEmptyState(); |
1165 | 1165 | return; |
1166 | 1166 | } |
| 1167 | + widget.style.display = ''; |
1167 | 1168 | clearMessages(); |
1168 | 1169 | if (!embedReady) { |
1169 | 1170 | showMessage('El visor de eventos se está cargando...', 'warn', true); |
|
1180 | 1181 | widget.setAttribute('show-past', 'true'); |
1181 | 1182 | widget.setAttribute('sort', 'none'); |
1182 | 1183 | widget.setAttribute('event-actions', 'none'); |
1183 | | - widget.setAttribute('empty-message', 'No hay eventos con esos filtros.'); |
1184 | 1184 | widget.events = events; |
1185 | 1185 | widget.eventActions = function (context) { |
1186 | 1186 | var event = context.originalEvent; |
|
1460 | 1460 | box.appendChild(empty); |
1461 | 1461 | } |
1462 | 1462 |
|
| 1463 | + function showFilteredEmptyState() { |
| 1464 | + var box = $('messages'); |
| 1465 | + box.replaceChildren(); |
| 1466 | + var empty = document.createElement('section'); |
| 1467 | + empty.className = 'empty-state'; |
| 1468 | + var active = activeFilterChips(); |
| 1469 | + |
| 1470 | + var title = document.createElement('h3'); |
| 1471 | + title.textContent = active.length ? 'No hay eventos con esos filtros' : 'No hay eventos en este apartado'; |
| 1472 | + empty.appendChild(title); |
| 1473 | + |
| 1474 | + if (active.length) { |
| 1475 | + var copy = document.createElement('p'); |
| 1476 | + copy.textContent = 'Quita alguno para ver resultados:'; |
| 1477 | + empty.appendChild(copy); |
| 1478 | + var chips = document.createElement('div'); |
| 1479 | + chips.className = 'chips'; |
| 1480 | + chips.style.maxHeight = 'none'; |
| 1481 | + active.forEach(function (item) { |
| 1482 | + var chip = document.createElement('button'); |
| 1483 | + chip.type = 'button'; |
| 1484 | + chip.className = 'chip is-active'; |
| 1485 | + chip.textContent = item.label + ' ×'; |
| 1486 | + chip.setAttribute('aria-label', 'Quitar filtro: ' + item.label); |
| 1487 | + chip.addEventListener('click', function () { |
| 1488 | + item.clear(); |
| 1489 | + persist(); |
| 1490 | + render(); |
| 1491 | + }); |
| 1492 | + chips.appendChild(chip); |
| 1493 | + }); |
| 1494 | + empty.appendChild(chips); |
| 1495 | + |
| 1496 | + if (active.length > 1) { |
| 1497 | + var actions = document.createElement('div'); |
| 1498 | + actions.className = 'empty-actions'; |
| 1499 | + var clearAll = document.createElement('button'); |
| 1500 | + clearAll.type = 'button'; |
| 1501 | + clearAll.className = 'ghost'; |
| 1502 | + clearAll.textContent = 'Limpiar filtros'; |
| 1503 | + clearAll.addEventListener('click', function () { |
| 1504 | + resetFilters(); |
| 1505 | + persist(); |
| 1506 | + render(); |
| 1507 | + }); |
| 1508 | + actions.appendChild(clearAll); |
| 1509 | + empty.appendChild(actions); |
| 1510 | + } |
| 1511 | + } |
| 1512 | + |
| 1513 | + box.appendChild(empty); |
| 1514 | + } |
| 1515 | + |
| 1516 | + function activeFilterChips() { |
| 1517 | + var list = []; |
| 1518 | + queryTerms(state.filters.q).forEach(function (term) { |
| 1519 | + list.push({ label: '#' + term, clear: function () { toggleQueryTerm(term); } }); |
| 1520 | + }); |
| 1521 | + var modeLabels = { online: 'Online', 'in-person': 'Presencial', hybrid: 'Híbrido' }; |
| 1522 | + if (state.filters.mode) { |
| 1523 | + list.push({ |
| 1524 | + label: 'Formato: ' + (modeLabels[state.filters.mode] || state.filters.mode), |
| 1525 | + clear: function () { state.filters.mode = ''; } |
| 1526 | + }); |
| 1527 | + } |
| 1528 | + if (state.filters.language) { |
| 1529 | + list.push({ label: 'Idioma: ' + state.filters.language, clear: function () { state.filters.language = ''; } }); |
| 1530 | + } |
| 1531 | + if (state.filters.country) { |
| 1532 | + list.push({ label: 'País: ' + state.filters.country, clear: function () { state.filters.country = ''; } }); |
| 1533 | + } |
| 1534 | + if (state.filters.cfp) { |
| 1535 | + list.push({ label: 'CFP abierto', clear: function () { state.filters.cfp = false; } }); |
| 1536 | + } |
| 1537 | + if (state.filters.future) { |
| 1538 | + list.push({ label: 'Solo futuros', clear: function () { state.filters.future = false; } }); |
| 1539 | + } |
| 1540 | + return list; |
| 1541 | + } |
| 1542 | + |
| 1543 | + function resetFilters() { |
| 1544 | + state.filters.q = ''; |
| 1545 | + state.filters.mode = ''; |
| 1546 | + state.filters.language = ''; |
| 1547 | + state.filters.country = ''; |
| 1548 | + state.filters.cfp = false; |
| 1549 | + state.filters.future = false; |
| 1550 | + } |
| 1551 | + |
1463 | 1552 | function subscribe(rawUrl, categoryId) { |
1464 | 1553 | var url; |
1465 | 1554 | try { url = normaliseUrl(rawUrl); } catch (e) { |
|
0 commit comments