Skip to content

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

Convert components used for displaying search results to `script setup` (#4799)

Olga Bulatc8f89fb57d0d
diff --git a/frontend/src/components/VCheckbox/VCheckbox.vue b/frontend/src/components/VCheckbox/VCheckbox.vue
index 8dc34f8b1..99b53c654 100644
--- a/frontend/src/components/VCheckbox/VCheckbox.vue
+++ b/frontend/src/components/VCheckbox/VCheckbox.vue
@@ -1,7 +1,10 @@
-<script lang="ts">
-import { computed, defineComponent, ref, watch } from "vue"
-
-import { defineEvent } from "~/types/emits"
+<script setup lang="ts">
+/**
+ * A checkbox input component that allows selection of multiple options from a list .
+ *
+ * Unlike the native checkbox, this component only has two states: checked / not checked.
+ */
+import { computed, ref, watch } from "vue"
import VIcon from "~/components/VIcon/VIcon.vue"
@@ -12,35 +15,20 @@ export type CheckboxAttrs = {
checked?: boolean
}
-/**
- * A checkbox input component that allows selection of multiple options from a list .
- *
- * Unlike the native checkbox, this component only has two states: checked / not checked.
- */
-export default defineComponent({
- name: "VCheckbox",
- components: {
- VIcon,
- },
- props: {
+const props = withDefaults(
+ defineProps<{
/**
* Checkbox `id` is used for the input id property, connecting the label to
* the checkbox. id is also used in the `change` event payload as the `name`
* and `value` parameters if they are not set.
*/
- id: {
- type: String,
- required: true,
- },
+ id: string
/**
* Whether the checkbox is checked or not. No indeterminate state is allowed.
*
* @default false
*/
- checked: {
- type: Boolean,
- default: false,
- },
+ checked?: boolean
/**
* Usually this is the category that this checkbox belongs to, e.g. 'license' for a
* 'by-nc-nd' checkbox, or 'licenseType' for 'commercial' checkbox.
@@ -52,79 +40,62 @@ export default defineComponent({
*
* If not set, the value of `id` prop is used instead.
*/
- name: {
- type: String,
- required: false,
- },
+ name?: string
/**
* The value parameter in `name=value` pair sent in the POST request body, here
* emitted in the event's payload. Usually the code as 'by-nc-nd'.
*
* If not set, the value of `id` prop is used.
*/
- value: {
- type: String,
- required: false,
- },
+ value?: string
/**
* Sets disabled property of the input and changes label opacity if set to true.
*/
- disabled: {
- type: Boolean,
- default: undefined,
- },
+ disabled?: boolean
/**
* whether to make the checkbox appear like a switch
*/
- isSwitch: {
- type: Boolean,
- default: false,
- },
- },
- emits: {
- change: defineEvent<[Omit<CheckboxAttrs, "disabled">]>(),
- },
- setup(props, { emit }) {
- const localCheckedState = ref(props.checked || false)
- const labelClasses = computed(() =>
- props.disabled ? "text-disabled" : "text-default"
- )
- const inputAttrs = computed<CheckboxAttrs>(() => {
- const attrs: CheckboxAttrs = {
- name: props.name || props.id,
- value: props.value || props.id,
- }
- if (localCheckedState.value) {
- attrs.checked = true
- }
- return attrs
- })
+ isSwitch?: boolean
+ }>(),
+ {
+ checked: false,
+ isSwitch: false,
+ }
+)
- watch(
- () => props.checked,
- (checked) => {
- if (checked !== localCheckedState.value) {
- localCheckedState.value = checked
- }
- }
- )
+const emit = defineEmits<{ change: [Omit<CheckboxAttrs, "disabled">] }>()
+const localCheckedState = ref(props.checked || false)
+const labelClasses = computed(() =>
+ props.disabled ? "text-disabled" : "text-default"
+)
+const inputAttrs = computed<CheckboxAttrs>(() => {
+ const attrs: CheckboxAttrs = {
+ name: props.name || props.id,
+ value: props.value || props.id,
+ }
+ if (localCheckedState.value) {
+ attrs.checked = true
+ }
+ return attrs
+})
- const onChange = () => {
- localCheckedState.value = !localCheckedState.value
- emit("change", {
- name: inputAttrs.value.name,
- value: inputAttrs.value.value,
- checked: localCheckedState.value,
- })
+watch(
+ () => props.checked,
+ (checked) => {
+ if (checked !== localCheckedState.value) {
+ localCheckedState.value = checked
}
- return {
- localCheckedState,
- labelClasses,
- inputAttrs,
- onChange,
- }
- },
-})
+ }
+)
+
+const onChange = () => {
+ localCheckedState.value = !localCheckedState.value
+ emit("change", {
+ name: inputAttrs.value.name,
+ value: inputAttrs.value.value,
+ checked: localCheckedState.value,
+ })
+}
</script>
<template>
diff --git a/frontend/src/components/VFilters/VSearchGridFilter.vue b/frontend/src/components/VFilters/VSearchGridFilter.vue
index 571ca9f6e..756b7fefd 100644
--- a/frontend/src/components/VFilters/VSearchGridFilter.vue
+++ b/frontend/src/components/VFilters/VSearchGridFilter.vue
@@ -1,90 +1,74 @@
-<script lang="ts">
-import { useI18n } from "#imports"
+<script setup lang="ts">
+import { useI18n, useNuxtApp } from "#imports"
-import { computed, defineComponent } from "vue"
+import { computed } from "vue"
import { storeToRefs } from "pinia"
import { useSearchStore } from "~/stores/search"
import type { FilterCategory } from "~/constants/filters"
-import { useAnalytics } from "~/composables/use-analytics"
import VFilterChecklist from "~/components/VFilters/VFilterChecklist.vue"
import VButton from "~/components/VButton.vue"
-export default defineComponent({
- name: "VSearchGridFilter",
- components: {
- VButton,
- VFilterChecklist,
- },
- props: {
+withDefaults(
+ defineProps<{
/**
* Whether to show the header with the title and the clear button.
*/
- showFilterHeader: {
- type: Boolean,
- default: true,
- },
+ showFilterHeader?: boolean
/**
* When the filters are in the sidebar, we change the keyboard tabbing order:
* the focus moves from the Filters button to the filter,
* and from the last tabbable element to the main content on Tab,
* and from the filters to the filters button on Shift Tab.
*/
- changeTabOrder: {
- type: Boolean,
- default: true,
- },
- },
- setup() {
- const searchStore = useSearchStore()
+ changeTabOrder?: boolean
+ }>(),
+ {
+ showFilterHeader: true,
+ changeTabOrder: true,
+ }
+)
- const { t } = useI18n({ useScope: "global" })
+const searchStore = useSearchStore()
- const { sendCustomEvent } = useAnalytics()
+const { t } = useI18n({ useScope: "global" })
- const {
- isAnyFilterApplied,
- searchTerm,
- searchType,
- searchFilters: filters,
- } = storeToRefs(searchStore)
+const { $sendCustomEvent } = useNuxtApp()
- const filterTypes = computed(
- () => Object.keys(filters.value) as FilterCategory[]
- )
- const filterTypeTitle = (filterType: FilterCategory) => {
- return t(`filters.${filterType}.title`)
- }
+const {
+ isAnyFilterApplied,
+ searchTerm,
+ searchType,
+ searchFilters: filters,
+} = storeToRefs(searchStore)
- const toggleFilter = ({
- filterType,
- code,
- }: {
- filterType: FilterCategory
- code: string
- }) => {
- const checked = searchStore.toggleFilter({ filterType, code })
- sendCustomEvent("APPLY_FILTER", {
- category: filterType,
- key: code,
- checked,
- searchType: searchType.value,
- query: searchTerm.value,
- })
- }
+const filterTypes = computed(
+ () => Object.keys(filters.value) as FilterCategory[]
+)
+const filterTypeTitle = (filterType: FilterCategory) => {
+ return t(`filters.${filterType}.title`)
+}
- return {
- isAnyFilterApplied,
- filters,
- filterTypes,
- filterTypeTitle,
- clearFilters: searchStore.clearFilters,
- toggleFilter,
- }
- },
-})
+const toggleFilter = ({
+ filterType,
+ code,
+}: {
+ filterType: FilterCategory
+ code: string
+}) => {
+ const checked = searchStore.toggleFilter({ filterType, code })
+ $sendCustomEvent("APPLY_FILTER", {
+ category: filterType,
+ key: code,
+ checked,
+ searchType: searchType.value,
+ query: searchTerm.value,
+ })
+}
+
+const clearFilters = () => searchStore.clearFilters()
</script>
<template>
diff --git a/frontend/src/components/VHomeGallery/VGalleryImage.vue b/frontend/src/components/VHomeGallery/VGalleryImage.vue
new file mode 100644
index 000000000..4cb425c8c
--- /dev/null
+++ b/frontend/src/components/VHomeGallery/VGalleryImage.vue
@@ -0,0 +1,42 @@
+<script setup lang="ts">
+import { useNuxtApp } from "#imports"
+
+import type { GallerySet } from "~/types/home-gallery"
+
+const props = defineProps<{
+ idx: number
+ dimens: number
+ set: GallerySet
+ image: {
+ id: string
+ src: string
+ title: string
+ url: string
+ }
+}>()
+
+const { $sendCustomEvent } = useNuxtApp()
+const handleClick = (id: string) => {
+ $sendCustomEvent("CLICK_HOME_GALLERY_IMAGE", {
+ set: props.set,
+ id,
+ })
+}
+</script>
+
+<template>
+ <VLink
+ class="home-cell rounded-full p-1 focus-visible:bg-default"
+ :style="{ '--delay': `${idx * 0.05}s` }"
+ :href="image.url"
+ @click="handleClick(image.id)"
+ >
+ <img
+ :height="dimens"
+ :width="dimens"
+ :src="image.src"
+ :alt="image.title"
+ :title="image.title"
+ />
+ </VLink>
+</template>
diff --git a/frontend/src/components/VHomeGallery/VHomeGallery.vue b/frontend/src/components/VHomeGallery/VHomeGallery.vue
index 9fb8e5743..a678789b4 100644
--- a/frontend/src/components/VHomeGallery/VHomeGallery.vue
+++ b/frontend/src/components/VHomeGallery/VHomeGallery.vue
@@ -1,106 +1,73 @@
-<script lang="ts">
-import { useLocalePath, useRouter } from "#imports"
-
-import { computed, defineComponent, PropType, ref } from "vue"
-
-import { useReducedMotion } from "~/composables/use-reduced-motion"
-import { useAnalytics } from "~/composables/use-analytics"
-import useResizeObserver from "~/composables/use-resize-observer"
-
-import VLink from "~/components/VLink.vue"
-
-import imageInfo from "~/assets/homepage_images.json"
-
-export const GALLERY_SETS = [
- "universe",
- "pottery",
- "olympics",
- "random",
-] as const
-export type GallerySet = (typeof GALLERY_SETS)[number]
-
+<script setup lang="ts">
/**
* Displays a grid of images for the homepage, with each image linking to its
* single result page. The number of columns automatically adjusts to the width
* of the container upto a max of 5.
*/
-export default defineComponent({
- name: "VHomeGallery",
- components: { VLink },
- props: {
- /**
- * the set of images to use for the gallery grid
- */
- set: {
- type: String as PropType<GallerySet>,
- required: false,
- default: "random",
- validator: (val: GallerySet) => GALLERY_SETS.includes(val),
- },
- },
- setup(props) {
- const localePath = useLocalePath()
- const router = useRouter()
- const prefersReducedMotion = useReducedMotion()
-
- const dimens = 152 // px
- const space = 24 // px; 32px space - 4px padding on both sides
-
- const rowCount = 3
- const columnCount = computed(() =>
- Math.min(
- 5, // Grid cannot exceed 5 columns as we only have 15 images.
- Math.floor((gridDimens.value.width + space) / (dimens + space))
- )
- )
-
- const el = ref<HTMLElement | null>(null) // template ref
- const { dimens: gridDimens } = useResizeObserver(el)
+import { useLocalePath, useRouter } from "#imports"
- const imageSet = computed(() =>
- props.set === "random"
- ? imageInfo.sets[Math.floor(Math.random() * imageInfo.sets.length)]
- : (imageInfo.sets.find((item) => (item.key = props.set)) ??
- imageInfo.sets[0])
- )
- const imageList = computed(() => {
- return imageSet.value.images.map((image, idx) => ({
- ...image,
- src: `/homepage_images/${imageSet.value.key}/${idx + 1}.png`,
- url: router.resolve(
- localePath({
- name: "image-id",
- params: { id: image.id },
- })
- ).href,
- }))
- })
- const imageCount = computed(() => columnCount.value * rowCount)
+import { computed, ref } from "vue"
- const { sendCustomEvent } = useAnalytics()
- const handleClick = (id: string) => {
- sendCustomEvent("CLICK_HOME_GALLERY_IMAGE", {
- set: imageSet.value.key,
- id,
- })
- }
+import { useReducedMotion } from "~/composables/use-reduced-motion"
+import useResizeObserver from "~/composables/use-resize-observer"
- return {
- el,
+import type { GallerySet } from "~/types/home-gallery"
- dimens,
- space,
+import VGalleryImage from "~/components/VHomeGallery/VGalleryImage.vue"
- imageCount,
- columnCount,
- imageList,
+import untypedImageInfo from "~/assets/homepage_images.json"
- prefersReducedMotion,
+const props = withDefaults(defineProps<{ set?: GallerySet }>(), {
+ set: "random",
+})
- handleClick,
- }
- },
+type HomepageImage = { id: string; title: string; src: string }
+type ImageSet = {
+ key: GallerySet
+ term: string
+ images: HomepageImage[]
+}
+const imageInfo = untypedImageInfo as unknown as {
+ sets: ImageSet[]
+}
+
+const localePath = useLocalePath()
+const router = useRouter()
+const prefersReducedMotion = useReducedMotion()
+
+const dimens = 152 // px
+const space = 24 // px; 32px space - 4px padding on both sides
+
+const rowCount = 3
+const columnCount = computed(() =>
+ Math.min(
+ 5, // Grid cannot exceed 5 columns as we only have 15 images.
+ Math.floor((gridDimens.value.width + space) / (dimens + space))
+ )
+)
+
+const el = ref<HTMLElement | null>(null) // template ref
+const { dimens: gridDimens } = useResizeObserver(el)
+
+const imageSet = computed(() =>
+ props.set === "random"
+ ? imageInfo.sets[Math.floor(Math.random() * imageInfo.sets.length)]
+ : (imageInfo.sets.find((item) => (item.key = props.set)) ??
+ imageInfo.sets[0])
+)
+const imageList = computed(() => {
+ return imageSet.value.images.map((image, idx) => ({
+ ...image,
+ src: `/homepage_images/${imageSet.value.key}/${idx + 1}.png`,
+ url: router.resolve(
+ localePath({
+ name: "image-id",
+ params: { id: image.id },
+ })
+ ).href,
+ }))
})
+const imageCount = computed(() => columnCount.value * rowCount)
</script>
<template>
@@ -118,8 +85,19 @@ export default defineComponent({
}"
>
<ClientOnly>
+ <template v-if="prefersReducedMotion">
+ <VGalleryImage
+ v-for="(image, idx) in imageList"
+ :key="image.url"
+ :image="image"
+ :set="imageSet.key"
+ :idx="idx"
+ :dimens="dimens"
+ />
+ </template>
<Transition
v-for="(image, idx) in imageList"
+ v-else
:key="idx"
enter-active-class="transition-opacity delay-[var(--delay)] duration-500"
leave-active-class="transition-opacity delay-[var(--delay)] duration-500"
@@ -128,21 +106,13 @@ export default defineComponent({
mode="out-in"
appear
>
- <VLink
- class="home-cell rounded-full p-1 focus-visible:bg-default"
+ <VGalleryImage
+ :idx="idx"
+ :dimens="dimens"
+ :image="image"
+ :set="imageSet.key"
:class="idx >= imageCount ? 'hidden' : 'block'"
- :style="{ '--delay': `${idx * 0.05}s` }"
- :href="image.url"
- @click="handleClick(image.id)"
- >
- <img
- :height="dimens"
- :width="dimens"
- :src="image.src"
- :alt="image.title"
- :title="image.title"
- />
- </VLink>
+ />
</Transition>
</ClientOnly>
</div>
diff --git a/frontend/src/components/VImageCell/VImageCell.vue b/frontend/src/components/VImageCell/VImageCell.vue
index 38e837a19..ec7334771 100644
--- a/frontend/src/components/VImageCell/VImageCell.vue
+++ b/frontend/src/components/VImageCell/VImageCell.vue
@@ -4,13 +4,12 @@ import { useI18n, useNuxtApp } from "#imports"
import { computed } from "vue"
import type { AspectRatio, ImageDetail } from "~/types/media"
-import type { ResultKind } from "~/types/result"
+import type { SingleResultProps } from "~/types/collection-component-props"
import { useImageCellSize } from "~/composables/use-image-cell-size"
+import { useSensitiveMedia } from "~/composables/use-sensitive-media"
import { IMAGE } from "~/constants/media"
-import { useSensitiveMedia } from "~/composables/use-sensitive-media"
-
import { useSearchStore } from "~/stores/search"
import VLicense from "~/components/VLicense/VLicense.vue"
@@ -19,25 +18,20 @@ import VLink from "~/components/VLink.vue"
import errorImage from "~/assets/image_not_available_placeholder.png"
const props = withDefaults(
- defineProps<{
- image: ImageDetail
- /**
- * The search term is added to the URL to allow the user to
- * navigate back/forward to the search results page.
- */
- searchTerm: string | null
- /**
- * All content view uses the square image cells, Image view
- * uses the image's intrinsic size.
- */
- aspectRatio?: AspectRatio
- kind?: ResultKind
- relatedTo?: string
- }>(),
+ defineProps<
+ SingleResultProps & {
+ image: ImageDetail
+ /**
+ * All content view uses the square image cells, Image view
+ * uses the image's intrinsic size.
+ */
+ aspectRatio?: AspectRatio
+ }
+ >(),
{
- aspectRatio: () => "square",
- kind: () => "search",
- relatedTo: () => "null",
+ aspectRatio: "square",
+ kind: "search",
+ relatedTo: "null",
}
)
diff --git a/frontend/src/components/VLoadMore.vue b/frontend/src/components/VLoadMore.vue
index e25bfdb74..acf26cb71 100644
--- a/frontend/src/components/VLoadMore.vue
+++ b/frontend/src/components/VLoadMore.vue
@@ -1,150 +1,116 @@
-<script lang="ts">
+<script setup lang="ts">
import { useI18n, useNuxtApp, useRoute } from "#imports"
-import {
- computed,
- defineComponent,
- onMounted,
- type PropType,
- ref,
- watch,
-} from "vue"
+import { computed, onMounted, ref, watch } from "vue"
import { storeToRefs } from "pinia"
import { useElementVisibility } from "@vueuse/core"
import { useMediaStore } from "~/stores/media"
import { useSearchStore } from "~/stores/search"
-import { defineEvent } from "~/types/emits"
import type { ResultKind } from "~/types/result"
import type { Collection } from "~/types/search"
+import type { SingleResultProps } from "~/types/collection-component-props"
import type { SupportedSearchType } from "~/constants/media"
import VButton from "~/components/VButton.vue"
-export default defineComponent({
- name: "VLoadMore",
- components: {
- VButton,
- },
- props: {
- searchType: {
- type: String as PropType<SupportedSearchType>,
- required: true,
- },
- searchTerm: {
- type: String,
- required: true,
- },
- kind: {
- type: String as PropType<ResultKind>,
- required: true,
- },
- isFetching: {
- type: Boolean,
- required: true,
- },
- },
- emits: {
- "load-more": defineEvent(),
- },
- setup(props, { emit }) {
- const loadMoreSectionRef = ref(null)
- const route = useRoute()
- const { t } = useI18n({ useScope: "global" })
- const mediaStore = useMediaStore()
- const searchStore = useSearchStore()
- const { $sendCustomEvent } = useNuxtApp()
-
- const { currentPage } = storeToRefs(mediaStore)
-
- const eventPayload = computed(() => {
- let kind: ResultKind =
- searchStore.strategy === "default" ? "search" : "collection"
- const collectionType =
- (searchStore.collectionValue as Collection) ?? "null"
- return {
- searchType: props.searchType,
- query: props.searchTerm,
- resultPage: currentPage.value || 1,
- kind,
- collectionType,
- collectionValue: searchStore.collectionValue ?? "null",
- }
- })
-
- /**
- * Whether we should show the "Load more" button.
- * If the fetching for the current query has started, there is at least
- * 1 page of results, there has been no fetching error, and there are
- * more results to fetch, we show the button.
- */
- const canLoadMore = computed(() => mediaStore.canLoadMore)
-
- const reachResultEndEventSent = ref(false)
- /**
- * On button click, send the analytics events and emit `load-more` event.
- *
- * The button is disabled when we are fetching, but we still check
- * whether we are currently fetching to be sure we don't fetch multiple times.
- *
- */
- const onLoadMore = async () => {
- if (props.isFetching) {
- return
- }
-
- reachResultEndEventSent.value = false
-
- $sendCustomEvent("LOAD_MORE_RESULTS", eventPayload.value)
-
- emit("load-more")
- }
+const props = defineProps<
+ SingleResultProps & {
+ searchType: SupportedSearchType
+ isFetching: boolean
+ }
+>()
+
+const emit = defineEmits<{
+ "load-more": []
+}>()
+
+const loadMoreSectionRef = ref(null)
+const route = useRoute()
+const { t } = useI18n({ useScope: "global" })
+const mediaStore = useMediaStore()
+const searchStore = useSearchStore()
+const { $sendCustomEvent } = useNuxtApp()
+
+const { currentPage } = storeToRefs(mediaStore)
+
+const eventPayload = computed(() => {
+ let kind: ResultKind =
+ searchStore.strategy === "default" ? "search" : "collection"
+ const collectionType = (searchStore.collectionValue as Collection) ?? "null"
+ return {
+ searchType: props.searchType,
+ query: props.searchTerm,
+ resultPage: currentPage.value || 1,
+ kind,
+ collectionType,
+ collectionValue: searchStore.collectionValue ?? "null",
+ }
+})
- const sendReachResultEnd = () => {
- // This function can be called before the media is fetched and
- // currentPage is updated from 0, so we use the value or 1.
- // The currentPage can never be 0 here because then the loadMore
- // button would not be visible.
- $sendCustomEvent("REACH_RESULT_END", eventPayload.value)
- }
+/**
+ * Whether we should show the "Load more" button.
+ * If the fetching for the current query has started, there is at least
+ * 1 page of results, there has been no fetching error, and there are
+ * more results to fetch, we show the button.
+ */
+const canLoadMore = computed(() => mediaStore.canLoadMore)
+
+const reachResultEndEventSent = ref(false)
+/**
+ * On button click, send the analytics events and emit `load-more` event.
+ *
+ * The button is disabled when we are fetching, but we still check
+ * whether we are currently fetching to be sure we don't fetch multiple times.
+ *
+ */
+const onLoadMore = async () => {
+ if (props.isFetching) {
+ return
+ }
+
+ reachResultEndEventSent.value = false
+
+ $sendCustomEvent("LOAD_MORE_RESULTS", eventPayload.value)
+
+ emit("load-more")
+}
+
+const sendReachResultEnd = () => {
+ // This function can be called before the media is fetched and
+ // currentPage is updated from 0, so we use the value or 1.
+ // The currentPage can never be 0 here because then the loadMore
+ // button would not be visible.
+ $sendCustomEvent("REACH_RESULT_END", eventPayload.value)
+}
+
+const buttonLabel = computed(() =>
+ props.isFetching ? t("browsePage.loading") : t("browsePage.load")
+)
+const mainPageElement = ref<HTMLElement | null>(null)
+onMounted(() => {
+ mainPageElement.value = document.getElementById("main-page")
+})
+const isLoadMoreButtonVisible = useElementVisibility(loadMoreSectionRef, {
+ scrollTarget: mainPageElement,
+})
+
+// Reset the reachResultEndEvent whenever the route changes,
+// to make sure the result end is tracked properly whenever
+// the search query or content type changes
+watch(route, () => {
+ reachResultEndEventSent.value = false
+})
- const buttonLabel = computed(() =>
- props.isFetching ? t("browsePage.loading") : t("browsePage.load")
- )
- const mainPageElement = ref<HTMLElement | null>(null)
- onMounted(() => {
- mainPageElement.value = document.getElementById("main-page")
- })
- const isLoadMoreButtonVisible = useElementVisibility(loadMoreSectionRef, {
- scrollTarget: mainPageElement,
- })
-
- // Reset the reachResultEndEvent whenever the route changes,
- // to make sure the result end is tracked properly whenever
- // the search query or content type changes
- watch(route, () => {
- reachResultEndEventSent.value = false
- })
-
- watch(isLoadMoreButtonVisible, (isVisible) => {
- if (isVisible) {
- if (reachResultEndEventSent.value) {
- return
- }
- sendReachResultEnd()
- reachResultEndEventSent.value = true
- }
- })
-
- return {
- buttonLabel,
- onLoadMore,
- canLoadMore,
-
- loadMoreSectionRef,
+watch(isLoadMoreButtonVisible, (isVisible) => {
+ if (isVisible) {
+ if (reachResultEndEventSent.value) {
+ return
}
- },
+ sendReachResultEnd()
+ reachResultEndEventSent.value = true
+ }
})
</script>
diff --git a/frontend/src/components/VScrollButton.vue b/frontend/src/components/VScrollButton.vue
index 16b136e94..47a4b97ca 100644
--- a/frontend/src/components/VScrollButton.vue
+++ b/frontend/src/components/VScrollButton.vue
@@ -1,36 +1,24 @@
-<script lang="ts">
-import { computed, defineComponent } from "vue"
-
-import { defineEvent } from "~/types/emits"
+<script setup lang="ts">
+import { computed } from "vue"
const positionWithoutSidebar = "ltr:right-4 rtl:left-4"
const positionWithSidebar = "ltr:right-[22rem] rtl:left-[22rem]"
-export default defineComponent({
- name: "VScrollButton",
- props: {
- isFilterSidebarVisible: {
- type: Boolean,
- default: true,
- },
- },
- emits: {
- tab: defineEvent<[KeyboardEvent]>(),
- },
- setup(props) {
- const hClass = computed(() =>
- props.isFilterSidebarVisible
- ? positionWithSidebar
- : positionWithoutSidebar
- )
- const scrollToTop = (e: MouseEvent) => {
- const element =
- (e.currentTarget as HTMLElement)?.closest("#main-page") || window
- element.scrollTo({ top: 0, left: 0, behavior: "smooth" })
- }
- return { hClass, scrollToTop }
- },
-})
+const props = withDefaults(
+ defineProps<{ isFilterSidebarVisible?: boolean }>(),
+ { isFilterSidebarVisible: true }
+)
+
+defineEmits<{ tab: [KeyboardEvent] }>()
+
+const hClass = computed(() =>
+ props.isFilterSidebarVisible ? positionWithSidebar : positionWithoutSidebar
+)
+const scrollToTop = (e: MouseEvent) => {
+ const element =
+ (e.currentTarget as HTMLElement)?.closest("#main-page") || window
+ element.scrollTo({ top: 0, left: 0, behavior: "smooth" })
+}
</script>
<template>
diff --git a/frontend/src/components/VSearchResultsGrid/VAllResultsGrid.vue b/frontend/src/components/VSearchResultsGrid/VAllResultsGrid.vue
index 38ef7fbef..07b186e78 100644
--- a/frontend/src/components/VSearchResultsGrid/VAllResultsGrid.vue
+++ b/frontend/src/components/VSearchResultsGrid/VAllResultsGrid.vue
@@ -1,5 +1,5 @@
-<script lang="ts">
-import { computed, defineComponent, type PropType } from "vue"
+<script setup lang="ts">
+import { computed } from "vue"
import { storeToRefs } from "pinia"
import { useUiStore } from "~/stores/ui"
@@ -10,41 +10,16 @@ import VImageCell from "~/components/VImageCell/VImageCell.vue"
import VAudioResult from "~/components/VSearchResultsGrid/VAudioResult.vue"
import VAudioInstructions from "~/components/VSearchResultsGrid/VAudioInstructions.vue"
-export default defineComponent({
- name: "VAllResultsGrid",
- components: {
- VImageCell,
- VAudioResult,
- VAudioInstructions,
- },
- props: {
- searchTerm: {
- type: String,
- required: true,
- },
- results: {
- type: Array as PropType<(AudioDetail | ImageDetail)[]>,
- required: true,
- },
- collectionLabel: {
- type: String,
- required: true,
- },
- },
- setup() {
- const uiStore = useUiStore()
- const { isFilterVisible: isSidebarVisible } = storeToRefs(uiStore)
+defineProps<{
+ searchTerm: string
+ results: (AudioDetail | ImageDetail)[]
+ collectionLabel: string
+}>()
- const isSm = computed(() => uiStore.isBreakpoint("sm"))
+const uiStore = useUiStore()
+const { isFilterVisible: isSidebarVisible } = storeToRefs(uiStore)
- return {
- isSidebarVisible,
- isSm,
-
- isDetail,
- }
- },
-})
+const isSm = computed(() => uiStore.isBreakpoint("sm"))
</script>
<template>
@@ -65,6 +40,7 @@ export default defineComponent({
:key="item.id"
:image="item"
:search-term="searchTerm"
+ kind="search"
aspect-ratio="square"
/>
<VAudioResult
diff --git a/frontend/src/components/VSearchResultsGrid/VAudioCollection.vue b/frontend/src/components/VSearchResultsGrid/VAudioCollection.vue
index 4239c5f21..c9fbce3b5 100644
--- a/frontend/src/components/VSearchResultsGrid/VAudioCollection.vue
+++ b/frontend/src/components/VSearchResultsGrid/VAudioCollection.vue
@@ -1,11 +1,10 @@
-<script lang="ts">
-import { computed, defineComponent, type PropType } from "vue"
-
-import type { AudioDetail } from "~/types/media"
-import type { ResultKind } from "~/types/result"
+<script setup lang="ts">
+import { computed } from "vue"
import { useUiStore } from "~/stores/ui"
+import type { CollectionComponentProps } from "~/types/collection-component-props"
+
import VAudioResult from "~/components/VSearchResultsGrid/VAudioResult.vue"
import VAudioInstructions from "~/components/VSearchResultsGrid/VAudioInstructions.vue"
@@ -13,61 +12,26 @@ import VAudioInstructions from "~/components/VSearchResultsGrid/VAudioInstructio
* This component shows a loading skeleton if the results are not yet loaded,
* and then shows the list of audio, with the Load more button if needed.
*/
-export default defineComponent({
- name: "VAudioCollection",
- components: {
- VAudioInstructions,
- VAudioResult,
- },
- props: {
- results: {
- type: Array as PropType<AudioDetail[]>,
- required: true,
- },
- /**
- * If used for Related audio, do not show the Load more button.
- */
- kind: {
- type: String as PropType<ResultKind>,
- required: true,
- },
- /**
- * The label used for the list of audio for accessibility.
- */
- collectionLabel: {
- type: String,
- required: true,
- },
- searchTerm: {
- type: String,
- required: true,
- },
- relatedTo: {
- type: String as PropType<string | null>,
- default: null,
- },
- },
- setup(props) {
- const uiStore = useUiStore()
- // Determine the size of the audio track based on the kind
- // of collection and the current breakpoint.
- const audioTrackSize = computed(() => {
- if (props.kind === "related") {
- return uiStore.isBreakpoint("sm") ? "m" : "s"
- } else {
- return !uiStore.isBreakpoint("sm")
- ? "s"
- : uiStore.isBreakpoint("xl")
- ? "l"
- : "m"
- }
- })
+const props = withDefaults(defineProps<CollectionComponentProps<"audio">>(), {
+ kind: "search",
+ relatedTo: "null",
+})
+
+const uiStore = useUiStore()
- return {
- audioTrackSize,
- }
- },
+// Determine the size of the audio track based on the kind
+// of collection and the current breakpoint.
+const audioTrackSize = computed(() => {
+ if (props.kind === "related") {
+ return uiStore.isBreakpoint("sm") ? "m" : "s"
+ } else {
+ return !uiStore.isBreakpoint("sm")
+ ? "s"
+ : uiStore.isBreakpoint("xl")
+ ? "l"
+ : "m"
+ }
})
</script>
diff --git a/frontend/src/components/VSearchResultsGrid/VAudioInstructions.vue b/frontend/src/components/VSearchResultsGrid/VAudioInstructions.vue
index f4f7e14e2..18c11fc0b 100644
--- a/frontend/src/components/VSearchResultsGrid/VAudioInstructions.vue
+++ b/frontend/src/components/VSearchResultsGrid/VAudioInstructions.vue
@@ -1,38 +1,20 @@
-<script lang="ts">
-import { computed, defineComponent, type PropType } from "vue"
+<script setup lang="ts">
+import { computed } from "vue"
import { useAudioSnackbar } from "~/composables/use-audio-snackbar"
import VSnackbar from "~/components/VSnackbar.vue"
-export default defineComponent({
- name: "VAudioInstructions",
- components: { VSnackbar },
- props: {
- kind: {
- type: String as PropType<"all" | "audio">,
- required: true,
- },
- },
- setup(props) {
- const { isVisible: isSnackbarVisible } = useAudioSnackbar()
+const props = defineProps<{ kind: "all" | "audio" }>()
- const keyboardKeys = computed(() =>
- props.kind === "all" ? ["spacebar"] : ["spacebar", "left", "right"]
- )
+const { isVisible: isSnackbarVisible } = useAudioSnackbar()
- const i18nPrefix = computed(() => {
- return props.kind === "all"
- ? "allResults.snackbar"
- : "audioResults.snackbar"
- })
+const keyboardKeys = computed(() =>
+ props.kind === "all" ? ["spacebar"] : ["spacebar", "left", "right"]
+)
- return {
- keyboardKeys,
- isSnackbarVisible,
- i18nPrefix,
- }
- },
+const i18nPrefix = computed(() => {
+ return props.kind === "all" ? "allResults.snackbar" : "audioResults.snackbar"
})
</script>
diff --git a/frontend/src/components/VSearchResultsGrid/VAudioResult.vue b/frontend/src/components/VSearchResultsGrid/VAudioResult.vue
index bbdd27d8d..b7a8f485a 100644
--- a/frontend/src/components/VSearchResultsGrid/VAudioResult.vue
+++ b/frontend/src/components/VSearchResultsGrid/VAudioResult.vue
@@ -1,7 +1,7 @@
-<script lang="ts">
+<script setup lang="ts">
import { useNuxtApp } from "#imports"
-import { defineComponent, PropType, toRefs } from "vue"
+import { toRefs } from "vue"
import { useAudioSnackbar } from "~/composables/use-audio-snackbar"
import { useSensitiveMedia } from "~/composables/use-sensitive-media"
@@ -11,90 +11,66 @@ import type { AudioInteractionData } from "~/types/analytics"
import type { AudioLayout, AudioSize } from "~/constants/audio"
import type { AudioTrackClickEvent } from "~/types/events"
import type { AudioDetail } from "~/types/media"
-import type { ResultKind } from "~/types/result"
+import type { SingleResultProps } from "~/types/collection-component-props"
import { useSearchStore } from "~/stores/search"
import VAudioTrack from "~/components/VAudioTrack/VAudioTrack.vue"
-export default defineComponent({
- name: "VAudioResult",
- components: { VAudioTrack },
- inheritAttrs: false,
- props: {
- layout: {
- type: String as PropType<Extract<AudioLayout, "box" | "row">>,
- required: true,
- },
- size: {
- type: String as PropType<AudioSize>,
- },
- audio: {
- type: Object as PropType<AudioDetail>,
- required: true,
- },
- searchTerm: {
- type: String,
- required: true,
- },
- kind: {
- type: String as PropType<ResultKind>,
- required: true,
- },
- relatedTo: {
- type: String as PropType<string | null>,
- default: null,
- },
- },
- setup(props) {
- const { $sendCustomEvent } = useNuxtApp()
- const searchStore = useSearchStore()
+defineOptions({ inheritAttrs: false })
- const { audio } = toRefs(props)
- const { isHidden: shouldBlur } = useSensitiveMedia(audio)
-
- const sendSelectSearchResultEvent = (
- audio: AudioDetail,
- { inWaveform }: AudioTrackClickEvent
- ) => {
- // Only send the event when the click navigates to the single result page.
- // If the click is in waveform or audio-control button, it controls the audio player.
- if (inWaveform) {
- return
- }
- useAudioSnackbar().hide()
- $sendCustomEvent("SELECT_SEARCH_RESULT", {
- id: audio.id,
- kind: props.kind,
- mediaType: AUDIO,
- query: props.searchTerm,
- provider: audio.provider,
- relatedTo: props.relatedTo ?? "null",
- sensitivities: audio.sensitivity?.join(",") ?? "",
- isBlurred: shouldBlur.value ?? "null",
- collectionType:
- searchStore.strategy !== "default" ? searchStore.strategy : "null",
- collectionValue: searchStore.collectionValue ?? "null",
- })
- }
- const sendInteractionEvent = (
- data: Omit<AudioInteractionData, "component">
- ) => {
- const component =
- props.kind === "related"
- ? "VRelatedAudio"
- : props.layout === "box"
- ? "VAllResultsGrid"
- : "AudioSearch"
- $sendCustomEvent("AUDIO_INTERACTION", { ...data, component })
+const props = withDefaults(
+ defineProps<
+ SingleResultProps & {
+ layout: Extract<AudioLayout, "box" | "row">
+ size?: AudioSize
+ audio: AudioDetail
}
+ >(),
+ { relatedTo: "null" }
+)
- return {
- sendSelectSearchResultEvent,
- sendInteractionEvent,
- }
- },
-})
+const { $sendCustomEvent } = useNuxtApp()
+const searchStore = useSearchStore()
+
+const { audio } = toRefs(props)
+const { isHidden: shouldBlur } = useSensitiveMedia(audio)
+
+const sendSelectSearchResultEvent = (
+ audio: AudioDetail,
+ { inWaveform }: AudioTrackClickEvent
+) => {
+ // Only send the event when the click navigates to the single result page.
+ // If the click is in waveform or audio-control button, it controls the audio player.
+ if (inWaveform) {
+ return
+ }
+ useAudioSnackbar().hide()
+ $sendCustomEvent("SELECT_SEARCH_RESULT", {
+ id: audio.id,
+ kind: props.kind,
+ mediaType: AUDIO,
+ query: props.searchTerm,
+ provider: audio.provider,
+ relatedTo: props.relatedTo ?? "null",
+ sensitivities: audio.sensitivity?.join(",") ?? "",
+ isBlurred: shouldBlur.value ?? "null",
+ collectionType:
+ searchStore.strategy !== "default" ? searchStore.strategy : "null",
+ collectionValue: searchStore.collectionValue ?? "null",
+ })
+}
+const sendInteractionEvent = (
+ data: Omit<AudioInteractionData, "component">
+) => {
+ const component =
+ props.kind === "related"
+ ? "VRelatedAudio"
+ : props.layout === "box"
+ ? "VAllResultsGrid"
+ : "AudioSearch"
+ $sendCustomEvent("AUDIO_INTERACTION", { ...data, component })
+}
</script>
<template>
diff --git a/frontend/src/components/VSearchResultsGrid/VCollectionResults.vue b/frontend/src/components/VSearchResultsGrid/VCollectionResults.vue
index 47d897879..2473a7fe9 100644
--- a/frontend/src/components/VSearchResultsGrid/VCollectionResults.vue
+++ b/frontend/src/components/VSearchResultsGrid/VCollectionResults.vue
@@ -1,50 +1,23 @@
-<script lang="ts">
-import { defineComponent, type PropType } from "vue"
-
+<script setup lang="ts">
import { isSupportedMediaType } from "~/constants/media"
import type { CollectionParams } from "~/types/search"
import type { AudioResults, ImageResults } from "~/types/result"
-import { defineEvent } from "~/types/emits"
-
import VCollectionHeader from "~/components/VCollectionHeader/VCollectionHeader.vue"
import VMediaCollection from "~/components/VSearchResultsGrid/VMediaCollection.vue"
import VLoadMore from "~/components/VLoadMore.vue"
-export default defineComponent({
- name: "VCollectionResults",
- components: { VLoadMore, VMediaCollection, VCollectionHeader },
- props: {
- collectionParams: {
- type: Object as PropType<CollectionParams>,
- required: true,
- },
- collectionLabel: {
- type: String,
- required: true,
- },
- results: {
- type: Object as PropType<ImageResults | AudioResults>,
- required: true,
- },
- isFetching: {
- type: Boolean,
- required: true,
- },
- searchTerm: {
- type: String,
- required: true,
- },
- creatorUrl: {
- type: String,
- },
- },
- emits: {
- "load-more": defineEvent(),
- },
- methods: { isSupportedMediaType },
-})
+defineProps<{
+ collectionParams: CollectionParams
+ collectionLabel: string
+ results: ImageResults | AudioResults
+ isFetching: boolean
+ searchTerm: string
+ creatorUrl?: string
+}>()
+
+defineEmits<{ "load-more": [] }>()
</script>
<template>
diff --git a/frontend/src/components/VSearchResultsGrid/VImageCollection.vue b/frontend/src/components/VSearchResultsGrid/VImageCollection.vue
index 258a89375..61aa6cae4 100644
--- a/frontend/src/components/VSearchResultsGrid/VImageCollection.vue
+++ b/frontend/src/components/VSearchResultsGrid/VImageCollection.vue
@@ -1,40 +1,15 @@
-<script lang="ts">
+<script setup lang="ts">
/**
* This component receives an array of images as a prop, and
* is responsible for displaying them as a grid.
*/
-import { defineComponent, type PropType } from "vue"
-import type { ResultKind } from "~/types/result"
-import type { ImageDetail } from "~/types/media"
+import type { CollectionComponentProps } from "~/types/collection-component-props"
import VImageCell from "~/components/VImageCell/VImageCell.vue"
-export default defineComponent({
- name: "VImageCollection",
- components: { VImageCell },
- props: {
- results: {
- type: Array as PropType<ImageDetail[]>,
- required: true,
- },
- kind: {
- type: String as PropType<ResultKind>,
- default: "search",
- },
- collectionLabel: {
- type: String,
- required: true,
- },
- searchTerm: {
- type: String,
- required: true,
- },
- relatedTo: {
- type: String as PropType<string>,
- default: "null",
- },
- },
+withDefaults(defineProps<CollectionComponentProps<"image">>(), {
+ relatedTo: "null",
})
</script>
diff --git a/frontend/src/components/VSearchResultsGrid/VMediaCollection.vue b/frontend/src/components/VSearchResultsGrid/VMediaCollection.vue
index 2182394f6..a0e4323ff 100644
--- a/frontend/src/components/VSearchResultsGrid/VMediaCollection.vue
+++ b/frontend/src/components/VSearchResultsGrid/VMediaCollection.vue
@@ -1,84 +1,31 @@
-<script lang="ts">
-import { computed, defineComponent, inject, type PropType, ref } from "vue"
+<script setup lang="ts">
+import { computed } from "vue"
-import type { Results } from "~/types/result"
-import { IsSidebarVisibleKey, ShowScrollButtonKey } from "~/types/provides"
-import { defineEvent } from "~/types/emits"
+import type { MediaCollectionComponentProps } from "~/types/collection-component-props"
+import { ALL_MEDIA, AUDIO, IMAGE } from "~/constants/media"
import VGridSkeleton from "~/components/VSkeleton/VGridSkeleton.vue"
import VAllResultsGrid from "~/components/VSearchResultsGrid/VAllResultsGrid.vue"
import VAudioCollection from "~/components/VSearchResultsGrid/VAudioCollection.vue"
import VImageCollection from "~/components/VSearchResultsGrid/VImageCollection.vue"
-import VScrollButton from "~/components/VScrollButton.vue"
-export default defineComponent({
- name: "VMediaCollection",
- components: {
- VScrollButton,
- VAllResultsGrid,
- VAudioCollection,
- VImageCollection,
- VGridSkeleton,
- },
- props: {
- results: {
- type: Object as PropType<Results>,
- required: true,
- },
- searchTerm: {
- type: String as PropType<string>,
- required: true,
- },
- kind: {
- type: String as PropType<"search" | "collection" | "related">,
- required: true,
- },
- collectionLabel: {
- type: String,
- required: true,
- },
- relatedTo: {
- type: String as PropType<string | null>,
- default: null,
- },
- /**
- * Overrides the value from the media store.
- * Used for the related media which uses a different store.
- */
- isFetching: {
- type: Boolean,
- required: true,
- },
- },
- emits: {
- "load-more": defineEvent(),
- },
- setup(props) {
- const showScrollButton = inject(ShowScrollButtonKey, ref(false))
- const isSidebarVisible = inject(IsSidebarVisibleKey, ref(false))
-
- const showSkeleton = computed(() => {
- return props.isFetching && props.results.items.length === 0
- })
+const props = withDefaults(defineProps<MediaCollectionComponentProps>(), {
+ relatedTo: "null",
+})
- const component = computed(() => {
- if (props.results.type === "image") {
- return "VImageCollection"
- } else if (props.results.type === "audio") {
- return "VAudioCollection"
- } else {
- return "VAllResultsGrid"
- }
- })
+defineEmits<{ "load-more": [] }>()
- return {
- showSkeleton,
- showScrollButton,
- isSidebarVisible,
- component,
- }
- },
+const showSkeleton = computed(() => {
+ return props.isFetching && props.results.items.length === 0
})
+
+const components = {
+ [IMAGE]: VImageCollection,
+ [AUDIO]: VAudioCollection,
+ [ALL_MEDIA]: VAllResultsGrid,
+}
+
+const component = computed(() => components[props.results.type])
</script>
<template>
@@ -99,11 +46,5 @@ export default defineComponent({
/>
<slot name="footer" />
-
- <VScrollButton
- v-show="showScrollButton"
- :is-filter-sidebar-visible="isSidebarVisible"
- data-testid="scroll-button"
- />
</section>
</template>
diff --git a/frontend/src/components/VSearchResultsGrid/VSearchResults.vue b/frontend/src/components/VSearchResultsGrid/VSearchResults.vue
index 7457510c9..c892f609e 100644
--- a/frontend/src/components/VSearchResultsGrid/VSearchResults.vue
+++ b/frontend/src/components/VSearchResultsGrid/VSearchResults.vue
@@ -1,11 +1,10 @@
-<script lang="ts">
+<script setup lang="ts">
import { useI18n } from "#imports"
-import { computed, defineComponent, PropType } from "vue"
+import { computed } from "vue"
import { useMediaStore } from "~/stores/media"
import { useSearchStore } from "~/stores/search"
-import { defineEvent } from "~/types/emits"
import type { SupportedMediaType } from "~/constants/media"
import type { Results } from "~/types/result"
@@ -16,54 +15,27 @@ import VLoadMore from "~/components/VLoadMore.vue"
import VExternalSearchForm from "~/components/VExternalSearch/VExternalSearchForm.vue"
import VContentLink from "~/components/VContentLink/VContentLink.vue"
-export default defineComponent({
- name: "VSearchResults",
- components: {
- VContentLink,
- VExternalSearchForm,
- VLoadMore,
- VMediaCollection,
- VSearchResultsTitle,
- },
- props: {
- searchTerm: {
- type: String as PropType<string>,
- required: true,
- },
- results: {
- type: Object as PropType<Results>,
- required: true,
- },
- isFetching: {
- type: Boolean,
- required: true,
- },
- },
- emits: {
- "load-more": defineEvent(),
- },
- setup(props) {
- const { t } = useI18n()
- const mediaStore = useMediaStore()
- const searchStore = useSearchStore()
+const props = defineProps<{
+ searchTerm: string
+ results: Results
+ isFetching: boolean
+}>()
- const collectionLabel = computed(() => {
- return t(`browsePage.aria.resultsLabel.${props.results.type}`, {
- query: props.searchTerm,
- })
- })
- const contentLinkPath = (mediaType: SupportedMediaType) =>
- searchStore.getSearchPath({ type: mediaType })
+defineEmits<{ "load-more": [] }>()
- const resultCounts = computed(() => mediaStore.resultCountsPerMediaType)
+const { t } = useI18n()
+const mediaStore = useMediaStore()
+const searchStore = useSearchStore()
- return {
- collectionLabel,
- contentLinkPath,
- resultCounts,
- }
- },
+const collectionLabel = computed(() => {
+ return t(`browsePage.aria.resultsLabel.${props.results.type}`, {
+ query: props.searchTerm,
+ })
})
+const contentLinkPath = (mediaType: SupportedMediaType) =>
+ searchStore.getSearchPath({ type: mediaType })
+
+const resultCounts = computed(() => mediaStore.resultCountsPerMediaType)
</script>
<template>
diff --git a/frontend/src/components/VSearchResultsTitle.vue b/frontend/src/components/VSearchResultsTitle.vue
index e9736903e..af89b6143 100644
--- a/frontend/src/components/VSearchResultsTitle.vue
+++ b/frontend/src/components/VSearchResultsTitle.vue
@@ -1,109 +1,93 @@
-<script lang="ts">
+<script setup lang="ts">
import { useI18n } from "#imports"
-import { defineComponent, PropType, computed } from "vue"
+import { computed } from "vue"
import type { SupportedMediaType, SupportedSearchType } from "~/constants/media"
import { useGetLocaleFormattedNumber } from "~/composables/use-get-locale-formatted-number"
import { getCountKey } from "~/composables/use-i18n-utilities"
-export default defineComponent({
- name: "VSearchResultsTitle",
- props: {
- searchTerm: {
- required: true,
- type: String,
- },
- size: {
- required: false,
- default: "default",
- type: String as PropType<"default" | "large">,
- },
- resultCounts: {
- required: true,
- type: Array as PropType<[SupportedMediaType, number][]>,
- },
- searchType: {
- required: true,
- type: String as PropType<SupportedSearchType>,
- },
- },
- setup(props) {
- const getLocaleFormattedNumber = useGetLocaleFormattedNumber()
- const { t } = useI18n()
- const mediaLocaleCounts = computed(() =>
- props.resultCounts.reduce(
- (acc, [mediaType, count]) => {
- return {
- ...acc,
- [mediaType]: {
- count,
- countKey: getCountKey(count),
- localeCount: getLocaleFormattedNumber(count),
- },
- }
+const props = withDefaults(
+ defineProps<{
+ searchTerm: string
+ searchType: SupportedSearchType
+ resultCounts: [SupportedMediaType, number][]
+ size?: "default" | "large"
+ }>(),
+ {
+ size: "default",
+ }
+)
+
+const getLocaleFormattedNumber = useGetLocaleFormattedNumber()
+const { t } = useI18n()
+const mediaLocaleCounts = computed(() =>
+ props.resultCounts.reduce(
+ (acc, [mediaType, count]) => {
+ return {
+ ...acc,
+ [mediaType]: {
+ count,
+ countKey: getCountKey(count),
+ localeCount: getLocaleFormattedNumber(count),
},
- {} as Record<
- SupportedMediaType,
- { count: number; countKey: string; localeCount: string }
- >
- )
- )
+ }
+ },
+ {} as Record<
+ SupportedMediaType,
+ { count: number; countKey: string; localeCount: string }
+ >
+ )
+)
- const _getAllMediaAriaHeading = () => {
- const imageLocaleCounts = mediaLocaleCounts.value.image
- const imageResults = t(
- `browsePage.aria.allResultsHeadingCount.image.${imageLocaleCounts.countKey}`,
- {
- localeCount: imageLocaleCounts.localeCount,
- }
- )
+const _getAllMediaAriaHeading = () => {
+ const imageLocaleCounts = mediaLocaleCounts.value.image
+ const imageResults = t(
+ `browsePage.aria.allResultsHeadingCount.image.${imageLocaleCounts.countKey}`,
+ {
+ localeCount: imageLocaleCounts.localeCount,
+ }
+ )
- const audioLocaleCounts = mediaLocaleCounts.value.audio
- const audioResults = t(
- `browsePage.aria.allResultsHeadingCount.audio.${audioLocaleCounts.countKey}`,
- {
- localeCount: audioLocaleCounts.localeCount,
- }
- )
+ const audioLocaleCounts = mediaLocaleCounts.value.audio
+ const audioResults = t(
+ `browsePage.aria.allResultsHeadingCount.audio.${audioLocaleCounts.countKey}`,
+ {
+ localeCount: audioLocaleCounts.localeCount,
+ }
+ )
- return t("browsePage.aria.results.all", {
+ return t("browsePage.aria.results.all", {
+ query: props.searchTerm,
+ imageResults,
+ audioResults,
+ })
+}
+
+const ariaHeading = computed((): string => {
+ switch (props.searchType) {
+ case "image": {
+ const { count, countKey, localeCount } = mediaLocaleCounts.value.image
+ return t(`browsePage.aria.results.image.${countKey}`, {
+ count,
+ localeCount,
query: props.searchTerm,
- imageResults,
- audioResults,
})
}
-
- const ariaHeading = computed((): string => {
- switch (props.searchType) {
- case "image": {
- const { count, countKey, localeCount } = mediaLocaleCounts.value.image
- return t(`browsePage.aria.results.image.${countKey}`, {
- count,
- localeCount,
- query: props.searchTerm,
- })
- }
- case "audio": {
- const { count, countKey, localeCount } = mediaLocaleCounts.value.audio
- return t(`browsePage.aria.results.audio.${countKey}`, {
- count,
- localeCount,
- query: props.searchTerm,
- })
- }
- default:
- case "all": {
- return _getAllMediaAriaHeading()
- }
- }
- })
-
- return {
- ariaHeading,
+ case "audio": {
+ const { count, countKey, localeCount } = mediaLocaleCounts.value.audio
+ return t(`browsePage.aria.results.audio.${countKey}`, {
+ count,
+ localeCount,
+ query: props.searchTerm,
+ })
+ }
+ default:
+ case "all": {
+ return _getAllMediaAriaHeading()
}
- },
+ }
})
</script>
diff --git a/frontend/src/components/VSkeleton/VAudioTrackSkeleton.vue b/frontend/src/components/VSkeleton/VAudioTrackSkeleton.vue
index cacc6c08d..a8aa8b9bf 100644
--- a/frontend/src/components/VSkeleton/VAudioTrackSkeleton.vue
+++ b/frontend/src/components/VSkeleton/VAudioTrackSkeleton.vue
@@ -1,14 +1,7 @@
-<script lang="ts">
-import { defineComponent } from "vue"
-
-export default defineComponent({
- name: "VAudioTrackSkeleton",
- methods: {
- getRandomSize(max = 250, min = 70) {
- return Math.floor(Math.random() * (max - min) + min)
- },
- },
-})
+<script setup lang="ts">
+const getRandomSize = (max = 250, min = 70) => {
+ return Math.floor(Math.random() * (max - min) + min)
+}
</script>
<template>
diff --git a/frontend/src/components/VSkeleton/VBone.vue b/frontend/src/components/VSkeleton/VBone.vue
index 2f1932a88..7ce0ed530 100644
--- a/frontend/src/components/VSkeleton/VBone.vue
+++ b/frontend/src/components/VSkeleton/VBone.vue
@@ -1,14 +1,9 @@
-<script lang="ts">
-import { defineComponent } from "vue"
-
-export default defineComponent({
- name: "VBone",
- props: { shimmer: { type: Boolean, default: true } },
-})
+<script setup lang="ts">
+withDefaults(defineProps<{ shimmer?: boolean }>(), { shimmer: true })
</script>
<template>
- <div :class="['bg-secondary', shimmer ? 'shimmering' : '']" />
+ <div :class="['bg-secondary', { shimmering: shimmer }]" />
</template>
<style scoped>
diff --git a/frontend/src/components/VSkeleton/VGridSkeleton.vue b/frontend/src/components/VSkeleton/VGridSkeleton.vue
index 1e2d0334c..e0a15e57b 100644
--- a/frontend/src/components/VSkeleton/VGridSkeleton.vue
+++ b/frontend/src/components/VSkeleton/VGridSkeleton.vue
@@ -1,52 +1,43 @@
-<script lang="ts">
+<script setup lang="ts">
/**
* Display placeholder elements while waiting for the actual elements to be
* loaded in the results views.
*/
-import { computed, defineComponent, PropType } from "vue"
+import { computed } from "vue"
import type { SupportedSearchType } from "~/constants/media"
import VAudioTrackSkeleton from "~/components/VSkeleton/VAudioTrackSkeleton.vue"
import VBone from "~/components/VSkeleton/VBone.vue"
-export default defineComponent({
- name: "VGridSkeleton",
- components: { VAudioTrackSkeleton, VBone },
- props: {
- isForTab: {
- type: String as PropType<SupportedSearchType>,
- default: "image",
- },
- numElems: {
- type: Number,
- },
- isSidebarVisible: {
- type: Boolean,
- default: false,
- },
- },
- setup(props) {
- function getRandomSize(max = 300, min = 100) {
- return Math.floor(Math.random() * (max - min) + min)
- }
+const props = withDefaults(
+ defineProps<{
+ isForTab?: SupportedSearchType
+ numElems?: number
+ isSidebarVisible?: boolean
+ }>(),
+ {
+ isForTab: "image",
+ isSidebarVisible: false,
+ }
+)
- const elementCount = computed(() => {
- // Calculate the default element count based on isForTab
- if (props.numElems) {
- return props.numElems
- }
- if (props.isForTab === "all") {
- return 20
- }
- if (props.isForTab === "image") {
- return 30
- }
- return 8
- })
+function getRandomSize(max = 300, min = 100) {
+ return Math.floor(Math.random() * (max - min) + min)
+}
- return { getRandomSize, elementCount }
- },
+const elementCount = computed(() => {
+ // Calculate the default element count based on isForTab
+ if (props.numElems) {
+ return props.numElems
+ }
+ if (props.isForTab === "all") {
+ return 20
+ }
+ if (props.isForTab === "image") {
+ return 30
+ }
+ return 8
})
</script>
diff --git a/frontend/src/components/VSnackbar.vue b/frontend/src/components/VSnackbar.vue
index 2beaa245f..b580d2b69 100644
--- a/frontend/src/components/VSnackbar.vue
+++ b/frontend/src/components/VSnackbar.vue
@@ -1,22 +1,14 @@
-<script lang="ts">
-import { defineComponent, PropType } from "vue"
-
-export default defineComponent({
- name: "VSnackbar",
- props: {
- size: {
- type: String as PropType<"small" | "large">,
- default: "small",
- },
- /**
- * whether the snackbar is visible or hidden
- */
- isVisible: {
- type: Boolean,
- default: true,
- },
- },
-})
+<script setup lang="ts">
+withDefaults(
+ defineProps<{
+ size?: "small" | "large"
+ isVisible?: boolean
+ }>(),
+ {
+ size: "small",
+ isVisible: true,
+ }
+)
</script>
<template>
diff --git a/frontend/src/layouts/content-layout.vue b/frontend/src/layouts/content-layout.vue
index 300bc33f6..f5bf10a21 100644
--- a/frontend/src/layouts/content-layout.vue
+++ b/frontend/src/layouts/content-layout.vue
@@ -7,6 +7,7 @@ import { ShowScrollButtonKey } from "~/types/provides"
import VFooter from "~/components/VFooter/VFooter.vue"
import VHeader from "~/components/VHeader/VHeader.vue"
+import VScrollButton from "~/components/VScrollButton.vue"
/**
* This is the ContentLayout: the single result and the content pages.
@@ -41,6 +42,12 @@ provide(ShowScrollButtonKey, showScrollButton)
<slot />
<VFooter mode="internal" class="border-t border-default bg-default" />
</div>
+
+ <VScrollButton
+ v-show="showScrollButton"
+ :is-filter-sidebar-visible="false"
+ data-testid="scroll-button"
+ />
</div>
</template>
diff --git a/frontend/src/layouts/search-layout.vue b/frontend/src/layouts/search-layout.vue
index 7ff2f8fc8..4ee9cc86e 100644
--- a/frontend/src/layouts/search-layout.vue
+++ b/frontend/src/layouts/search-layout.vue
@@ -5,12 +5,17 @@ import { useScroll } from "@vueuse/core"
import { useUiStore } from "~/stores/ui"
import { isSearchTypeSupported, useSearchStore } from "~/stores/search"
-import { IsHeaderScrolledKey, IsSidebarVisibleKey } from "~/types/provides"
+import {
+ IsHeaderScrolledKey,
+ IsSidebarVisibleKey,
+ ShowScrollButtonKey,
+} from "~/types/provides"
import VFooter from "~/components/VFooter/VFooter.vue"
import VSearchGridFilter from "~/components/VFilters/VSearchGridFilter.vue"
import VSafeBrowsing from "~/components/VSafeBrowsing/VSafeBrowsing.vue"
import VHeader from "~/components/VHeader/VHeader.vue"
+import VScrollButton from "~/components/VScrollButton.vue"
defineOptions({
name: "SearchLayout",
@@ -56,6 +61,7 @@ onMounted(() => {
provide(IsHeaderScrolledKey, isHeaderScrolled)
provide(IsSidebarVisibleKey, isSidebarVisible)
+provide(ShowScrollButtonKey, showScrollButton)
</script>
<template>
@@ -88,6 +94,12 @@ provide(IsSidebarVisibleKey, isSidebarVisible)
<slot />
<VFooter mode="content" class="border-t border-default bg-default" />
</div>
+
+ <VScrollButton
+ v-show="showScrollButton"
+ :is-filter-sidebar-visible="isSidebarVisible"
+ data-testid="scroll-button"
+ />
</div>
</template>
diff --git a/frontend/src/types/collection-component-props.ts b/frontend/src/types/collection-component-props.ts
new file mode 100644
index 000000000..7d9b113de
--- /dev/null
+++ b/frontend/src/types/collection-component-props.ts
@@ -0,0 +1,30 @@
+import { type SupportedSearchType, IMAGE, AUDIO } from "~/constants/media"
+import type { AudioDetail, ImageDetail } from "~/types/media"
+import type { ResultKind, Results } from "~/types/result"
+
+export type SingleResultProps = {
+ kind: ResultKind
+ searchTerm: string
+ relatedTo?: string
+}
+export type CommonCollectionProps = SingleResultProps & {
+ collectionLabel: string
+}
+
+export type MediaCollectionComponentProps = CommonCollectionProps & {
+ results: Results
+ /**
+ * Overrides the value from the media store.
+ * Used for the related media which uses a different store.
+ */
+ isFetching: boolean
+}
+
+export type CollectionComponentProps<T extends SupportedSearchType> =
+ CommonCollectionProps & {
+ results: T extends typeof IMAGE
+ ? ImageDetail[]
+ : T extends typeof AUDIO
+ ? AudioDetail[]
+ : (ImageDetail | AudioDetail)[]
+ }
diff --git a/frontend/src/types/home-gallery.ts b/frontend/src/types/home-gallery.ts
new file mode 100644
index 000000000..847ff15ce
--- /dev/null
+++ b/frontend/src/types/home-gallery.ts
@@ -0,0 +1,2 @@
+const GALLERY_SETS = ["universe", "pottery", "olympics", "random"] as const
+export type GallerySet = (typeof GALLERY_SETS)[number]
diff --git a/frontend/test/playwright/visual-regression/pages/errors.spec.ts-snapshots/generic-error-xl-linux.png b/frontend/test/playwright/visual-regression/pages/errors.spec.ts-snapshots/generic-error-xl-linux.png
index c451d2c58..c8804252e 100644
Binary files a/frontend/test/playwright/visual-regression/pages/errors.spec.ts-snapshots/generic-error-xl-linux.png and b/frontend/test/playwright/visual-regression/pages/errors.spec.ts-snapshots/generic-error-xl-linux.png differ