Reset figure on avatar editor toggle

This commit is contained in:
Bill 2022-03-16 23:19:01 -04:00
parent 830db963d7
commit 2796abc718

View File

@ -37,7 +37,7 @@ export const AvatarEditorView: FC<{}> = props =>
const [ isWardrobeVisible, setIsWardrobeVisible ] = useState(false); const [ isWardrobeVisible, setIsWardrobeVisible ] = useState(false);
const [ lastFigure, setLastFigure ] = useState<string>(null); const [ lastFigure, setLastFigure ] = useState<string>(null);
const [ lastGender, setLastGender ] = useState<string>(null); const [ lastGender, setLastGender ] = useState<string>(null);
const [ needsReset, setNeedsReset ] = useState(false); const [ needsReset, setNeedsReset ] = useState(true);
const [ isInitalized, setIsInitalized ] = useState(false); const [ isInitalized, setIsInitalized ] = useState(false);
const maxWardrobeSlots = useMemo(() => GetConfiguration<number>('avatar.wardrobe.max.slots', 10), []); const maxWardrobeSlots = useMemo(() => GetConfiguration<number>('avatar.wardrobe.max.slots', 10), []);
@ -180,14 +180,7 @@ export const AvatarEditorView: FC<{}> = props =>
setIsVisible(false); setIsVisible(false);
return; return;
case 'toggle': case 'toggle':
setIsVisible(prevValue => setIsVisible(prevValue => !prevValue);
{
const flag = !prevValue;
if(flag) setNeedsReset(true);
return flag;
});
return; return;
} }
}, []); }, []);
@ -278,6 +271,16 @@ export const AvatarEditorView: FC<{}> = props =>
setNeedsReset(false); setNeedsReset(false);
}, [ isVisible, isInitalized, needsReset, loadAvatarInEditor ]); }, [ isVisible, isInitalized, needsReset, loadAvatarInEditor ]);
useEffect(() =>
{
if(isVisible) return;
return () =>
{
setNeedsReset(true);
}
}, [ isVisible ]);
if(!isVisible || !figureData) return null; if(!isVisible || !figureData) return null;
return ( return (