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">
{loadedWallpapers.map((wallpaper) => (
<WallpaperTile
key={wallpaper.slug}
wallpaper={wallpaper}
theme={theme}
isSelected={background === wallpaper.slug}

View File

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