fix backgroundselector

This commit is contained in:
SethBurkart123
2023-11-16 14:41:47 +11:00
parent 3d19676dc1
commit 048122fa2c
@@ -87,14 +87,7 @@ export default function BackgroundSelector({ selectedType, setSelectedType, isEd
store.delete(fileId); store.delete(fileId);
setBackgrounds(prev => prev.filter(bg => bg.id !== fileId)); setBackgrounds(prev => prev.filter(bg => bg.id !== fileId));
<img // Check if the background being deleted is currently selected
className="object-cover w-full h-full rounded-xl"
src={bg.url}
alt="swatch"
/>
</div>
))}
{backgrounds.concat(presetBackgrounds as Background[]).filter(bg => bg.type === 'image' && bg.isPreset && !bg.isDownloaded && !downloadedPresetIds.includes(bg.id)).map(bg => (
if (fileId === selectedBackground) { if (fileId === selectedBackground) {
selectNoBackground(); // Disable the current background selectNoBackground(); // Disable the current background
} }
@@ -130,24 +123,16 @@ export default function BackgroundSelector({ selectedType, setSelectedType, isEd
<input type="file" accept='image/*, video/*' onChange={handleFileChange} className="absolute inset-0 w-full h-full opacity-0 cursor-pointer" /> <input type="file" accept='image/*, video/*' onChange={handleFileChange} className="absolute inset-0 w-full h-full opacity-0 cursor-pointer" />
</div> </div>
{backgrounds.filter(bg => bg.type === 'image').map(bg => ( {backgrounds.filter(bg => bg.type === 'image').map(bg => (
<div <div key={bg.id}
key={bg.id}
onClick={() => selectBackground(bg.id)} onClick={() => selectBackground(bg.id)}
className={`relative w-16 h-16 cursor-pointer rounded-xl transition ring dark:ring-white ring-zinc-300 ${isEditMode ? 'animate-shake' : ''} ${selectedBackground === bg.id && selectedType === "background" ? 'dark:ring-2 ring-4' : 'ring-0'}`} className={`relative w-16 h-16 cursor-pointer rounded-xl transition ring dark:ring-white ring-zinc-300 ${isEditMode ? 'animate-shake' : ''} ${selectedBackground === bg.id && selectedType === "background" ? 'dark:ring-2 ring-4' : 'ring-0'}`}>
>
{isEditMode && ( {isEditMode && (
<div <div className="absolute top-0 right-0 z-10 flex w-6 h-6 p-2 text-white translate-x-1/2 -translate-y-1/2 bg-red-600 rounded-full place-items-center"
className="absolute top-0 right-0 z-10 flex w-6 h-6 p-2 text-white translate-x-1/2 -translate-y-1/2 bg-red-600 rounded-full place-items-center" onClick={() => deleteBackground(bg.id)}>
onClick={() => deleteBackground(bg.id)}
>
<div className="w-4 h-0.5 bg-white"></div> <div className="w-4 h-0.5 bg-white"></div>
</div> </div>
)} )}
<img <img className="object-cover w-full h-full rounded-xl" src={bg.url} alt="swatch" />
className="object-cover w-full h-full rounded-xl"
src={bg.url}
alt="swatch"
/>
</div> </div>
))} ))}
{backgrounds.concat(presetBackgrounds as Background[]).filter(bg => bg.type === 'image' && bg.isPreset && !bg.isDownloaded && !downloadedPresetIds.includes(bg.id)).map(bg => ( {backgrounds.concat(presetBackgrounds as Background[]).filter(bg => bg.type === 'image' && bg.isPreset && !bg.isDownloaded && !downloadedPresetIds.includes(bg.id)).map(bg => (