Skip to content

Commit 7af1f6a

Browse files
authored
fix(charger): uploading a photo no longer blanks the page (#148)
invalidateExtensions() nulled the extensions cache, unmounting the page and the nav until a manual reload. The upload endpoint already persists and re-resolves server-side, so the client now only cache-busts the local <img> via an onUploaded callback.
1 parent 6074fcb commit 7af1f6a

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

‎app/src/components/ChargerImageButtons.tsx‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@ import { useRef, useState } from 'react';
22
import { ImagePlus } from 'lucide-react';
33
import { useTranslation } from 'react-i18next';
44
import type { ChargerCfg } from '@/data/types';
5-
import { invalidateExtensions } from '@/hooks/useExtensions';
65
import { apiFetch } from '@/data/api-client';
76
import { heliosToast } from '@/lib/toast';
87

98
/** Boton pequeno (arriba-derecha de la tarjeta) para cambiar la foto del
109
* coche: reescala a 460 px de alto en canvas (conserva transparencia) y la
1110
* sube al endpoint del cargador. La imagen vive en dataDir, no en el repo. */
12-
export default function ChargerImageButtons({ charger }: { charger: ChargerCfg }) {
11+
export default function ChargerImageButtons({ charger, onUploaded }: { charger: ChargerCfg; onUploaded?: () => void }) {
1312
const { t } = useTranslation();
1413
const fileRef = useRef<HTMLInputElement>(null);
1514
const [busy, setBusy] = useState(false);
@@ -40,7 +39,7 @@ export default function ChargerImageButtons({ charger }: { charger: ChargerCfg }
4039
body: JSON.stringify({ image: dataUrl }),
4140
headers: { 'Content-Type': 'application/json' },
4241
});
43-
invalidateExtensions();
42+
onUploaded?.();
4443
heliosToast(t('cargador.imageOk'));
4544
} catch (err) {
4645
console.error('[imagen]', err);

‎app/src/pages/Cargador.tsx‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ function ChargerView({ charger, live }: { charger: ChargerCfg; live?: ChargerLiv
124124
const { getHistory } = useEnergyData();
125125

126126
const [curve, setCurve] = useState<ChargerCurvePoint[] | null>(null);
127+
// cache-bust de la foto tras subirla (sin recargar la config global)
128+
const [imgBust, setImgBust] = useState(0);
127129
const [history, setHistory] = useState<HistoryDay[] | null>(null);
128130
const [pwrBusy, setPwrBusy] = useState(false);
129131
const [ampBusy, setAmpBusy] = useState(false);
@@ -319,7 +321,7 @@ function ChargerView({ charger, live }: { charger: ChargerCfg; live?: ChargerLiv
319321
<stateChip.Icon size={14} />
320322
{stateChip.text}
321323
</span>
322-
<ChargerImageButtons charger={charger} />
324+
<ChargerImageButtons charger={charger} onUploaded={() => setImgBust(Date.now())} />
323325
</div>
324326

325327
<div className="flex flex-col gap-5 lg:flex-row lg:items-stretch">
@@ -331,7 +333,7 @@ function ChargerView({ charger, live }: { charger: ChargerCfg; live?: ChargerLiv
331333
>
332334
{charger.imageUrl ? (
333335
<img
334-
src={charger.imageUrl}
336+
src={`${charger.imageUrl}${imgBust ? `?t=${imgBust}` : ''}`}
335337
alt={charger.name}
336338
draggable={false}
337339
className="h-full max-h-full w-full object-contain select-none"

0 commit comments

Comments
 (0)