Skip to content

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

Update the display of sensitive audio display (#4780)

Olga Bulat276b847a857c
diff --git a/frontend/src/components/VAudioThumbnail/VAudioThumbnail.vue b/frontend/src/components/VAudioThumbnail/VAudioThumbnail.vue
index 85dbd97fe..b7709abc7 100644
--- a/frontend/src/components/VAudioThumbnail/VAudioThumbnail.vue
+++ b/frontend/src/components/VAudioThumbnail/VAudioThumbnail.vue
@@ -1,109 +1,86 @@
-<script lang="ts">
+<script setup lang="ts">
+/**
+ * Displays the cover art for the audio in a square aspect ratio.
+ */
import { useI18n } from "#imports"
-import { toRefs, ref, onMounted, defineComponent, PropType } from "vue"
+import { toRefs, ref, onMounted } from "vue"
import { rand, hash } from "~/utils/prng"
import { lerp, dist, bezier, Point } from "~/utils/math"
import type { AudioDetail } from "~/types/media"
import { useSensitiveMedia } from "~/composables/use-sensitive-media"
-/**
- * Displays the cover art for the audio in a square aspect ratio.
- */
-export default defineComponent({
- name: "VAudioThumbnail",
- props: {
- /**
- * the details of the audio whose artwork is to be shown; The properties
- * `thumbnail`, `title` and `creator` are used.
- */
- audio: {
- type: Object as PropType<AudioDetail>,
- required: true,
- },
- },
- setup(props) {
- const { audio } = toRefs(props)
- const { isHidden: shouldBlur } = useSensitiveMedia(audio)
-
- const { t } = useI18n({ useScope: "global" })
- const helpText = shouldBlur.value
- ? t("sensitiveContent.title.audio")
- : t("audioThumbnail.alt", {
- title: props.audio.title,
- creator: props.audio.creator,
- })
-
- /* Switching */
-
- const imgEl = ref<HTMLImageElement | null>(null)
- const isOk = ref(false)
- const handleLoad = () => {
- isOk.value = true
- }
- onMounted(() => {
- isOk.value = Boolean(imgEl.value?.complete && imgEl.value?.naturalWidth)
+const props = defineProps<{
+ /**
+ * The details of the audio whose artwork is to be shown. The properties
+ * `thumbnail`, `title` and `creator` are used.
+ */
+ audio: AudioDetail
+}>()
+
+const { audio } = toRefs(props)
+const { isHidden: shouldBlur } = useSensitiveMedia(audio)
+
+const { t } = useI18n({ useScope: "global" })
+const helpText = shouldBlur.value
+ ? t("sensitiveContent.title.audio")
+ : t("audioThumbnail.alt", {
+ title: props.audio.title,
+ creator: props.audio.creator,
})
- /* Artwork */
-
- const dotCount = 10
- const canvasSize = 768
- const minRadius = 2
- const maxRadius = 27
-
- const random = rand(hash(props.audio.title ?? ""))
- const ctrlPts = Array.from(
- { length: 4 },
- (_, idx) => [random() * canvasSize, (idx / 3) * canvasSize] as Point
- )
-
- const pointCount = dotCount + 1
- const bezierPoints = bezier(ctrlPts, pointCount)
-
- const offset = (i: number) => {
- return i * (canvasSize / (dotCount + 1))
- }
- const radius = (i: number, j: number) => {
- const bezierPoint = bezierPoints[i]
- const distance = dist([0, bezierPoint], [0, offset(j)])
- const maxFeasibleDistance = canvasSize * ((dotCount - 1) / (dotCount + 1))
- return lerp(maxRadius, minRadius, distance / maxFeasibleDistance)
- }
-
- return {
- imgEl,
- isOk,
- handleLoad,
-
- canvasSize,
- dotCount,
- offset,
- radius,
- helpText,
-
- shouldBlur,
- }
- },
+/* Switching */
+
+const imgEl = ref<HTMLImageElement | null>(null)
+const isOk = ref(false)
+const handleLoad = () => {
+ isOk.value = true
+}
+onMounted(() => {
+ isOk.value = Boolean(imgEl.value?.complete && imgEl.value?.naturalWidth)
})
+
+/* Artwork */
+
+const dotCount = 10
+const canvasSize = 768
+const minRadius = 2
+const maxRadius = 27
+
+const random = rand(hash(props.audio.title ?? ""))
+const ctrlPts = Array.from(
+ { length: 4 },
+ (_, idx) => [random() * canvasSize, (idx / 3) * canvasSize] as Point
+)
+
+const pointCount = dotCount + 1
+const bezierPoints = bezier(ctrlPts, pointCount)
+
+const offset = (i: number) => {
+ return i * (canvasSize / (dotCount + 1))
+}
+const radius = (i: number, j: number) => {
+ const bezierPoint = bezierPoints[i]
+ const distance = dist([0, bezierPoint], [0, offset(j)])
+ const maxFeasibleDistance = canvasSize * ((dotCount - 1) / (dotCount + 1))
+ return lerp(maxRadius, minRadius, distance / maxFeasibleDistance)
+}
</script>
<template>
<!-- Should be wrapped by a fixed-width parent -->
- <div
- class="relative h-0 w-full overflow-hidden bg-complementary pt-full"
- :title="helpText"
- >
+ <div class="relative h-0 w-full overflow-hidden pt-full" :title="helpText">
<!-- Programmatic thumbnail -->
<svg
- class="absolute inset-0"
- :class="{ hidden: shouldBlur && isOk }"
+ v-if="!isOk"
+ class="absolute inset-0 bg-complementary"
:viewBox="`0 0 ${canvasSize} ${canvasSize}`"
>
<template v-for="i in dotCount">
<circle
v-for="j in dotCount"
+ v-show="!shouldBlur"
:key="`${i}-${j}`"
class="fill-gray-12"
:cx="offset(j)"
@@ -113,6 +90,12 @@ export default defineComponent({
</template>
</svg>
+ <!-- The element that blurs the programmatic thumbnail -->
+ <div
+ v-show="shouldBlur && !audio.thumbnail"
+ class="bg-blur absolute bg-complementary"
+ />
+
<div v-show="audio.thumbnail && isOk" class="thumbnail absolute inset-0">
<img
ref="imgEl"
@@ -123,5 +106,11 @@ export default defineComponent({
@load="handleLoad"
/>
</div>
+
+ <VIcon
+ v-show="shouldBlur"
+ name="eye-closed"
+ class="absolute left-[calc(50%-0.75rem)] top-[calc(50%-0.75rem)]"
+ />
</div>
</template>