Files
discord-decomp/modules/guilds_bar/native/hooks/usePreloadedGuildAsset.tsx
T
2026-11-01 12:12:55 +02:00

48 lines
1.4 KiB
TypeScript

// Metro module 14995 (f14996).
import { useState, useRef, useEffect } from "react";
import useRefValue from "../../../../hooks/useRefValue";
import FastImage from "../../../../components_native/common/FastImage";
export default function usePreloadedGuildAsset(a0, a1, a2) {
const guildId = a0;
const preloading = a1;
let r2 = a2;
const asset = a2;
const [, setState] = useState({});
const ref = useRef({
guildId: a0,
asset: a2,
icon: a1,
preloading: a1
});
useEffect(() => () => {
ref.current.guildId = void 0;
}, []);
const refValue = useRefValue(ref);
if (a0 === refValue.guildId) {
r2 = refValue.asset;
}
useEffect(() => {
L7: {
if (guildId === ref.current.guildId && preloading != null) {
if (!(preloading !== ref.current.icon && preloading !== ref.current.preloading)) {
break L7;
}
ref.current.preloading = preloading;
FastImage.preload(preloading).then(() => {
if (ref.current.guildId === guildId && ref.current.preloading === preloading) {
ref.current.icon = preloading;
ref.current.asset = asset;
setState({});
}
});
} else {
ref.current.guildId = guildId;
ref.current.icon = preloading;
ref.current.preloading = preloading;
ref.current.asset = asset;
}
}
});
return r2;
};