{"version":3,"file":"utils-CfDtu69z.js","sources":["../../../../libs/ui-xc/src/hooks/ExposeFolderContext/useFolderFragment.tsx","../../../../libs/ui-xc/src/components/Feed/utils.ts","../../../../libs/ui-xc/src/hooks/useFeed.ts","../../../../apps/xc-eufe/src/utils.ts"],"sourcesContent":["import {useContext, useEffect, useRef} from 'react'\nimport {json} from 'react-router-dom'\n\nimport {setCurrentContactPerson, setCurrentOffice, useExposeFolderQuery} from '@sdox/api'\n\nimport {ExposeFolderContext} from './ExposeFolderContext'\nimport {FolderSkeleton} from '../../components/FolderSkeleton'\n\nimport type {PropsWithChildren} from 'react'\n\nexport const useFolderFragment = () => {\n const context = useContext(ExposeFolderContext)\n if (!context) {\n throw new Error('Context without nearest provider. Check your react tree.')\n }\n return context\n}\n\nexport const ExposeFolderContextProvider = ({children, slug}: PropsWithChildren<{slug: string}>) => {\n const intervalIdRef = useRef | undefined>(undefined)\n const {data, loading, error, client} = useExposeFolderQuery({\n variables: {slug},\n fetchPolicy: 'cache-first',\n })\n\n useEffect(() => {\n if (!data?.exposeFolder || data.exposeFolder.__typename === 'ErrorType') return\n const xcRecords = data.exposeFolder.xcRecords\n intervalIdRef.current = setInterval(() => {\n xcRecords.forEach(record => {\n // we use a cache-first query but we want to reset the check each 10s\n // backend will debounce this anyway\n client.cache.evict({\n id: 'ROOT_QUERY',\n fieldName: 'isFolderItemAvailable',\n args: {slug, exposeFolderRecordId: record.id},\n // Do not broadcast or the query gets reevaluated\n broadcast: false,\n })\n })\n }, 1000 * 10)\n return () => clearInterval(intervalIdRef.current)\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [data?.exposeFolder])\n\n if (error) throw json(error.message, {status: error?.graphQLErrors[0]?.extensions?.code as number})\n if (loading || !data?.exposeFolder) return \n\n if (data.exposeFolder.__typename === 'ErrorType'){\n throw json(data.exposeFolder.message, {status: data.exposeFolder.rawCode})\n }\n\n setCurrentOffice(client, data.exposeFolder.office)\n setCurrentContactPerson(client, data.exposeFolder.contactPerson)\n\n return {children}\n}\n","export const getFeedItemId = (recordId: string) => `xcRecord_${recordId}`\n","import {useSearchParams} from 'react-router-dom'\n\nexport const useFeed = (): [isOpen: boolean, setIsOpen: (open: boolean) => void] => {\n const [searchParams, setSearchParams] = useSearchParams()\n const isOpen = searchParams.get('feed') === 'true'\n\n const setIsOpen = (open: boolean) => {\n setSearchParams(\n (params) => {\n params.set('feed', open ? 'true' : 'false')\n return params\n },\n {preventScrollReset: open},\n )\n }\n\n return [isOpen, setIsOpen]\n}\n","import {useLocation, useNavigate, useParams, useSearchParams} from 'react-router-dom'\n\nimport {useFolderFragment} from '@sdox/ui-xc'\n\nimport type {NavigateOptions} from 'react-router-dom'\n\nexport const useNavigateTo = () => {\n // hack for xcnw\n const {basePath = 'xcnw', seFolderSlug, linkSlug} = useParams()\n const navigate = useNavigate()\n const location = useLocation()\n const [search] = useSearchParams()\n const {xcRecords} = useFolderFragment()\n\n const prefix = `/${basePath}/${seFolderSlug || linkSlug}`\n\n const isCurrentURL = (url: string) => location.pathname === url\n\n const toId = (id: string, options?: NavigateOptions, searchParams?: URLSearchParams) => {\n const newUrl = `${prefix}/${id}/`\n const combinedSearch = new URLSearchParams({\n ...Object.fromEntries(search),\n ...Object.fromEntries(searchParams ?? []),\n }).toString()\n return isCurrentURL(newUrl) ? null : navigate({pathname: newUrl, search: combinedSearch}, options)\n }\n\n const toContent = (options?: NavigateOptions) => {\n navigate({pathname: prefix, search: search.toString()}, options)\n }\n\n const toFirstDocument = (options?: NavigateOptions, search?: URLSearchParams) => {\n const firstRecordId = xcRecords?.[0]?.id\n\n if (firstRecordId) { // navigate to first document if xcRecords exists and is not empty\n toId(firstRecordId, options, search)\n } else { // navigate to NoDocument page when there is no record in the folder\n navigate(`${prefix}/empty`)\n }\n }\n\n return {toId, toContent, toFirstDocument}\n}\n"],"names":["useFolderFragment","context","useContext","ExposeFolderContext","ExposeFolderContextProvider","children","slug","intervalIdRef","useRef","data","loading","error","client","useExposeFolderQuery","useEffect","xcRecords","record","json","_b","_a","FolderSkeleton","setCurrentOffice","setCurrentContactPerson","getFeedItemId","recordId","useFeed","searchParams","setSearchParams","useSearchParams","open","params","useNavigateTo","basePath","seFolderSlug","linkSlug","useParams","navigate","useNavigate","location","useLocation","search","prefix","isCurrentURL","url","toId","id","options","newUrl","combinedSearch","firstRecordId"],"mappings":"iLAUO,MAAMA,EAAoB,IAAM,CAC/B,MAAAC,EAAUC,aAAWC,CAAmB,EAC9C,GAAI,CAACF,EACG,MAAA,IAAI,MAAM,0DAA0D,EAErE,OAAAA,CACT,EAEaG,EAA8B,CAAC,CAAC,SAAAC,EAAU,KAAAC,KAA6C,SAC5F,MAAAC,EAAgBC,SAAmD,MAAS,EAC5E,CAAC,KAAAC,EAAM,QAAAC,EAAS,MAAAC,EAAO,OAAAC,CAAA,EAAUC,EAAqB,CAC1D,UAAW,CAAC,KAAAP,CAAI,EAChB,YAAa,aAAA,CACd,EAsBD,GApBAQ,EAAAA,UAAU,IAAM,CACd,GAAI,EAACL,GAAA,MAAAA,EAAM,eAAgBA,EAAK,aAAa,aAAe,YAAa,OACnE,MAAAM,EAAYN,EAAK,aAAa,UACtB,OAAAF,EAAA,QAAU,YAAY,IAAM,CACxCQ,EAAU,QAAkBC,GAAA,CAG1BJ,EAAO,MAAM,MAAM,CACjB,GAAI,aACJ,UAAW,wBACX,KAAM,CAAC,KAAAN,EAAM,qBAAsBU,EAAO,EAAE,EAE5C,UAAW,EAAA,CACZ,CAAA,CACF,CAAA,EACA,IAAO,EAAE,EACL,IAAM,cAAcT,EAAc,OAAO,CAAA,EAE/C,CAACE,GAAA,YAAAA,EAAM,YAAY,CAAC,EAEnBE,EAAO,MAAMM,EAAKN,EAAM,QAAS,CAAC,QAAQO,GAAAC,EAAAR,GAAA,YAAAA,EAAO,cAAc,KAArB,YAAAQ,EAAyB,aAAzB,YAAAD,EAAqC,KAAe,EAClG,GAAIR,GAAW,EAACD,GAAA,MAAAA,EAAM,cAAc,aAAQW,EAAe,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