matias-cataife commited on
Commit
e6eee39
·
1 Parent(s): ca10378

fix: drawer redraw after manual enrich uses real score from refreshed ALL_PLAYERS

Browse files
Files changed (1) hide show
  1. static/app.js +11 -18
static/app.js CHANGED
@@ -1376,24 +1376,17 @@ async function enrichByUrl(pid, season, btn) {
1376
  status.style.color = 'var(--good, #34d399)';
1377
  status.textContent = `OK: ${res.scraped._scraped_name || ''} ${res.scraped.tm_market_value || ''}` +
1378
  (res.pushed_to_hf ? ' · guardado en dataset HF' : ` · ⚠ no se pudo subir a HF: ${res.push_error || 'unknown'}`);
1379
- // refresh the drawer with updated player detail
1380
- setTimeout(async () => {
1381
- try {
1382
- const p = await API.player(pid, season);
1383
- // map detail-shape back into card-shape used by playerDetailHTML
1384
- const shaped = {
1385
- pid: p.playerId, j: p.jugador, e: p.equipo, c: p.competencia, t: p.season,
1386
- p: p.pos, age: p.age, nat: p.nationality, foot: p.foot, ht: p.height,
1387
- mv: p.mv, ct: p.contract, photo: p.photo, tm_url: p.tm_url,
1388
- ss: 0, ps: 0, pf: 0,
1389
- min: p.minutos, mp: p.partidos, n_comp: p.n_competitions,
1390
- bl: p.blocks || {},
1391
- };
1392
- document.getElementById('tableDrawerBody').innerHTML = playerDetailHTML(shaped);
1393
- } catch (e) { /* keep drawer as-is */ }
1394
- // also refresh the table so the row picks up the new tm_url + mv
1395
- refreshFromServer();
1396
- }, 400);
1397
  } catch (e) {
1398
  status.style.color = '#f87171';
1399
  status.textContent = 'Error: ' + (e.message || e);
 
1376
  status.style.color = 'var(--good, #34d399)';
1377
  status.textContent = `OK: ${res.scraped._scraped_name || ''} ${res.scraped.tm_market_value || ''}` +
1378
  (res.pushed_to_hf ? ' · guardado en dataset HF' : ` · ⚠ no se pudo subir a HF: ${res.push_error || 'unknown'}`);
1379
+ // Refresh the table FIRST so ALL_PLAYERS picks up the freshly scored row,
1380
+ // then redraw the drawer using the up-to-date row (real ss/ps/pf, not zeroes).
1381
+ try {
1382
+ const result = await API.score(buildScorePayload());
1383
+ ALL_PLAYERS = result.rows;
1384
+ if (typeof onFilterChange === 'function') onFilterChange();
1385
+ } catch (e) { /* keep going */ }
1386
+ const updated = ALL_PLAYERS.find(p => p.pid === pid && (p.t || '') === (season || ''));
1387
+ if (updated) {
1388
+ document.getElementById('tableDrawerBody').innerHTML = playerDetailHTML(updated);
1389
+ }
 
 
 
 
 
 
 
1390
  } catch (e) {
1391
  status.style.color = '#f87171';
1392
  status.textContent = 'Error: ' + (e.message || e);