{"version":3,"file":"usePostsQuery-DTvXoRhn.js","sources":["../../../frontend/src/Hooks/usePostsQuery.ts"],"sourcesContent":["import { useQuery } from 'react-query';\n\nimport Api from '../Services/Api';\nimport { Post } from '../Utils/Types/Posts';\nimport useCurrentUser from './useCurrentUser';\n\ninterface PostsQueryResponse {\n posts: Post[];\n paging: any;\n postsCount: number;\n isFetching: boolean;\n isLoading: boolean;\n isSuccess: boolean;\n isError: boolean;\n error: any;\n}\n\nconst usePostsQuery = (\n key: any,\n {\n assigneeId = '',\n authorId = '',\n extraParams,\n iVotedFor,\n limit,\n page = 0,\n parentId = [],\n post,\n search = '',\n sort,\n space,\n status,\n tags = [],\n types,\n useQueryProps,\n visibilities = [],\n }: any,\n): PostsQueryResponse => {\n // Note: Posts return permissions based on the current user\n // so we need to refetch the post when the user changes\n const { currentUser } = useCurrentUser();\n\n const { data, ...params } = useQuery(\n [\n ...(Array.isArray(key) ? key : [key]),\n currentUser?.id,\n assigneeId,\n authorId,\n extraParams,\n iVotedFor,\n page,\n parentId,\n post,\n search,\n sort,\n status,\n tags,\n types,\n visibilities,\n ],\n () =>\n Api.getPosts({\n assigneeId,\n authorId,\n extraParams,\n iVotedFor,\n limit,\n page,\n parentId: post?.id || parentId,\n search,\n sort,\n status,\n tags,\n types,\n visibilities,\n }),\n {\n enabled: !!space.id,\n select: (response: any) => response.data,\n keepPreviousData: true,\n refetchOnWindowFocus: false,\n ...useQueryProps,\n },\n );\n\n const posts: Post[] = (data?.data || []) as Post[];\n\n return {\n posts,\n paging: data?.paging || { total: 0 },\n postsCount: data?.paging?.total || 0,\n ...params,\n };\n};\n\nexport default usePostsQuery;\n"],"names":["usePostsQuery","key","_ref","_data$paging","_ref$assigneeId","assigneeId","_ref$authorId","authorId","extraParams","iVotedFor","limit","_ref$page","page","_ref$parentId","parentId","post","_ref$search","search","sort","space","status","_ref$tags","tags","types","useQueryProps","_ref$visibilities","visibilities","_useCurrentUser","useCurrentUser","currentUser","_useQuery","useQuery","concat","_toConsumableArray","Array","isArray","id","Api","getPosts","_objectSpread","enabled","select","response","data","keepPreviousData","refetchOnWindowFocus","params","_objectWithoutProperties","_excluded","posts","paging","total","postsCount"],"mappings":";q9BAiBA,IAAMA,GAAgB,SACpBC,EAAQC,EAmBe,CAAAC,IAAAA,EAAAC,EAAAF,EAjBrBG,WAAAA,EAAUD,IAAG,OAAA,GAAEA,EAAAE,EAAAJ,EACfK,SAAAA,EAAQD,IAAG,OAAA,GAAEA,EACbE,EAAWN,EAAXM,YACAC,EAASP,EAATO,UACAC,EAAKR,EAALQ,MAAKC,EAAAT,EACLU,KAAAA,EAAID,IAAG,OAAA,EAACA,EAAAE,EAAAX,EACRY,SAAAA,EAAQD,IAAG,OAAA,GAAEA,EACbE,EAAIb,EAAJa,KAAIC,EAAAd,EACJe,OAAAA,EAAMD,IAAG,OAAA,GAAEA,EACXE,EAAIhB,EAAJgB,KACAC,EAAKjB,EAALiB,MACAC,EAAMlB,EAANkB,OAAMC,EAAAnB,EACNoB,KAAAA,EAAID,IAAG,OAAA,CAAA,EAAEA,EACTE,EAAKrB,EAALqB,MACAC,EAAatB,EAAbsB,cAAaC,EAAAvB,EACbwB,aAAAA,EAAYD,IAAG,OAAA,CAAA,EAAEA,EAKnBE,EAAwBC,EAAAA,EAAhBC,EAAWF,EAAXE,YAERC,EAA4BC,EAAQC,CAAAA,EAAAA,OAAAC,EAE5BC,MAAMC,QAAQlC,CAAG,EAAIA,EAAM,CAACA,CAAG,CAAC,EAAA,CACpC4B,GAAW,KAAA,OAAXA,EAAaO,GACb/B,EACAE,EACAC,EACAC,EACAG,EACAE,EACAC,EACAE,EACAC,EACAE,EACAE,EACAC,EACAG,CAAY,CAEd,EAAA,UAAA,CAAA,OACEW,EAAIC,SAAS,CACXjC,WAAAA,EACAE,SAAAA,EACAC,YAAAA,EACAC,UAAAA,EACAC,MAAAA,EACAE,KAAAA,EACAE,UAAUC,GAAAA,YAAAA,EAAMqB,KAAMtB,EACtBG,OAAAA,EACAC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