Files
discord-decomp/modules/applications/useGuildApplication.tsx
T
2026-11-01 12:12:55 +02:00

96 lines
2.7 KiB
TypeScript

// Metro module 16519 (f16520).
import { useState, useCallback, useEffect } from "react";
import ApplicationStore from "./ApplicationStore";
import { useStateFromStores } from "../../_bundle/Module589";
import ApplicationActionCreators from "./ApplicationActionCreators";
import { APIError } from "../../errors/index";
export default function useGuildApplication(a0, a1) {
let callback;
const type = a1;
const stateFromStores = useStateFromStores([ApplicationStore], () => ApplicationStore.getGuildApplication(a0, type));
const [loading, setState] = useState(stateFromStores == null);
const [error, setState2] = useState();
const [state, setState3] = useState(false);
callback = useCallback(async () => {
let c28422_2;
let c28422_3 = 0;
let c31061_0;
L15: {
L14: {
try {
if (stateFromStores != null) {
break L15;
}
if (a0 != null) {
setState3(true);
setState(true);
c28422_3 = 2;
await ApplicationActionCreators.getApplicationsForGuild(a0, {
type,
includeTeam: true
});
c28422_3 = 1;
c28422_3 = 0;
(0, setState)(false);
break L14;
}
break L15;
} catch ($e) {
const r28 = $e;
let r7 = r28;
c28422_2 = r28;
let r29 = c28422_3;
if (r29 !== 0) {
while (true) {
if (r29 === 1) {
try {
const r92 = c28422_2;
c28422_3 = 0;
(0, setState)(false);
throw r92;
} catch (r90) {
r7 = r90;
c28422_2 = r90;
r29 = c28422_3;
if (r29 === 0) {
break;
}
}
} else {
try {
const r71 = c28422_2;
c28422_3 = 1;
c31061_0 = r71;
setState2(new APIError(c31061_0));
c28422_3 = 0;
(0, setState)(false);
break L14;
} catch (r68) {
r7 = r68;
c28422_2 = r68;
r29 = c28422_3;
if (r29 === 0) {
break;
}
}
}
}
}
throw r7;
}
}
return void 0;
}
}, [stateFromStores, a1, a0]);
useEffect(() => {
if (!state) {
callback();
}
}, [state, callback]);
return {
application: stateFromStores,
error,
loading
};
};