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

67 lines
1.7 KiB
TypeScript

// Metro module 12291 (f12292).
import { useMemo, useState, useCallback } from "react";
function $mk89585($env) {
return () => {
const r2 = $env.$parent;
const r3 = r2[0];
const r7 = r2[1];
const r6 = r3(r7[2]);
const r9 = $env[0];
return {
protocol: r6.getProtocol(r9),
hostname: r3(r7[2]).getHostname(r9)
};
};
}
let env8491 = {};
export function useUrlParts(a0) {
let env19770;
const r1 = env19770 = {
$parent: env8491
};
env19770[0] = a0;
const memo = useMemo($mk89585(r1), [a0]);
const { protocol, hostname } = memo;
const authorityPrefix = a0.substr(protocol.length, 2) === "//" ? "//" : "";
return {
protocol,
authorityPrefix,
hostname,
theRestOfTheUrl: a0.replace(`${protocol}${authorityPrefix}${hostname}`, "")
};
}
export function useModalState({ url, trustUrl, onConfirm, onCancel, onClose }) {
let env19772;
const [state, setShouldTrustUrl] = useState(false);
const r23 = env19772 = {
$parent: env8491
};
env19772[0] = url;
const memo = useMemo($mk89585(r23), [url]);
const { protocol, hostname } = memo;
const authorityPrefix = url.substr(protocol.length, 2) === "//" ? "//" : "";
return {
protocol,
authorityPrefix,
hostname,
theRestOfTheUrl: url.replace(`${protocol}${authorityPrefix}${hostname}`, ""),
shouldTrustUrl: state,
setShouldTrustUrl,
handleConfirm: useCallback(() => {
if (state) {
trustUrl(url);
}
if (onClose != null) {
onClose();
}
onConfirm();
}, [url, state, trustUrl, onConfirm, onClose]),
handleCancel: useCallback(() => {
if (onClose != null) {
onClose();
}
onCancel();
}, [onCancel, onClose])
};
}