Settings / Wallpapers: Fix auto-selecting random wallpaper (#2921)

This commit is contained in:
Alexander Zinchuk 2023-04-06 08:20:28 +02:00
parent ea6996ff83
commit 91b06c6ec9
2 changed files with 6 additions and 1 deletions

View File

@ -154,6 +154,7 @@ const SettingsGeneralBackground: FC<OwnProps & StateProps> = ({
<div className="settings-wallpapers"> <div className="settings-wallpapers">
{loadedWallpapers.map((wallpaper) => ( {loadedWallpapers.map((wallpaper) => (
<WallpaperTile <WallpaperTile
key={wallpaper.slug}
wallpaper={wallpaper} wallpaper={wallpaper}
theme={theme} theme={theme}
isSelected={background === wallpaper.slug} isSelected={background === wallpaper.slug}

View File

@ -44,6 +44,7 @@ const WallpaperTile: FC<OwnProps> = ({
undefined, undefined,
'slow', 'slow',
); );
const isLoadingRef = useRef(false);
const [isLoadAllowed, setIsLoadAllowed] = useState(false); const [isLoadAllowed, setIsLoadAllowed] = useState(false);
const { const {
mediaData: fullMedia, loadProgress, mediaData: fullMedia, loadProgress,
@ -68,8 +69,10 @@ const WallpaperTile: FC<OwnProps> = ({
}, [fullMedia, onClick, slug]); }, [fullMedia, onClick, slug]);
useEffect(() => { useEffect(() => {
if (fullMedia) { // If we've clicked on a wallpaper, select it when full media is loaded
if (fullMedia && isLoadingRef.current) {
handleSelect(); handleSelect();
isLoadingRef.current = false;
} }
}, [fullMedia, handleSelect]); }, [fullMedia, handleSelect]);
@ -77,6 +80,7 @@ const WallpaperTile: FC<OwnProps> = ({
if (fullMedia) { if (fullMedia) {
handleSelect(); handleSelect();
} else { } else {
isLoadingRef.current = true;
setIsLoadAllowed((isAllowed) => !isAllowed); setIsLoadAllowed((isAllowed) => !isAllowed);
} }
}, [fullMedia, handleSelect]); }, [fullMedia, handleSelect]);