Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions app/src/components/ChargerImageButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ import { useRef, useState } from 'react';
import { ImagePlus } from 'lucide-react';
import { useTranslation } from 'react-i18next';
import type { ChargerCfg } from '@/data/types';
import { invalidateExtensions } from '@/hooks/useExtensions';
import { apiFetch } from '@/data/api-client';
import { heliosToast } from '@/lib/toast';

/** Boton pequeno (arriba-derecha de la tarjeta) para cambiar la foto del
* coche: reescala a 460 px de alto en canvas (conserva transparencia) y la
* sube al endpoint del cargador. La imagen vive en dataDir, no en el repo. */
export default function ChargerImageButtons({ charger }: { charger: ChargerCfg }) {
export default function ChargerImageButtons({ charger, onUploaded }: { charger: ChargerCfg; onUploaded?: () => void }) {
const { t } = useTranslation();
const fileRef = useRef<HTMLInputElement>(null);
const [busy, setBusy] = useState(false);
Expand Down Expand Up @@ -40,7 +39,7 @@ export default function ChargerImageButtons({ charger }: { charger: ChargerCfg }
body: JSON.stringify({ image: dataUrl }),
headers: { 'Content-Type': 'application/json' },
});
invalidateExtensions();
onUploaded?.();
heliosToast(t('cargador.imageOk'));
} catch (err) {
console.error('[imagen]', err);
Expand Down
6 changes: 4 additions & 2 deletions app/src/pages/Cargador.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@
const { getHistory } = useEnergyData();

const [curve, setCurve] = useState<ChargerCurvePoint[] | null>(null);
// cache-bust de la foto tras subirla (sin recargar la config global)
const [imgBust, setImgBust] = useState(0);
const [history, setHistory] = useState<HistoryDay[] | null>(null);
const [pwrBusy, setPwrBusy] = useState(false);
const [ampBusy, setAmpBusy] = useState(false);
Expand Down Expand Up @@ -269,7 +271,7 @@
}
}
return out;
}, [history, solarHistory, period, anchor, today, i18n.language]);

Check warning on line 274 in app/src/pages/Cargador.tsx

View workflow job for this annotation

GitHub Actions / frontend

React Hook useMemo has an unnecessary dependency: 'i18n.language'. Either exclude it or remove the dependency array

const stats = useMemo(() => {
const kwh = rows.reduce((acc, r) => acc + r.kwh, 0);
Expand Down Expand Up @@ -319,7 +321,7 @@
<stateChip.Icon size={14} />
{stateChip.text}
</span>
<ChargerImageButtons charger={charger} />
<ChargerImageButtons charger={charger} onUploaded={() => setImgBust(Date.now())} />
</div>

<div className="flex flex-col gap-5 lg:flex-row lg:items-stretch">
Expand All @@ -331,7 +333,7 @@
>
{charger.imageUrl ? (
<img
src={charger.imageUrl}
src={`${charger.imageUrl}${imgBust ? `?t=${imgBust}` : ''}`}
alt={charger.name}
draggable={false}
className="h-full max-h-full w-full object-contain select-none"
Expand Down
Loading