UNPKG

synapse-react-client

Version:

[![npm version](https://badge.fury.io/js/synapse-react-client.svg)](https://badge.fury.io/js/synapse-react-client) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettie

51 lines (50 loc) 1.92 kB
import { jsx as n } from "react/jsx-runtime"; import { useSearchParams as f } from "react-router"; import { SEARCH_PAGE_QUERY_PARAM as a } from "../../utils/SynapseConstants.js"; import { SynapseSearchPageResults as y } from "./SynapseSearchPageResults.js"; import S from "./SynapseSearchPageRouter.js"; import { DEFAULT_SEARCH_QUERY as g } from "../../utils/searchDefaults.js"; import { useMemo as h, useEffect as d } from "react"; import { parseSynId as l } from "../../utils/functions/RegularExpressions.js"; import "@sage-bionetworks/synapse-types"; import { getEndpoint as P, BackendDestinationEnum as E } from "../../utils/functions/getEndpoint.js"; import "../../synapse-client/SynapseClient.js"; import "@sage-bionetworks/synapse-client/generated/models/ErrorResponseCode"; import "@sage-bionetworks/synapse-client/generated/models/TwoFactorAuthErrorResponse"; import "@sage-bionetworks/synapse-client/util/SynapseClientError"; import "@sage-bionetworks/synapse-client/util/synapseClientFetch"; import "lodash-es"; function R() { const [t, c] = f(), s = t.get(a) || ""; let m = {}; try { m = s ? JSON.parse(s) : {}; } catch (r) { console.error("Error parsing search query from URL:", r); } const i = { ...g, ...m }, p = i?.queryTerm?.[0] || "", e = h(() => l(p), [p]); d(() => { if (e) { const r = e.targetVersionNumber ? `${e.targetId}.${e.targetVersionNumber}` : e.targetId; window.location.assign( `${P( E.PORTAL_ENDPOINT )}Synapse:${r}` ); } }, [e]); const u = (r) => { c((o) => (r && r.queryTerm && r.queryTerm.length > 0 ? o.set(a, JSON.stringify(r)) : o.delete(a), o)); }; return e ? null : /* @__PURE__ */ n(y, { query: i, setQuery: u }); } function M(t) { return /* @__PURE__ */ n(S, { ...t, children: /* @__PURE__ */ n(R, {}) }); } export { M as default }; //# sourceMappingURL=SynapseSearchPage.js.map