Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
Convert components used on single result pages (#4819)
Olga Bulat49ee33a31929
diff --git a/frontend/src/components/VBackToSearchResultsLink.vue b/frontend/src/components/VBackToSearchResultsLink.vueindex ff8f78bc7..631ae37ae 100644--- a/frontend/src/components/VBackToSearchResultsLink.vue+++ b/frontend/src/components/VBackToSearchResultsLink.vue@@ -1,7 +1,6 @@-<script lang="ts">-import { defineComponent } from "vue"-+<script setup lang="ts">import { useAnalytics } from "~/composables/use-analytics"+import { useSearchStore } from "~/stores/search"import VIcon from "~/components/VIcon/VIcon.vue"@@ -11,40 +10,23 @@ import VButton from "~/components/VButton.vue"* This link takes the user from a single result back to the list of all* results. It only appears if the user navigated from the search results.*/-export default defineComponent({- components: {- VIcon,- VButton,- },- props: {- /**- * The unique ID of the media- */- id: {- type: String,- required: true,- },- href: {- type: String,- required: true,- },- },- setup(props) {- const { sendCustomEvent } = useAnalytics()- const searchStore = useSearchStore()+const props = defineProps<{+ /**+ * The unique ID of the media+ */+ id: string+ href: string+}>()- const handleClick = () => {- sendCustomEvent("BACK_TO_SEARCH", {- id: props.id,- searchType: searchStore.searchType,- })- }+const { sendCustomEvent } = useAnalytics()+const searchStore = useSearchStore()- return {- handleClick,- }- },-})+const handleClick = () => {+ sendCustomEvent("BACK_TO_SEARCH", {+ id: props.id,+ searchType: searchStore.searchType,+ })+}</script><template>diff --git a/frontend/src/components/VContentReport/VDmcaNotice.vue b/frontend/src/components/VContentReport/VDmcaNotice.vueindex 9e4046630..0414f3a2b 100644--- a/frontend/src/components/VContentReport/VDmcaNotice.vue+++ b/frontend/src/components/VContentReport/VDmcaNotice.vue@@ -1,39 +1,19 @@-<script lang="ts">-import { defineComponent } from "vue"-+<script setup lang="ts">import { DMCA_FORM_URL } from "~/constants/content-report"-import { defineEvent } from "~/types/emits"import VLink from "~/components/VLink.vue"-export default defineComponent({- name: "VDmcaNotice",- components: { VLink },- props: {- /**- * the foreign landing URL for the media item- */- foreignLandingUrl: {- type: String,- required: true,- },- /**- * the name of the provider of the media item- */- provider: {- type: String,- required: true,- },- },- emits: {- click: defineEvent(),- },- setup() {- return {- DMCA_FORM_URL,- }- },-})+defineProps<{+ /**+ * the foreign landing URL for the media item+ */+ foreignLandingUrl: string+ /**+ * the name of the provider of the media item+ */+ provider: string+}>()+defineEmits<{ click: [] }>()</script><template>diff --git a/frontend/src/components/VContentReport/VReportDescForm.vue b/frontend/src/components/VContentReport/VReportDescForm.vueindex ab6b1df49..cb09984ac 100644--- a/frontend/src/components/VContentReport/VReportDescForm.vue+++ b/frontend/src/components/VContentReport/VReportDescForm.vue@@ -1,48 +1,32 @@-<script lang="ts">-import { computed, defineComponent, PropType } from "vue"+<script setup lang="ts">+import { computed } from "vue"-import { reasons, OTHER, ReportReason } from "~/constants/content-report"-import { defineEvent } from "~/types/emits"+import { OTHER, type ReportReason } from "~/constants/content-report"-export default defineComponent({- name: "VReportDescForm",- model: {- prop: "content",- event: "update:content",- },- props: {+const props = withDefaults(+ defineProps<{/*** the contents of the textarea*/- content: {- type: String,- default: "",- },+ content?: string/*** the reason selected for reporting the content*/- reason: {- type: String as PropType<ReportReason>,- validator: (val: ReportReason) => reasons.includes(val),- },- },- emits: {- "update:content": defineEvent<[string]>(),- },- setup(props, { emit }) {- const text = computed({- get: () => props.content,- set: (val) => emit("update:content", val),- })+ reason: ReportReason+ }>(),+ {+ content: "",+ }+)- const isRequired = computed(() => props.reason === OTHER)+const emit = defineEmits<{ "update:content": [string] }>()- return {- isRequired,- text,- }- },+const text = computed({+ get: () => props.content,+ set: (val) => emit("update:content", val),})++const isRequired = computed(() => props.reason === OTHER)</script><template>diff --git a/frontend/src/components/VCopyButton.vue b/frontend/src/components/VCopyButton.vueindex 4f040c095..4b7c30117 100644--- a/frontend/src/components/VCopyButton.vue+++ b/frontend/src/components/VCopyButton.vue@@ -1,75 +1,56 @@-<script lang="ts">+<script setup lang="ts">import Clipboard from "clipboard"-import { defineComponent, onBeforeUnmount, onMounted, ref } from "vue"+import { onBeforeUnmount, onMounted, ref } from "vue"import { useHydrating } from "~/composables/use-hydrating"import VButton from "~/components/VButton.vue"-export default defineComponent({- name: "VCopyButton",- components: { VButton },- props: {- el: {- type: String,- required: true,- },- id: {- type: String,- required: true,- },- },- emits: ["copied", "copy-failed"],- setup(props, { emit }) {- const clipboard = ref<Clipboard | null>(null)- const success = ref(false)-- function setFocusOnButton(): void {- const button = document.getElementById(props.id)- if (button) {- button.focus()- }- }-- const onCopySuccess = (e: Clipboard.Event) => {- success.value = true- emit("copied")-- setTimeout(() => {- success.value = false- }, 2000)-- e.clearSelection()-- /* Set the focus back on the button */- setFocusOnButton()- }- const onCopyError = (e: Clipboard.Event) => {- emit("copy-failed")- e.clearSelection()-- /* Restore focus on the button */- setFocusOnButton()- }-- onMounted(() => {- clipboard.value = new Clipboard(`#${props.id}`)- clipboard.value.on("success", onCopySuccess)- clipboard.value.on("error", onCopyError)- })-- onBeforeUnmount(() => clipboard.value?.destroy())-- const { doneHydrating } = useHydrating()-- return {- clipboard,- success,- doneHydrating,- }- },+const props = defineProps<{ el: string; id: string }>()++const emit = defineEmits<{ copied: []; "copy-failed": [] }>()++const clipboard = ref<Clipboard | null>(null)+const success = ref(false)++function setFocusOnButton(): void {+ const button = document.getElementById(props.id)+ if (button) {+ button.focus()+ }+}++const onCopySuccess = (e: Clipboard.Event) => {+ success.value = true+ emit("copied")++ setTimeout(() => {+ success.value = false+ }, 2000)++ e.clearSelection()++ /* Set the focus back on the button */+ setFocusOnButton()+}+const onCopyError = (e: Clipboard.Event) => {+ emit("copy-failed")+ e.clearSelection()++ /* Restore focus on the button */+ setFocusOnButton()+}++onMounted(() => {+ clipboard.value = new Clipboard(`#${props.id}`)+ clipboard.value.on("success", onCopySuccess)+ clipboard.value.on("error", onCopyError)})++onBeforeUnmount(() => clipboard.value?.destroy())++const { doneHydrating } = useHydrating()</script><template>diff --git a/frontend/src/components/VHideButton.vue b/frontend/src/components/VHideButton.vueindex 02389e80c..32906250a 100644--- a/frontend/src/components/VHideButton.vue+++ b/frontend/src/components/VHideButton.vue@@ -1,32 +1,16 @@-<script lang="ts">-import { computed, defineComponent } from "vue"+<script setup lang="ts">+import { computed } from "vue"import { useUiStore } from "~/stores/ui"-import { defineEvent } from "~/types/emits"import VButton from "~/components/VButton.vue"import VIconButton from "~/components/VIconButton/VIconButton.vue"import VIcon from "~/components/VIcon/VIcon.vue"-export default defineComponent({- name: "VHideButton",- components: {- VButton,- VIconButton,- VIcon,- },- emits: {- click: defineEvent(),- },- setup() {- const uiStore = useUiStore()- const isMd = computed(() => uiStore.isBreakpoint("md"))+defineEmits<{ click: [] }>()- return {- isMd,- }- },-})+const uiStore = useUiStore()+const isMd = computed(() => uiStore.isBreakpoint("md"))</script><template>diff --git a/frontend/src/components/VLicense/VLicense.vue b/frontend/src/components/VLicense/VLicense.vueindex 9bafaee27..8a655b098 100644--- a/frontend/src/components/VLicense/VLicense.vue+++ b/frontend/src/components/VLicense/VLicense.vue@@ -1,7 +1,11 @@-<script lang="ts">+<script setup lang="ts">+/**+ * Displays the icons for the license along with a readable display name for the+ * license.+ */import { useI18n } from "#imports"-import { computed, defineComponent, PropType } from "vue"+import { computed } from "vue"import type { License } from "~/constants/license"import { getFullLicenseName, getElements } from "~/utils/license"@@ -9,55 +13,38 @@ import { camelCase } from "~/utils/case"import VIcon from "~/components/VIcon/VIcon.vue"-/**- * Displays the icons for the license along with a readable display name for the- * license.- */-export default defineComponent({- name: "VLicense",- components: { VIcon },- props: {+const props = withDefaults(+ defineProps<{/*** the slug of the license* @values*/- license: {- type: String as PropType<License>,- required: true,- },+ license: License/*** Whether to display icons filled with a white background or leave them transparent.*/- bgFilled: {- type: Boolean,- default: false,- },+ bgFilled?: boolean/*** Either to show the license name next to the icons or hide it.*/- hideName: {- type: Boolean,- default: false,- },- },- setup(props) {- const i18n = useI18n({ useScope: "global" })+ hideName?: boolean+ }>(),+ {+ bgFilled: false,+ hideName: false,+ }+)- const iconNames = computed(() => getElements(props.license))- const licenseName = computed(() => {- const licenseKey =- props.license === "sampling+" ? props.license : camelCase(props.license)- return {- readable: i18n.t(`licenseReadableNames.${licenseKey}`),- full: getFullLicenseName(props.license, "", i18n),- }- })+const i18n = useI18n({ useScope: "global" })- return {- iconNames,- licenseName,- }- },+const iconNames = computed(() => getElements(props.license))+const licenseName = computed(() => {+ const licenseKey =+ props.license === "sampling+" ? props.license : camelCase(props.license)+ return {+ readable: i18n.t(`licenseReadableNames.${licenseKey}`),+ full: getFullLicenseName(props.license, "", i18n),+ }})</script>diff --git a/frontend/src/components/VSingleResultControls.vue b/frontend/src/components/VSingleResultControls.vueindex f7f1b7c49..a204dfdc4 100644--- a/frontend/src/components/VSingleResultControls.vue+++ b/frontend/src/components/VSingleResultControls.vue@@ -1,5 +1,5 @@-<script lang="ts">-import { computed, defineComponent, PropType } from "vue"+<script setup lang="ts">+import { computed } from "vue"import { useSensitiveMedia } from "~/composables/use-sensitive-media"@@ -10,31 +10,12 @@ import { useSearchStore } from "~/stores/search"import VBackToSearchResultsLink from "~/components/VBackToSearchResultsLink.vue"import VHideButton from "~/components/VHideButton.vue"-export default defineComponent({- name: "VSingleResultControls",- components: {- VBackToSearchResultsLink,- VHideButton,- },- props: {- media: {- type: Object as PropType<AudioDetail | ImageDetail>,- required: true,- },- },- setup(props) {- const searchStore = useSearchStore()-- const backToSearchPath = computed(() => searchStore.backToSearchPath)- const { hide, canBeHidden } = useSensitiveMedia(props.media)-- return {- hide,- canBeHidden,- backToSearchPath,- }- },-})+const props = defineProps<{ media: AudioDetail | ImageDetail }>()++const searchStore = useSearchStore()++const backToSearchPath = computed(() => searchStore.backToSearchPath)+const { hide, canBeHidden } = useSensitiveMedia(props.media)</script><template>diff --git a/frontend/src/components/VSketchFabViewer.vue b/frontend/src/components/VSketchFabViewer.vueindex ae1ac024b..e94aa9580 100644--- a/frontend/src/components/VSketchFabViewer.vue+++ b/frontend/src/components/VSketchFabViewer.vue@@ -1,7 +1,7 @@-<script lang="ts">+<script setup lang="ts">import { useI18n, useNuxtApp } from "#imports"-import { defineComponent, ref, onMounted } from "vue"+import { ref, onMounted } from "vue"import { loadScript } from "~/utils/load-script"@@ -20,48 +20,39 @@ declare global {}}-export default defineComponent({- props: {- uid: {- type: String,- required: true,- },- },- emits: ["failure"],- setup(props, { emit }) {- const { t } = useI18n({ useScope: "global" })- const label = t("sketchfabIframeTitle", { sketchfab: "Sketchfab" })- const node = ref<Element | undefined>()- const { $sentry } = useNuxtApp()+const props = defineProps<{ uid: string }>()- const initSketchfab = async () => {- await loadScript(sketchfabUrl)- if (typeof window.Sketchfab === "undefined") {- $sentry.captureMessage("Unable to find window.Sketchfab after loading")- return- }+const emit = defineEmits<{ failure: [] }>()- if (!node.value) {- // This is impossible as far as I can tell as the- // function is only called in `onMounted`- return- }+const { t } = useI18n({ useScope: "global" })+const label = t("sketchfabIframeTitle", { sketchfab: "Sketchfab" })+const node = ref<Element | undefined>()+const { $sentry } = useNuxtApp()- const sf = new window.Sketchfab(node.value)- sf.init(props.uid, {- error: (e: unknown) => {- $sentry.captureException(e)- emit("failure")- },- })- }+const initSketchfab = async () => {+ await loadScript(sketchfabUrl)+ if (typeof window.Sketchfab === "undefined") {+ $sentry.captureMessage("Unable to find window.Sketchfab after loading")+ return+ }- onMounted(() => {- initSketchfab()- })+ if (!node.value) {+ // This is impossible as far as I can tell as the+ // function is only called in `onMounted`+ return+ }++ const sf = new window.Sketchfab(node.value)+ sf.init(props.uid, {+ error: (e: unknown) => {+ $sentry.captureException(e)+ emit("failure")+ },+ })+}- return { node, label }- },+onMounted(() => {+ initSketchfab()})</script>diff --git a/frontend/src/components/VTag/VTag.vue b/frontend/src/components/VTag/VTag.vueindex f6aef7ad7..f2898b6ca 100644--- a/frontend/src/components/VTag/VTag.vue+++ b/frontend/src/components/VTag/VTag.vue@@ -1,18 +1,7 @@-<script lang="ts">-import { defineComponent } from "vue"-+<script setup lang="ts">import VButton from "~/components/VButton.vue"-export default defineComponent({- name: "VTag",- components: { VButton },- props: {- href: {- type: String,- required: true,- },- },-})+defineProps<{ href: string }>()</script><template>