Decor: Prevent more crashes

This commit is contained in:
Nuckyz 2024-11-12 15:02:56 -03:00
parent 69dc4fd594
commit 7ef536c6c6
No known key found for this signature in database
GPG key ID: 440BF8296E1C4AD9

View file

@ -99,19 +99,28 @@ export function useUserDecorAvatarDecoration(user?: User): AvatarDecoration | nu
const [decorAvatarDecoration, setDecorAvatarDecoration] = useState<string | null>(user ? useUsersDecorationsStore.getState().getAsset(user.id) ?? null : null); const [decorAvatarDecoration, setDecorAvatarDecoration] = useState<string | null>(user ? useUsersDecorationsStore.getState().getAsset(user.id) ?? null : null);
useEffect(() => { useEffect(() => {
const destructor = useUsersDecorationsStore.subscribe( const destructor = (() => {
state => { try {
if (!user) return; return useUsersDecorationsStore.subscribe(
const newDecorAvatarDecoration = state.getAsset(user.id); state => {
if (!newDecorAvatarDecoration) return; if (!user) return;
if (decorAvatarDecoration !== newDecorAvatarDecoration) setDecorAvatarDecoration(newDecorAvatarDecoration); const newDecorAvatarDecoration = state.getAsset(user.id);
if (!newDecorAvatarDecoration) return;
if (decorAvatarDecoration !== newDecorAvatarDecoration) setDecorAvatarDecoration(newDecorAvatarDecoration);
}
);
} catch {
return () => { };
} }
); })();
try {
if (user) {
const { fetch: fetchUserDecorAvatarDecoration } = useUsersDecorationsStore.getState();
fetchUserDecorAvatarDecoration(user.id);
}
} catch { }
if (user) {
const { fetch: fetchUserDecorAvatarDecoration } = useUsersDecorationsStore.getState();
fetchUserDecorAvatarDecoration(user.id);
}
return destructor; return destructor;
}, []); }, []);