Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Add download button to the single audio result page (#288)

Olga Bulatb1c941341c7e
diff --git a/src/components/AudioTrack/PlayPause.vue b/src/components/AudioTrack/PlayPause.vue
index 1bd971937..1efbdcc99 100644
--- a/src/components/AudioTrack/PlayPause.vue
+++ b/src/components/AudioTrack/PlayPause.vue
@@ -1,7 +1,7 @@
<template>
<button
type="button"
- class="play-pause flex items-center justify-center bg-dark-charcoal text-white transition-shadow duration-100 ease-linear disabled:opacity-70 focus:outline-none focus-visible:ring focus-visible:ring-offset-2 focus-visible:ring-pink"
+ class="play-pause flex-shrink-0 flex items-center justify-center bg-dark-charcoal text-white transition-shadow duration-100 ease-linear disabled:opacity-70 focus:outline-none focus-visible:ring focus-visible:ring-offset-2 focus-visible:ring-pink"
@click="handleClick"
>
<span class="sr-only">{{ label }}</span>
diff --git a/src/components/AudioTrack/layouts/Full.vue b/src/components/AudioTrack/layouts/Full.vue
index f739ae444..f5b8171c9 100644
--- a/src/components/AudioTrack/layouts/Full.vue
+++ b/src/components/AudioTrack/layouts/Full.vue
@@ -2,8 +2,8 @@
<div class="full-track w-full">
<slot name="controller" />
- <div class="flex flex-row space-between mx-16 my-6">
- <div class="left-content flex flex-row items-center gap-6">
+ <div class="flex flex-row justify-between items-top mx-16 my-6">
+ <div class="left-content flex flex-row items-top gap-6">
<slot name="play-pause" />
<div class="audio-info">
@@ -28,8 +28,7 @@
</div>
</div>
- <!-- TODO: Download dropdown -->
- <div class="right-content bg-pink h-12 w-30 rounded-sm ml-auto" />
+ <DownloadButton :formats="getFormats(audio)" />
</div>
</div>
</template>
@@ -52,9 +51,47 @@ export default {
}
return '--:--'
}
-
+ /**
+ * Returns specific display name for file format if there is a mapping for
+ * provider's format display names (like Jamendo's `mp32` -> `MP3 V0`).
+ * Otherwise, returns UpperCase format or ''
+ * @param {string} provider
+ * @param {string} [format]
+ */
+ const displayFormat = (provider, format) => {
+ const filetypeMappings = {
+ jamendo: { mp31: 'MP3 96kbs', mp32: 'MP3 V0' },
+ }
+ if (filetypeMappings[provider] && filetypeMappings[provider][format]) {
+ return filetypeMappings[provider][format]
+ }
+ return format ? format.toUpperCase() : ''
+ }
+ /**
+ * Creates a list of { extension_name, download_url } objects
+ * for DownloadButton
+ * @param {AudioDetail} audio
+ */
+ const getFormats = (audio) => {
+ let formats = [
+ {
+ extension_name: displayFormat(audio.provider, audio.filetype),
+ download_url: audio.url,
+ },
+ ]
+ if (audio.alt_files) {
+ formats = formats.concat(
+ audio.alt_files.map((altFile) => ({
+ extension_name: displayFormat(audio.provider, altFile.filetype),
+ download_url: altFile.url,
+ }))
+ )
+ }
+ return formats
+ }
return {
timeFmt,
+ getFormats,
}
},
}
diff --git a/src/components/DownloadButton.vue b/src/components/DownloadButton.vue
index e803d01cb..68e6d213a 100644
--- a/src/components/DownloadButton.vue
+++ b/src/components/DownloadButton.vue
@@ -2,6 +2,7 @@
<DropdownButton
v-if="filesizes"
:dropdown-aria-label="$t('download-button.aria.dropdown-label')"
+ :is-single-item="formats.length === 1"
>
<template #default="{ buttonProps }">
<a
diff --git a/src/components/DropdownButton.vue b/src/components/DropdownButton.vue
index 829ec8706..7581b1615 100644
--- a/src/components/DropdownButton.vue
+++ b/src/components/DropdownButton.vue
@@ -9,9 +9,10 @@
}"
/>
<button
+ v-if="!isSingleItem"
ref="dropdownButton"
type="button"
- class="dropdown-button ml-1 rounded-r-sm rounded-l-none"
+ class="dropdown-button ml-1 rounded-r-sm rounded-l-none w-14"
:class="{ 'dropdown-button-active': isOpen }"
aria-haspopup="menu"
:aria-label="safeDropdownAriaLabel"
@@ -55,6 +56,10 @@ const DropdownButton = {
type: String,
required: false,
},
+ isSingleItem: {
+ type: Boolean,
+ required: false,
+ },
},
data() {
return {
@@ -146,7 +151,7 @@ export default DropdownButton
<style lang="css" scoped>
.dropdown-button {
- @apply flex items-center justify-center bg-pink text-white font-bold p-2 px-4 transition-shadow duration-100 ease-linear disabled:opacity-70 focus:outline-none focus-visible:ring focus-visible:ring-offset-2 focus-visible:ring-pink hover:bg-dark-pink no-underline appearance-none;
+ @apply flex items-center justify-center bg-pink text-white font-bold p-4 leading-6 transition-shadow duration-100 ease-linear disabled:opacity-70 focus:outline-none focus-visible:ring focus-visible:ring-offset-2 focus-visible:ring-pink hover:bg-dark-pink no-underline appearance-none;
}
.dropdown-button-active {
diff --git a/src/data/sample-audio-responses.json b/src/data/sample-audio-responses.json
index faa4d4815..0b3d7c5e8 100644
--- a/src/data/sample-audio-responses.json
+++ b/src/data/sample-audio-responses.json
@@ -30,6 +30,7 @@
"name": "vocal"
}
],
+ "filetype": "mp3",
"fields_matched": ["tags.name"],
"genres": ["classical", "gospel"],
"detail_url": "http://localhost:8000/v1/audio/8071128a-bebc-4c24-823d-6e26a2e6dfe2",
@@ -58,6 +59,7 @@
"name": "vocal"
}
],
+ "filetype": "mp3",
"fields_matched": ["tags.name"],
"genres": ["metal"],
"detail_url": "http://localhost:8000/v1/audio/73e00493-9189-42ed-955b-4f9d26d0d9f4",
@@ -220,7 +222,7 @@
"provider": "jamendo",
"source": "jamendo",
"category": "music",
- "filetype": "mp3",
+ "filetype": "mp32",
"sample_rate": "1.67",
"description": "",
"tags": [
@@ -250,6 +252,16 @@
"name": "Distance & Temps",
"url": "https://www.jamendo.com/album/1290/distance-and-temps"
},
+ "alt_files": [
+ {
+ "filetype": "flac",
+ "url": "https://mp3d.jamendo.com/download/track/8561/flac"
+ },
+ {
+ "filetype": "mp31",
+ "url": "https://mp3d.jamendo.com/download/track/8561/mp31"
+ }
+ ],
"duration": 248000,
"detail_url": "http://localhost:8000/v1/audio/242c1a4c-0623-436c-a600-7847412d28b6",
"related_url": "http://localhost:8000/v1/audio/242c1a4c-0623-436c-a600-7847412d28b6/recommendations"
diff --git a/test/unit/specs/components/AudioTrack/audio-track.spec.js b/test/unit/specs/components/AudioTrack/audio-track.spec.js
index e66906b83..d55174500 100644
--- a/test/unit/specs/components/AudioTrack/audio-track.spec.js
+++ b/test/unit/specs/components/AudioTrack/audio-track.spec.js
@@ -42,6 +42,7 @@ describe('AudioTrack', () => {
license_url: 'https://creativecommons.org/licenses/by-nc-sa/2.5/',
provider: 'jamendo',
source: 'jamendo',
+ filetype: 'mp32',
tags: [
{
name: 'vocal',