{"version":3,"file":"8XCteuRt.js","sources":["../../../../components/blog/CategoryPicker.vue","../../../../composables/storyblok/useCategoryPosts.ts"],"sourcesContent":["\n \n \n {{ t(\"title\") }}\n {{ t(\"subtitle\") }}\n\n \n \n \n {{ category }}\n \n\n \n {{ t(\"btn.all-posts\") }}\n \n \n \n \n \n\n\n\n\n\n\n\n{\n \"pt\": {\n \"title\": \"Sabe tudo por tema\",\n \"subtitle\": \"Escolhe um tema\",\n \"btn\": {\n \"all-posts\": \"Todos os Artigos\"\n }\n }\n}\n\n","import { Post } from \"@/types/Post\";\nimport { Status } from \"~/types/CustomFetch\";\nimport { mapResultToPosts } from \"~/utils/storyblok/mapResultToPosts\";\n\nexport const useCategoryPosts = (category: Ref) => {\n const status: Ref = ref(\"idle\");\n const { storyblokVersion } = useRuntimeConfig().public;\n\n const posts: Ref = ref([]);\n const page = ref(1);\n const totalPages = ref(0);\n\n watch(category, () => {\n page.value = 1;\n });\n\n watch(\n [page, category],\n () => {\n status.value = \"pending\";\n\n useStoryblokApi()\n .getStories({\n version: storyblokVersion as \"draft\" | \"published\",\n content_type: \"post\",\n sort_by: \"first_published_at:desc\",\n page: page.value,\n per_page: 12,\n resolve_links: \"url\",\n resolve_relations: [\"post.author\", \"post.specialist\"],\n filter_query: (() => {\n const filter: {\n category?: any;\n postType: any;\n } = {\n postType: {\n in: \"post\",\n },\n };\n\n if (category.value) {\n filter.category = {\n in: category.value,\n };\n }\n\n return filter;\n })(),\n })\n .then((r) => {\n const mappedResult = mapResultToPosts(r);\n\n posts.value = mappedResult.posts;\n totalPages.value = mappedResult.totalPages;\n\n status.value = \"success\";\n })\n .catch(() => {\n status.value = \"error\";\n });\n },\n {\n immediate: true,\n }\n );\n\n return {\n status,\n posts,\n page,\n totalPages,\n };\n};\n"],"names":["t","useI18n","activeCategory","_useModel","__props","useCategoryPosts","category","status","ref","storyblokVersion","useRuntimeConfig","posts","page","totalPages","watch","useStoryblokApi","filter","r","mappedResult","mapResultToPosts"],"mappings":"8cAqCM,KAAA,CAAE,EAAAA,CAAE,EAAIC,EAAQ,EAEhBC,EAAiBC,EAAWC,EAAA,YAEjC,0zBCrCYC,EAAoBC,GAA0B,CACnD,MAAAC,EAAsBC,EAAI,MAAM,EAChC,CAAE,iBAAAC,CAAA,EAAqBC,EAAA,EAAmB,OAE1CC,EAAqBH,EAAI,EAAE,EAC3BI,EAAOJ,EAAI,CAAC,EACZK,EAAaL,EAAI,CAAC,EAExB,OAAAM,EAAMR,EAAU,IAAM,CACpBM,EAAK,MAAQ,CAAA,CACd,EAEDE,EACE,CAACF,EAAMN,CAAQ,EACf,IAAM,CACJC,EAAO,MAAQ,UAEfQ,EAAA,EACG,WAAW,CACV,QAASN,EACT,aAAc,OACd,QAAS,0BACT,KAAMG,EAAK,MACX,SAAU,GACV,cAAe,MACf,kBAAmB,CAAC,cAAe,iBAAiB,EACpD,cAAe,IAAM,CACnB,MAAMI,EAGF,CACF,SAAU,CACR,GAAI,MAAA,CAER,EAEA,OAAIV,EAAS,QACXU,EAAO,SAAW,CAChB,GAAIV,EAAS,KACf,GAGKU,CACN,GAAA,CAAA,CACJ,EACA,KAAMC,GAAM,CACL,MAAAC,EAAeC,EAAiBF,CAAC,EAEvCN,EAAM,MAAQO,EAAa,MAC3BL,EAAW,MAAQK,EAAa,WAEhCX,EAAO,MAAQ,SAAA,CAChB,EACA,MAAM,IAAM,CACXA,EAAO,MAAQ,OAAA,CAChB,CACL,EACA,CACE,UAAW,EAAA,CAEf,EAEO,CACL,OAAAA,EACA,MAAAI,EACA,KAAAC,EACA,WAAAC,CACF,CACF"}
{{ t(\"subtitle\") }}