Files
discord-decomp/modules/parent_tools/hooks/useConnectGuardianGate.tsx
T
2026-11-01 12:12:55 +02:00

57 lines
1.9 KiB
TypeScript

// Metro module 16280 (f16281).
import { useState, useRef, useCallback } from "react";
import FamilyCenterStore from "../FamilyCenterStore";
import { useStateFromStoresObject } from "../../../_bundle/Module589";
import { getLinkCodeForCurrentUser } from "../FamilyCenterActionCreators";
import useMountEffect from "../../../hooks/useMountEffect";
export function useConnectGuardianGate() {
let ref;
const stateFromStoresObject = useStateFromStoresObject([FamilyCenterStore], () => ({
linkCode: FamilyCenterStore.getLinkCode(),
expiresAt: FamilyCenterStore.getLinkCodeExpiresAt()
}));
const { linkCode, expiresAt } = stateFromStoresObject;
const [state, setState] = useState(false);
const [state2, setState2] = useState(() => {
const linkCodeExpiresAt = FamilyCenterStore.getLinkCodeExpiresAt();
return FamilyCenterStore.getLinkCode() != null && linkCodeExpiresAt != null && linkCodeExpiresAt > Date.now();
});
ref = useRef(0);
const callback = useCallback(() => {
const current = ref.current + 1;
ref.current = current;
let c28317_0 = current;
setState(false);
getLinkCodeForCurrentUser().then(() => {
if (c28317_0 === ref.current) {
setState(false);
setState2(true);
}
}).catch(() => {
L6: {
if (c28317_0 === ref.current) {
const linkCodeExpiresAt = FamilyCenterStore.getLinkCodeExpiresAt();
if (FamilyCenterStore.getLinkCode() != null && linkCodeExpiresAt != null && linkCodeExpiresAt > Date.now()) {
setState2(true);
break L6;
}
setState(true);
}
}
});
}, []);
useMountEffect(callback);
return state ? {
state: "error"
} : state2 ? linkCode != null && expiresAt != null ? {
state: "gate",
linkCode,
expiresAt,
refresh: callback
} : {
state: "error"
} : {
state: "loading"
};
}