fix: properly track featured_photo state in menu editor

This commit is contained in:
2026-06-30 00:13:30 -05:00
parent 271457dfa5
commit ef2bfa5f05
+5 -4
View File
@@ -1524,7 +1524,8 @@ function MenuSection({ items, setItems, images, onToast }: any) {
function MenuEditor({ item, setItem, onSave, onCancel }: any) {
const [localPhotos, setLocalPhotos] = useState<string[]>(item.photos || []);
const i = { ...item, photos: localPhotos };
const [featuredPhoto, setFeaturedPhoto] = useState<string | null>(item.featured_photo || null);
const i = { ...item, photos: localPhotos, featured_photo: featuredPhoto };
const addPhotos = async (files: FileList) => {
const newPhotos: string[] = [];
@@ -1565,13 +1566,13 @@ function MenuEditor({ item, setItem, onSave, onCancel }: any) {
<img
src={ph}
alt=""
onClick={() => setItem({ ...i, featured_photo: ph })}
onClick={() => setFeaturedPhoto(ph)}
style={{
width: 64, height: 48, objectFit: 'cover', borderRadius: 6, border: i.featured_photo === ph ? `2px solid ${C.gold}` : '1px solid #eee',
width: 64, height: 48, objectFit: 'cover', borderRadius: 6, border: featuredPhoto === ph ? `2px solid ${C.gold}` : '1px solid #eee',
cursor: 'pointer',
}}
/>
<button onClick={() => setLocalPhotos(prev => prev.filter((_, j) => j !== idx))}
<button onClick={() => { setLocalPhotos(prev => prev.filter((_, j) => j !== idx)); if (featuredPhoto === ph) setFeaturedPhoto(null); }}
style={{ position: 'absolute', top: -4, right: -4, width: 18, height: 18, borderRadius: '50%', background: C.danger, color: '#fff', border: 'none', cursor: 'pointer', fontSize: '11px', lineHeight: 18, padding: 0 }}>×</button>
</div>
))}