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

58 lines (57 loc) 1.45 kB
import { useRef as u, useEffect as k, useCallback as w } from "react"; import { atom as m, useAtom as d } from "jotai"; import c from "universal-cookie"; const E = { functionalAllowed: !0, analyticsAllowed: !0 }, a = { functionalAllowed: !1, analyticsAllowed: !1 }, l = "org.sagebionetworks.security.cookies.portal.preference", p = () => { const e = new c().get(l, { doNotParse: !0 }); let o = a; try { e != null && (o = JSON.parse(e)); } catch { console.error( `Failed to parse CookiePreference from value, falling back to allow none. value=${e}` ); } return o; }, C = m(a), h = () => { const [t, e] = d( C ), o = u(!1); k(() => { if (!o.current) { o.current = !0; const r = p(); e(r); } }, [e]); const n = w( (r) => { r.functionalAllowed || (localStorage.clear(), sessionStorage.clear()); const i = /* @__PURE__ */ new Date(), s = /* @__PURE__ */ new Date(); s.setFullYear(i.getFullYear() + 1); const f = window.location.hostname.toLowerCase(); new c().set(l, r, { path: "/", expires: s, domain: f.endsWith(".synapse.org") ? "synapse.org" : void 0 }), e(r); }, [e] ); return [t, n]; }; export { l as COOKIES_AGREEMENT_COOKIE_KEY, E as allowAll, a as allowNone, p as getCurrentCookiePreferences, h as useCookiePreferences }; //# sourceMappingURL=useCookiePreferences.js.map