Fix: Image path persists upon clearing image

This commit is contained in:
Moyasee
2025-10-12 22:34:05 +03:00
parent 82c0dc0d97
commit 60ae7d40fa

View File

@@ -67,6 +67,11 @@ export function EditGameModal({
};
const setCustomGameAssets = useCallback((game: LibraryGame | Game) => {
// Check if assets were removed (URLs are null but original paths exist)
const iconRemoved = !game.iconUrl && (game as any).originalIconPath;
const logoRemoved = !game.logoImageUrl && (game as any).originalLogoPath;
const heroRemoved = !game.libraryHeroImageUrl && (game as any).originalHeroPath;
setAssetPaths({
icon: extractLocalPath(game.iconUrl),
logo: extractLocalPath(game.logoImageUrl),
@@ -85,10 +90,22 @@ export function EditGameModal({
(game as any).originalHeroPath ||
extractLocalPath(game.libraryHeroImageUrl),
});
// Set removed assets state based on whether assets were explicitly removed
setRemovedAssets({
icon: iconRemoved,
logo: logoRemoved,
hero: heroRemoved,
});
}, []);
const setNonCustomGameAssets = useCallback(
(game: LibraryGame) => {
// Check if assets were removed (custom URLs are null but original paths exist)
const iconRemoved = !game.customIconUrl && (game as any).customOriginalIconPath;
const logoRemoved = !game.customLogoImageUrl && (game as any).customOriginalLogoPath;
const heroRemoved = !game.customHeroImageUrl && (game as any).customOriginalHeroPath;
setAssetPaths({
icon: extractLocalPath(game.customIconUrl),
logo: extractLocalPath(game.customLogoImageUrl),
@@ -111,6 +128,13 @@ export function EditGameModal({
extractLocalPath(game.customHeroImageUrl),
});
// Set removed assets state based on whether assets were explicitly removed
setRemovedAssets({
icon: iconRemoved,
logo: logoRemoved,
hero: heroRemoved,
});
setDefaultUrls({
icon: shopDetails?.assets?.iconUrl || game.iconUrl || null,
logo: shopDetails?.assets?.logoImageUrl || game.logoImageUrl || null,
@@ -148,8 +172,12 @@ export function EditGameModal({
};
const getAssetDisplayPath = (assetType: AssetType): string => {
// Use original path if available, otherwise fall back to display path
return originalAssetPaths[assetType] || assetDisplayPaths[assetType];
// If asset was removed, don't show any path
if (removedAssets[assetType]) {
return "";
}
// Use display path first, then fall back to original path
return assetDisplayPaths[assetType] || originalAssetPaths[assetType];
};
const setAssetPath = (assetType: AssetType, path: string): void => {
@@ -226,12 +254,13 @@ export function EditGameModal({
setRemovedAssets((prev) => ({ ...prev, [assetType]: true }));
setAssetPath(assetType, "");
setAssetDisplayPath(assetType, "");
setOriginalAssetPaths((prev) => ({ ...prev, [assetType]: "" }));
// Don't clear originalAssetPaths - keep them for reference but don't use them for display
} else {
// For non-custom games, clear custom assets (restore to shop defaults)
// For non-custom games, also mark asset as removed and clear paths (restore to shop defaults)
setRemovedAssets((prev) => ({ ...prev, [assetType]: true }));
setAssetPath(assetType, "");
setAssetDisplayPath(assetType, "");
setOriginalAssetPaths((prev) => ({ ...prev, [assetType]: "" }));
// Don't clear originalAssetPaths - keep them for reference but don't use them for display
}
};
@@ -403,9 +432,9 @@ export function EditGameModal({
// Helper function to prepare non-custom game assets
const prepareNonCustomGameAssets = () => {
return {
customIconUrl: assetPaths.icon ? `local:${assetPaths.icon}` : null,
customLogoImageUrl: assetPaths.logo ? `local:${assetPaths.logo}` : null,
customHeroImageUrl: assetPaths.hero ? `local:${assetPaths.hero}` : null,
customIconUrl: removedAssets.icon ? null : (assetPaths.icon ? `local:${assetPaths.icon}` : null),
customLogoImageUrl: removedAssets.logo ? null : (assetPaths.logo ? `local:${assetPaths.logo}` : null),
customHeroImageUrl: removedAssets.hero ? null : (assetPaths.hero ? `local:${assetPaths.hero}` : null),
};
};
@@ -439,9 +468,9 @@ export function EditGameModal({
customIconUrl,
customLogoImageUrl,
customHeroImageUrl,
customOriginalIconPath: originalAssetPaths.icon || undefined,
customOriginalLogoPath: originalAssetPaths.logo || undefined,
customOriginalHeroPath: originalAssetPaths.hero || undefined,
customOriginalIconPath: removedAssets.icon ? undefined : (originalAssetPaths.icon || undefined),
customOriginalLogoPath: removedAssets.logo ? undefined : (originalAssetPaths.logo || undefined),
customOriginalHeroPath: removedAssets.hero ? undefined : (originalAssetPaths.hero || undefined),
});
};
@@ -484,6 +513,23 @@ export function EditGameModal({
hero: false,
});
// Clear all asset paths to ensure clean state
setAssetPaths({
icon: "",
logo: "",
hero: "",
});
setAssetDisplayPaths({
icon: "",
logo: "",
hero: "",
});
setOriginalAssetPaths({
icon: "",
logo: "",
hero: "",
});
if (isCustomGame(game)) {
setCustomGameAssets(game);
// Clear default URLs for custom games