fix: properly track featured_photo state in menu editor
This commit is contained in:
@@ -1524,7 +1524,8 @@ function MenuSection({ items, setItems, images, onToast }: any) {
|
|||||||
|
|
||||||
function MenuEditor({ item, setItem, onSave, onCancel }: any) {
|
function MenuEditor({ item, setItem, onSave, onCancel }: any) {
|
||||||
const [localPhotos, setLocalPhotos] = useState<string[]>(item.photos || []);
|
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 addPhotos = async (files: FileList) => {
|
||||||
const newPhotos: string[] = [];
|
const newPhotos: string[] = [];
|
||||||
@@ -1565,13 +1566,13 @@ function MenuEditor({ item, setItem, onSave, onCancel }: any) {
|
|||||||
<img
|
<img
|
||||||
src={ph}
|
src={ph}
|
||||||
alt=""
|
alt=""
|
||||||
onClick={() => setItem({ ...i, featured_photo: ph })}
|
onClick={() => setFeaturedPhoto(ph)}
|
||||||
style={{
|
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',
|
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>
|
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>
|
</div>
|
||||||
))}
|
))}
|
||||||
|
|||||||
Reference in New Issue
Block a user