Decor: Prevent crashing from useUserDecorAvatarDecoration
This commit is contained in:
parent
0cb84cee83
commit
1fe7912ec1
|
@ -95,24 +95,30 @@ export const useUsersDecorationsStore = proxyLazy(() => zustandCreate((set: any,
|
||||||
} as UsersDecorationsState)));
|
} as UsersDecorationsState)));
|
||||||
|
|
||||||
export function useUserDecorAvatarDecoration(user?: User): AvatarDecoration | null | undefined {
|
export function useUserDecorAvatarDecoration(user?: User): AvatarDecoration | null | undefined {
|
||||||
const [decorAvatarDecoration, setDecorAvatarDecoration] = useState<string | null>(user ? useUsersDecorationsStore.getState().getAsset(user.id) ?? null : null);
|
try {
|
||||||
|
const [decorAvatarDecoration, setDecorAvatarDecoration] = useState<string | null>(user ? useUsersDecorationsStore.getState().getAsset(user.id) ?? null : null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const destructor = useUsersDecorationsStore.subscribe(
|
const destructor = useUsersDecorationsStore.subscribe(
|
||||||
state => {
|
state => {
|
||||||
if (!user) return;
|
if (!user) return;
|
||||||
const newDecorAvatarDecoration = state.getAsset(user.id);
|
const newDecorAvatarDecoration = state.getAsset(user.id);
|
||||||
if (!newDecorAvatarDecoration) return;
|
if (!newDecorAvatarDecoration) return;
|
||||||
if (decorAvatarDecoration !== newDecorAvatarDecoration) setDecorAvatarDecoration(newDecorAvatarDecoration);
|
if (decorAvatarDecoration !== newDecorAvatarDecoration) setDecorAvatarDecoration(newDecorAvatarDecoration);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
if (user) {
|
||||||
|
const { fetch: fetchUserDecorAvatarDecoration } = useUsersDecorationsStore.getState();
|
||||||
|
fetchUserDecorAvatarDecoration(user.id);
|
||||||
}
|
}
|
||||||
);
|
return destructor;
|
||||||
|
}, []);
|
||||||
|
|
||||||
if (user) {
|
return decorAvatarDecoration ? { asset: decorAvatarDecoration, skuId: SKU_ID } : null;
|
||||||
const { fetch: fetchUserDecorAvatarDecoration } = useUsersDecorationsStore.getState();
|
} catch (e) {
|
||||||
fetchUserDecorAvatarDecoration(user.id);
|
console.error(e);
|
||||||
}
|
}
|
||||||
return destructor;
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return decorAvatarDecoration ? { asset: decorAvatarDecoration, skuId: SKU_ID } : null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue