phx-react
Version:
PHX REACT
35 lines • 1.41 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = PHXUrlApply;
const direct_link_1 = require("../../../hooks/direct-link");
function PHXUrlApply(key, value, listKeyResetParams, configUrlApply, onlyResetValueUrl) {
const isUseUrlApply = configUrlApply && key && value !== undefined;
const listKeyReset = listKeyResetParams !== null && listKeyResetParams !== void 0 ? listKeyResetParams : [];
if (isUseUrlApply) {
const { router, searchParams, replaceUrl } = configUrlApply;
// Clone current params
const params = new URLSearchParams(searchParams.toString());
const defaultValue = '0';
if (!onlyResetValueUrl) {
params.set(key, value);
}
for (const keyReset of listKeyReset) {
params.set(keyReset, defaultValue);
}
const paramValue = params.toString().toLowerCase();
if (router) {
// Push to URL without reload
if (replaceUrl) {
router.replace(`?${paramValue}`, { scroll: false });
}
else {
router.push(`?${paramValue}`, { scroll: false });
}
}
else {
const directLink = (0, direct_link_1.PHXUseDirectLink)();
directLink(`?${paramValue}`, { replace: replaceUrl });
}
}
}
//# sourceMappingURL=PHXUrlApply.js.map