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

98 lines
2.6 KiB
TypeScript

// Metro module 10007 (f10008).
import { useEffect } from "react";
import ApplicationStore from "./ApplicationStore";
import { DelayedCall } from "../../_bundle/Timeout";
import Module12 from "../../_bundle/Module12";
import ApplicationActionCreators from "./ApplicationActionCreators";
import { useStateFromStores } from "../../_bundle/Module589";
function $mk83758($env) {
return () => {
const r4 = $env[0];
if (r4 != null && r4 !== "") {
$env.$parent[5].request(r4);
}
};
}
function $mk83759($env) {
return () => $env[0]._flush();
}
let c6656_0, c6655_5;
let env6656;
let env6655 = {};
class ApplicationFetchManager {
constructor() {
let env17619;
const r3 = env17619 = {};
env17619[0] = this;
this._lastFetchedAttempted = new Map();
this._pending = new Set();
this._flushHandler = new DelayedCall(32, $mk83759(r3));
}
request(a0) {
if (!this._pending.has(a0)) {
const r11 = this._lastFetchedAttempted.get(a0);
if (!(r11 != null && Date.now() - r11 < 60000)) {
this._pending.add(a0);
this._flushHandler.delay(false);
}
}
}
_flush() {
let c17620_0, c17620_2;
const r8 = [];
let c17620_1 = r8;
this._pending.forEach((item) => {
this._lastFetchedAttempted.set(item, Date.now());
c17620_1.push(item);
});
this._pending.clear();
const r14 = [];
c17620_2 = r14;
const r15 = [];
c17620_0 = r15;
r8.forEach((item) => {
if (ApplicationStore.didFetchingApplicationFail(item)) {
c17620_0.push(item);
} else {
c17620_2.push(item);
}
});
if (r14.length > 0) {
Module12.chunk(r14, 20).forEach((item) => {
ApplicationActionCreators.fetchApplications(item, false);
});
}
if (r15.length > 0) {
Module12.chunk(r15, 20).forEach((item) => {
ApplicationActionCreators.fetchApplications(item, true);
});
}
}
}
const r30 = {
__proto__: ApplicationFetchManager.prototype
};
const r31 = env6656 = {};
c6656_0 = r30;
r30._lastFetchedAttempted = new Map();
r30._pending = new Set();
r30._flushHandler = new DelayedCall(32, $mk83759(r31));
c6655_5 = r30;
export function useRequestApplication(a0) {
let env17618;
const r1 = env17618 = {
$parent: env6655
};
env17618[0] = a0;
useEffect($mk83758(r1), [a0]);
}
export function useGetOrFetchApplicationBatched(a0) {
let env17622;
const r3 = env17622 = {
$parent: env6655
};
env17622[0] = a0;
useEffect($mk83758(r3), [a0]);
return useStateFromStores([ApplicationStore], () => a0 != null ? a0 !== "" ? ApplicationStore.getApplication(a0) : null : null, [a0]);
}