{"version":3,"file":"PodcastPresentationList-nLE6an8K.mjs","names":[],"sources":["../src/components/display/podcasts/PodcastPresentationList.vue","../src/components/display/podcasts/PodcastPresentationList.vue"],"sourcesContent":["<!--\n  Simple component to display a few podcasts\n-->\n<template>\n    <PresentationLayout\n        v-if=\"!loading && !error\"\n        :title=\"title\"\n        :items=\"podcasts\"\n        :route=\"href\"\n        :button-text=\"buttonText\"\n    >\n        <template #item=\"{ item, first }\">\n            <PresentationItem\n                :class=\"!isPhone && first ? 'me-3' : ''\"\n                :name=\"item.title\"\n                :route=\"route(item)\"\n                :image-url=\"item.imageUrl\"\n                :description=\"item.description\"\n                :vertical=\"!isPhone && first\"\n                :tags=\"tags.get(item.podcastId)\"\n                :additional-info=\"additionalInfo.get(item.podcastId)\"\n            >\n                <template #after-image>\n                    <PodcastPlayButton\n                        :podcast=\"item\"\n                        :hide-play=\"false\"\n                        :show-processing=\"false\"\n                    />\n                </template>\n            </PresentationItem>\n        </template>\n    </PresentationLayout>\n    <ClassicLoading\n        v-else\n        :loading-text=\"loading ? $t('Loading emissions ...') : undefined\"\n        :error-text=\"error ? $t(`Error`) : undefined\"\n    />\n</template>\n\n<script setup lang=\"ts\">\nimport classicApi from \"../../../api/classicApi\";\nimport {useErrorHandler} from \"../../composable/useErrorHandler\";\nimport ClassicLoading from \"../../form/ClassicLoading.vue\";\nimport { Emission } from \"@/stores/class/general/emission\";\nimport { onMounted, reactive, Ref, ref, watch } from \"vue\";\nimport { AxiosError } from \"axios\";\nimport {useResizePhone} from \"../../composable/useResizePhone\";\nimport { ListClassicReturn } from \"../../../stores/class/general/listReturn\";\n\nimport PresentationLayout from \"../../layouts/PresentationLayout.vue\"; \nimport { Podcast, SimplifiedPodcast, simplifiedToFull } from \"../../../stores/class/general/podcast\";\n\nimport PresentationItem from \"../../layouts/PresentationItem.vue\"; \nimport PodcastPlayButton from \"./PodcastPlayButton.vue\"; \nimport { RouteLocationRaw } from \"vue-router\";\nimport { podcastApi, PodcastSort } from \"../../../api/podcastApi\";\nimport { usePresentationItem } from \"../../composable/usePresentationItem\";\n\n//Props \nconst props = withDefaults(defineProps<{\n    /**\n     * ID of the organisation\n     */\n    organisationId?: string;\n    /**\n     * Title of the section\n     */\n    title?: string;\n    /**\n     * Link to the \"more\" section\n     */\n    href?: string;\n    /**\n     * Label for the \"more\" button\n     */\n    buttonText?: string;\n    /**\n     * Display podcasts exclusively from these rubriques\n     */\n    rubriquesId?: Array<number>;\n    /**\n     * Mode of retrieval for podcasts\n     */\n    retrievalMode?: 'by-emission'|'any';\n}>(), {\n    retrievalMode: 'by-emission'\n});\n\n//Data \nconst loading = ref(true);\nconst error = ref(false);\nconst podcasts: Ref<Array<Podcast>> = ref([]);\nconst tags = reactive(new Map<number, Array<string>>());\nconst additionalInfo = reactive(new Map<number, Array<string>>());\n  \n//Composables\nconst { isPhone } = useResizePhone();\nconst { handle403 } = useErrorHandler();\nconst { tagsFor, additionalInfoFor } = usePresentationItem();\n\nonMounted(fetchNext);\n\nwatch(podcasts, async () => {\n    podcasts.value.forEach(async (podcast) => {\n        if (!tags.has(podcast.podcastId)) {\n            const [t, i] = await Promise.all([\n                tagsFor(podcast),\n                additionalInfoFor(podcast)\n            ]);\n            tags.set(podcast.podcastId, t);\n            additionalInfo.set(podcast.podcastId, i);\n        }\n    });\n});\n\n//Methods\nasync function fetchNext(): Promise<void> {\n    loading.value = true;\n    try {\n        let func: () => Promise<Array<Podcast>>;\n        if (props.retrievalMode === 'any') {\n            func = fetchPodcasts;\n        } else {\n            func = fetchPodcastsByEmission;\n        }\n        const result = await func();\n\n        // Sort podcasts by pub date so that the most recent one is focused\n        podcasts.value = result.sort((p1, p2) => {\n            return new Date(p2.pubDate).getTime() - new Date(p1.pubDate).getTime();\n        });\n    \n        loading.value = false;\n    } catch (errorWs) {\n        console.error(errorWs);\n        handle403(errorWs as AxiosError);\n        error.value = true;\n    }\n    loading.value = false;\n}\n\nasync function fetchPodcasts(): Promise<Array<Podcast>> {\n    const response = await podcastApi.searchFull({\n        first: 0,\n        size: 5,\n        organisationId: [props.organisationId],\n        sort: PodcastSort.DATE,\n        rubriqueId: props.rubriquesId\n    }, true);\n\n    return response.result;\n}\n\nasync function fetchPodcastsByEmission(): Promise<Array<Podcast>> {\n    // Retrieve latest emissions\n    const emissions = await classicApi.fetchData<ListClassicReturn<Emission>>({\n        api: 0,\n        path: \"emission/search\",\n        parameters: {\n            first: 0,\n            size: 5,\n            organisationId: props.organisationId,\n            sort: \"LAST_PODCAST_DESC\",\n            rubriqueId: props.rubriquesId\n        },\n        specialTreatement: true\n    });\n\n    const promises: Array<Promise<SimplifiedPodcast>> = [];\n\n    for (let i = 0; i < emissions.result.length; i++) {\n        promises.push(podcastApi.search({\n            first: 0,\n            size: 1,\n            organisationId: [props.organisationId],\n            emissionId: [emissions.result[i].emissionId],\n            sort: PodcastSort.DATE,\n            rubriqueId: props.rubriquesId\n        }, true).then(r => r.result[0]));\n    }\n\n    // Retrieve the podcasts for these emissions\n    const data = await Promise.all(promises);\n\n    return data.filter((em: SimplifiedPodcast | null) => null !== em && undefined !== em).map(p => {\n        // Get emission from podcast\n        const emission = emissions.result.find(e => e.emissionId === p.emissionId);\n        // Create full podcast from simplified + emission\n        return simplifiedToFull(p, emission.orga, emission);\n    });\n}\n\nfunction route(podcast: Podcast): RouteLocationRaw {\n    return {\n        name: 'podcast',\n        params: { podcastId: podcast.podcastId }\n    }\n}\n</script>\n","<!--\n  Simple component to display a few podcasts\n-->\n<template>\n    <PresentationLayout\n        v-if=\"!loading && !error\"\n        :title=\"title\"\n        :items=\"podcasts\"\n        :route=\"href\"\n        :button-text=\"buttonText\"\n    >\n        <template #item=\"{ item, first }\">\n            <PresentationItem\n                :class=\"!isPhone && first ? 'me-3' : ''\"\n                :name=\"item.title\"\n                :route=\"route(item)\"\n                :image-url=\"item.imageUrl\"\n                :description=\"item.description\"\n                :vertical=\"!isPhone && first\"\n                :tags=\"tags.get(item.podcastId)\"\n                :additional-info=\"additionalInfo.get(item.podcastId)\"\n            >\n                <template #after-image>\n                    <PodcastPlayButton\n                        :podcast=\"item\"\n                        :hide-play=\"false\"\n                        :show-processing=\"false\"\n                    />\n                </template>\n            </PresentationItem>\n        </template>\n    </PresentationLayout>\n    <ClassicLoading\n        v-else\n        :loading-text=\"loading ? $t('Loading emissions ...') : undefined\"\n        :error-text=\"error ? $t(`Error`) : undefined\"\n    />\n</template>\n\n<script setup lang=\"ts\">\nimport classicApi from \"../../../api/classicApi\";\nimport {useErrorHandler} from \"../../composable/useErrorHandler\";\nimport ClassicLoading from \"../../form/ClassicLoading.vue\";\nimport { Emission } from \"@/stores/class/general/emission\";\nimport { onMounted, reactive, Ref, ref, watch } from \"vue\";\nimport { AxiosError } from \"axios\";\nimport {useResizePhone} from \"../../composable/useResizePhone\";\nimport { ListClassicReturn } from \"../../../stores/class/general/listReturn\";\n\nimport PresentationLayout from \"../../layouts/PresentationLayout.vue\"; \nimport { Podcast, SimplifiedPodcast, simplifiedToFull } from \"../../../stores/class/general/podcast\";\n\nimport PresentationItem from \"../../layouts/PresentationItem.vue\"; \nimport PodcastPlayButton from \"./PodcastPlayButton.vue\"; \nimport { RouteLocationRaw } from \"vue-router\";\nimport { podcastApi, PodcastSort } from \"../../../api/podcastApi\";\nimport { usePresentationItem } from \"../../composable/usePresentationItem\";\n\n//Props \nconst props = withDefaults(defineProps<{\n    /**\n     * ID of the organisation\n     */\n    organisationId?: string;\n    /**\n     * Title of the section\n     */\n    title?: string;\n    /**\n     * Link to the \"more\" section\n     */\n    href?: string;\n    /**\n     * Label for the \"more\" button\n     */\n    buttonText?: string;\n    /**\n     * Display podcasts exclusively from these rubriques\n     */\n    rubriquesId?: Array<number>;\n    /**\n     * Mode of retrieval for podcasts\n     */\n    retrievalMode?: 'by-emission'|'any';\n}>(), {\n    retrievalMode: 'by-emission'\n});\n\n//Data \nconst loading = ref(true);\nconst error = ref(false);\nconst podcasts: Ref<Array<Podcast>> = ref([]);\nconst tags = reactive(new Map<number, Array<string>>());\nconst additionalInfo = reactive(new Map<number, Array<string>>());\n  \n//Composables\nconst { isPhone } = useResizePhone();\nconst { handle403 } = useErrorHandler();\nconst { tagsFor, additionalInfoFor } = usePresentationItem();\n\nonMounted(fetchNext);\n\nwatch(podcasts, async () => {\n    podcasts.value.forEach(async (podcast) => {\n        if (!tags.has(podcast.podcastId)) {\n            const [t, i] = await Promise.all([\n                tagsFor(podcast),\n                additionalInfoFor(podcast)\n            ]);\n            tags.set(podcast.podcastId, t);\n            additionalInfo.set(podcast.podcastId, i);\n        }\n    });\n});\n\n//Methods\nasync function fetchNext(): Promise<void> {\n    loading.value = true;\n    try {\n        let func: () => Promise<Array<Podcast>>;\n        if (props.retrievalMode === 'any') {\n            func = fetchPodcasts;\n        } else {\n            func = fetchPodcastsByEmission;\n        }\n        const result = await func();\n\n        // Sort podcasts by pub date so that the most recent one is focused\n        podcasts.value = result.sort((p1, p2) => {\n            return new Date(p2.pubDate).getTime() - new Date(p1.pubDate).getTime();\n        });\n    \n        loading.value = false;\n    } catch (errorWs) {\n        console.error(errorWs);\n        handle403(errorWs as AxiosError);\n        error.value = true;\n    }\n    loading.value = false;\n}\n\nasync function fetchPodcasts(): Promise<Array<Podcast>> {\n    const response = await podcastApi.searchFull({\n        first: 0,\n        size: 5,\n        organisationId: [props.organisationId],\n        sort: PodcastSort.DATE,\n        rubriqueId: props.rubriquesId\n    }, true);\n\n    return response.result;\n}\n\nasync function fetchPodcastsByEmission(): Promise<Array<Podcast>> {\n    // Retrieve latest emissions\n    const emissions = await classicApi.fetchData<ListClassicReturn<Emission>>({\n        api: 0,\n        path: \"emission/search\",\n        parameters: {\n            first: 0,\n            size: 5,\n            organisationId: props.organisationId,\n            sort: \"LAST_PODCAST_DESC\",\n            rubriqueId: props.rubriquesId\n        },\n        specialTreatement: true\n    });\n\n    const promises: Array<Promise<SimplifiedPodcast>> = [];\n\n    for (let i = 0; i < emissions.result.length; i++) {\n        promises.push(podcastApi.search({\n            first: 0,\n            size: 1,\n            organisationId: [props.organisationId],\n            emissionId: [emissions.result[i].emissionId],\n            sort: PodcastSort.DATE,\n            rubriqueId: props.rubriquesId\n        }, true).then(r => r.result[0]));\n    }\n\n    // Retrieve the podcasts for these emissions\n    const data = await Promise.all(promises);\n\n    return data.filter((em: SimplifiedPodcast | null) => null !== em && undefined !== em).map(p => {\n        // Get emission from podcast\n        const emission = emissions.result.find(e => e.emissionId === p.emissionId);\n        // Create full podcast from simplified + emission\n        return simplifiedToFull(p, emission.orga, emission);\n    });\n}\n\nfunction route(podcast: Podcast): RouteLocationRaw {\n    return {\n        name: 'podcast',\n        params: { podcastId: podcast.podcastId }\n    }\n}\n</script>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA2DA,MAAM,QAAQ;EA8Bd,MAAM,UAAU,IAAI,IAAI;EACxB,MAAM,QAAQ,IAAI,KAAK;EACvB,MAAM,WAAgC,IAAI,CAAC,CAAC;EAC5C,MAAM,OAAO,yBAAS,IAAI,IAA2B,CAAC;EACtD,MAAM,iBAAiB,yBAAS,IAAI,IAA2B,CAAC;EAGhE,MAAM,EAAE,YAAY,eAAe;EACnC,MAAM,EAAE,cAAc,gBAAgB;EACtC,MAAM,EAAE,SAAS,sBAAsB,oBAAoB;EAE3D,UAAU,SAAS;EAEnB,MAAM,UAAU,YAAY;GACxB,SAAS,MAAM,QAAQ,OAAO,YAAY;IACtC,IAAI,CAAC,KAAK,IAAI,QAAQ,SAAS,GAAG;KAC9B,MAAM,CAAC,GAAG,KAAK,MAAM,QAAQ,IAAI,CAC7B,QAAQ,OAAO,GACf,kBAAkB,OAAO,CAC7B,CAAC;KACD,KAAK,IAAI,QAAQ,WAAW,CAAC;KAC7B,eAAe,IAAI,QAAQ,WAAW,CAAC;IAC3C;GACJ,CAAC;EACL,CAAC;EAGD,eAAe,YAA2B;GACtC,QAAQ,QAAQ;GAChB,IAAI;IACA,IAAI;IACJ,IAAI,MAAM,kBAAkB,OACxB,OAAO;SAEP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