Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
<script setup lang="ts">
import { definePageMeta, useAsyncData, useHead } from "#imports"
import { skipToContentTargetId } from "#shared/constants/window"
import { AUDIO } from "#shared/constants/media"
import type { CollectionParams } from "#shared/types/search"
import { useCollection } from "~/composables/use-collection"
import { usePageRobotsRule } from "~/composables/use-page-robots-rule"
import VCollectionResults from "~/components/VSearchResultsGrid/VCollectionResults.vue"
defineOptions({
name: "AudioCollection",
})
definePageMeta({
layout: "content-layout",
middleware: "collection",
})
const {
collectionParams,
isFetching,
media,
creatorUrl,
collectionLabel,
fetchMedia,
loadMore,
pageTitle,
canLoadMore,
} = useCollection({ mediaType: AUDIO })
// Collection params are not nullable in the collections route, this is enforced by the middleware
// Question: should this non-nullability be filtered in the type and enforced in runtime by `useCollection`?
usePageRobotsRule(
`${(collectionParams.value as NonNullable<CollectionParams>).collection}-collection`
)
useHead({
meta: [{ property: "og:title", content: pageTitle.value }],
title: pageTitle.value,
})
/**
* Media is not empty when we navigate back to this page, so we don't need to fetch
* it again to make sure that all the previously fetched media is displayed.
*/
await useAsyncData(
"audio-collection",
async () => (media.value.length ? media.value : await fetchMedia()),
{ lazy: true, server: false }
)
</script>
<template>
<main
:id="skipToContentTargetId"
tabindex="-1"
class="p-6 pt-0 lg:p-10 lg:pt-2"
>
<VCollectionResults
v-if="collectionParams"
search-term=""
:is-fetching="isFetching"
:results="{ type: 'audio', items: media }"
:collection-label="collectionLabel"
:collection-params="collectionParams"
:creator-url="creatorUrl"
:can-load-more="canLoadMore"
@load-more="loadMore"
/>
</main>
</template>