Skip to content

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

Remove `mediaType` from `search.query` state (#851)

Olga Bulat802ace346a09
diff --git a/package.json b/package.json
index 2a8c96160..e79ba3211 100644
--- a/package.json
+++ b/package.json
@@ -22,6 +22,7 @@
"test:watch": "jest --collectCoverage=false --watch",
"test:unit": "jest --collectCoverage=false",
"test:e2e": "playwright test",
+ "test:e2e-debug": "PWDEBUG=1 playwright test",
"run-server": "cross-env nuxt build && pnpm start",
"e2e:ci": "start-server-and-test run-server http://localhost:8443 test:e2e",
"generate-e2e-tests": "playwright codegen localhost:8443/",
diff --git a/src/components/VAllResultsGrid/VAllResultsGrid.vue b/src/components/VAllResultsGrid/VAllResultsGrid.vue
index 2b3748593..de648eefb 100644
--- a/src/components/VAllResultsGrid/VAllResultsGrid.vue
+++ b/src/components/VAllResultsGrid/VAllResultsGrid.vue
@@ -56,12 +56,14 @@ import { computed, defineComponent, useContext } from '@nuxtjs/composition-api'
import VImageCell from '~/components/VAllResultsGrid/VImageCell.vue'
import VAudioCell from '~/components/VAllResultsGrid/VAudioCell.vue'
import VLoadMore from '~/components/VLoadMore.vue'
+import VContentLink from '~/components/VContentLink/VContentLink.vue'
+import GridSkeleton from '~/components/Skeleton/GridSkeleton.vue'
import srand from '~/utils/srand'
export default defineComponent({
name: 'VAllResultsGrid',
- components: { VImageCell, VAudioCell, VLoadMore },
+ components: { GridSkeleton, VContentLink, VImageCell, VAudioCell, VLoadMore },
props: ['canLoadMore'],
setup(_, { emit }) {
const { i18n, store } = useContext()
@@ -86,18 +88,21 @@ export default defineComponent({
// if (resultsLoading.value) return []
const media = store.getters['media/mediaResults']
const mediaKeys = Object.keys(media)
-
// Seed the random number generator with the ID of
// the first and last search result, so the non-image
// distribution is the same on repeated searches
const rand = srand(Object.keys(media[mediaKeys[0]])[0])
const randomIntegerInRange = (min, max) =>
Math.floor(rand() * (max - min + 1)) + min
-
+ /**
+ * When navigating from All page to Audio page, VAllResultsGrid is displayed
+ * for a short period of time. Then media['image'] is undefined, and it throws an error
+ * `TypeError: can't convert undefined to object`. To fix it, we add `|| {}` to the media['image'].
+ */
/** @type {import('../../store/types').AudioDetail[] | import('../../store/types').ImageDetail[]} */
const newResults = []
// first push all images to the results list
- for (const id of Object.keys(media['image'])) {
+ for (const id of Object.keys(media['image'] || {})) {
const item = media['image'][id]
item.frontendMediaType = 'image'
newResults.push(item)
diff --git a/src/components/VContentSwitcher/VMobileMenuModal.vue b/src/components/VContentSwitcher/VMobileMenuModal.vue
index 8e3e60c84..df7e4632d 100644
--- a/src/components/VContentSwitcher/VMobileMenuModal.vue
+++ b/src/components/VContentSwitcher/VMobileMenuModal.vue
@@ -1,7 +1,7 @@
<template>
<div ref="nodeRef" class="mobile-menu ms-auto md:ms-0">
<div ref="triggerContainerRef" @click="onTriggerClick">
- <VContentSwitcherButton
+ <VSearchTypeButton
:a11y-props="triggerA11yProps"
:active-item="activeItem"
aria-controls="content-switcher-modal"
@@ -19,8 +19,8 @@
class="p-6"
aria-labelledby="content-switcher-heading"
>
- <VContentTypes
- ref="contentTypesNode"
+ <VSearchTypes
+ ref="searchTypesNode"
size="small"
:active-item="content.activeType.value"
@select="selectItem"
@@ -33,28 +33,29 @@
<script>
import {
+ computed,
+ defineComponent,
onMounted,
reactive,
ref,
watch,
- computed,
} from '@nuxtjs/composition-api'
import { useBodyScrollLock } from '~/composables/use-body-scroll-lock'
-import useContentType from '~/composables/use-content-type'
+import useSearchType from '~/composables/use-search-type'
import usePages from '~/composables/use-pages'
import VMobileModalContent from '~/components/VModal/VMobileModalContent.vue'
-import VContentTypes from '~/components/VContentSwitcher/VContentTypes.vue'
+import VSearchTypes from '~/components/VContentSwitcher/VSearchTypes.vue'
import VPageList from '~/components/VHeader/VPageMenu/VPageList.vue'
-import VContentSwitcherButton from '~/components/VContentSwitcher/VContentSwitcherButton'
+import VSearchTypeButton from '~/components/VContentSwitcher/VSearchTypeButton.vue'
-export default {
+export default defineComponent({
name: 'VMobileContentSwitcher',
components: {
VMobileModalContent,
- VContentTypes,
+ VSearchTypes,
VPageList,
- VContentSwitcherButton,
+ VSearchTypeButton,
},
props: {
activeItem: {
@@ -63,11 +64,11 @@ export default {
},
},
setup(_, { emit }) {
- const content = useContentType()
+ const content = useSearchType()
const pages = usePages()
/** @type {import('@nuxtjs/composition-api').Ref<import('vue/types/vue').Vue | null>} */
- const contentTypesNode = ref(null)
+ const searchTypesNode = ref(null)
const modalRef = ref(null)
const triggerContainerRef = ref(null)
@@ -85,7 +86,7 @@ export default {
onMounted(() => (triggerRef.value = triggerContainerRef.value?.firstChild))
const initialFocusElement = computed(() =>
- contentTypesNode.value?.$el?.querySelector('[aria-checked="true"]')
+ searchTypesNode.value?.$el?.querySelector('[aria-checked="true"]')
)
watch([visibleRef], ([visible]) => {
@@ -133,8 +134,8 @@ export default {
visibleRef,
selectItem,
initialFocusElement,
- contentTypesNode,
+ searchTypesNode,
}
},
-}
+})
</script>
diff --git a/src/components/VContentSwitcher/VContentSwitcherButton.vue b/src/components/VContentSwitcher/VSearchTypeButton.vue
similarity index 85%
rename from src/components/VContentSwitcher/VContentSwitcherButton.vue
rename to src/components/VContentSwitcher/VSearchTypeButton.vue
index 5764bf96e..28c3f9fa5 100644
--- a/src/components/VContentSwitcher/VContentSwitcherButton.vue
+++ b/src/components/VContentSwitcher/VSearchTypeButton.vue
@@ -22,9 +22,14 @@
</VButton>
</template>
<script>
-import { ALL_MEDIA, AUDIO, IMAGE } from '~/constants/media'
-import { computed, inject, useContext } from '@nuxtjs/composition-api'
-import useContentType from '~/composables/use-content-type'
+import { ALL_MEDIA, supportedSearchTypes } from '~/constants/media'
+import {
+ computed,
+ defineComponent,
+ inject,
+ useContext,
+} from '@nuxtjs/composition-api'
+import useSearchType from '~/composables/use-search-type'
import { isMinScreen } from '~/composables/use-media-query'
import caretDownIcon from '~/assets/icons/caret-down.svg'
@@ -32,8 +37,8 @@ import caretDownIcon from '~/assets/icons/caret-down.svg'
import VButton from '~/components/VButton.vue'
import VIcon from '~/components/VIcon/VIcon.vue'
-export default {
- name: 'VContentSwitcherButton',
+export default defineComponent({
+ name: 'VSearchTypeButton',
components: { VButton, VIcon },
props: {
a11yProps: {
@@ -43,7 +48,7 @@ export default {
activeItem: {
type: String,
default: ALL_MEDIA,
- validator: (v) => [ALL_MEDIA, IMAGE, AUDIO].includes(v),
+ validator: (v) => supportedSearchTypes.includes(v),
},
type: {
type: String,
@@ -56,7 +61,7 @@ export default {
const isHeaderScrolled = inject('isHeaderScrolled', null)
const isMinScreenMd = isMinScreen('md', { shouldPassInSSR: true })
- const { icons, activeType: activeItem } = useContentType()
+ const { icons, activeType: activeItem } = useSearchType()
const isIconButton = computed(
() => isHeaderScrolled?.value && !isMinScreenMd.value
)
@@ -67,7 +72,7 @@ export default {
return 'w-10 h-10'
} else {
/**
- When there is a caret down icon (on 'md' screens), paddings are balanced,
+ When there is a caret down icon (on 'md' screens), paddings are balanced,
without it, paddings need to be adjusted.
*/
return 'ps-2 pe-3 md:px-2'
@@ -107,5 +112,5 @@ export default {
icon: computed(() => icons[activeItem.value]),
}
},
-}
+})
</script>
diff --git a/src/components/VContentSwitcher/VContentItem.vue b/src/components/VContentSwitcher/VSearchTypeItem.vue
similarity index 92%
rename from src/components/VContentSwitcher/VContentItem.vue
rename to src/components/VContentSwitcher/VSearchTypeItem.vue
index 16a43eb74..d152ee7b2 100644
--- a/src/components/VContentSwitcher/VContentItem.vue
+++ b/src/components/VContentSwitcher/VSearchTypeItem.vue
@@ -25,8 +25,8 @@ const propTypes = {
selected: { type: Boolean, default: false },
icon: { type: String, required: true },
}
-const VContentItem = defineComponent({
- name: 'VContentItem',
+export default defineComponent({
+ name: 'VSearchTypeItem',
props: propTypes,
setup(props) {
const status = computed(() => {
@@ -37,5 +37,4 @@ const VContentItem = defineComponent({
}
},
})
-export default VContentItem
</script>
diff --git a/src/components/VContentSwitcher/VContentSwitcherPopover.vue b/src/components/VContentSwitcher/VSearchTypePopover.vue
similarity index 79%
rename from src/components/VContentSwitcher/VContentSwitcherPopover.vue
rename to src/components/VContentSwitcher/VSearchTypePopover.vue
index 75ebb5b8b..af160348b 100644
--- a/src/components/VContentSwitcher/VContentSwitcherPopover.vue
+++ b/src/components/VContentSwitcher/VSearchTypePopover.vue
@@ -6,7 +6,7 @@
placement="bottom-start"
>
<template #trigger="{ a11yProps }">
- <VContentSwitcherButton
+ <VSearchTypeButton
:a11y-props="a11yProps"
aria-controls="content-switcher-popover"
:active-item="activeItem"
@@ -18,7 +18,7 @@
:type="placement"
/>
</template>
- <VContentTypes
+ <VSearchTypes
id="content-switcher-popover"
size="medium"
:active-item="activeItem"
@@ -28,20 +28,20 @@
</template>
<script>
-import { computed, ref } from '@nuxtjs/composition-api'
-import useContentType from '~/composables/use-content-type'
+import { computed, defineComponent, ref } from '@nuxtjs/composition-api'
+import useSearchType from '~/composables/use-search-type'
import checkIcon from '~/assets/icons/checkmark.svg'
import VPopover from '~/components/VPopover/VPopover.vue'
-import VContentSwitcherButton from '~/components/VContentSwitcher/VContentSwitcherButton.vue'
-import VContentTypes from '~/components/VContentSwitcher/VContentTypes.vue'
+import VSearchTypeButton from '~/components/VContentSwitcher/VSearchTypeButton.vue'
+import VSearchTypes from '~/components/VContentSwitcher/VSearchTypes.vue'
-export default {
- name: 'VContentSwitcherPopover',
+export default defineComponent({
+ name: 'VSearchTypePopover',
components: {
- VContentSwitcherButton,
+ VSearchTypeButton,
VPopover,
- VContentTypes,
+ VSearchTypes,
},
model: {
prop: 'activeItem',
@@ -58,7 +58,7 @@ export default {
},
},
setup(props, { emit }) {
- const content = useContentType()
+ const content = useSearchType()
const contentMenuPopover = ref(null)
@@ -91,5 +91,5 @@ export default {
closeMenu,
}
},
-}
+})
</script>
diff --git a/src/components/VContentSwitcher/VContentTypeButton.vue b/src/components/VContentSwitcher/VSearchTypeRadio.vue
similarity index 82%
rename from src/components/VContentSwitcher/VContentTypeButton.vue
rename to src/components/VContentSwitcher/VSearchTypeRadio.vue
index 3aa1112f5..670919559 100644
--- a/src/components/VContentSwitcher/VContentTypeButton.vue
+++ b/src/components/VContentSwitcher/VSearchTypeRadio.vue
@@ -7,7 +7,7 @@
@click="handleClick"
>
<VIcon :icon-path="iconPath" class="me-1 flex-shrink-0" />
- <span>{{ $t(`search-type.${contentType}`) }}</span>
+ <span>{{ $t(`search-type.${searchType}`) }}</span>
</button>
</template>
@@ -17,7 +17,7 @@ import {
ALL_MEDIA,
AUDIO,
IMAGE,
- supportedContentTypes,
+ supportedSearchTypes,
} from '~/constants/media'
import VIcon from '~/components/VIcon/VIcon.vue'
@@ -32,16 +32,16 @@ const iconMapping = {
}
export default defineComponent({
- name: 'VContentTypeButton',
+ name: 'VSearchTypeRadio',
components: { VIcon },
props: {
/**
* One of the media types supported.
*/
- contentType: {
+ searchType: {
type: String,
required: true,
- validator: (v) => supportedContentTypes.includes(v),
+ validator: (v) => supportedSearchTypes.includes(v),
},
selected: {
type: Boolean,
@@ -49,8 +49,8 @@ export default defineComponent({
},
},
setup(props, { emit }) {
- const iconPath = computed(() => iconMapping[props.contentType])
- const handleClick = () => emit('select', props.contentType)
+ const iconPath = computed(() => iconMapping[props.searchType])
+ const handleClick = () => emit('select', props.searchType)
return { iconPath, handleClick }
},
})
diff --git a/src/components/VContentSwitcher/VContentTypes.vue b/src/components/VContentSwitcher/VSearchTypes.vue
similarity index 75%
rename from src/components/VContentSwitcher/VContentTypes.vue
rename to src/components/VContentSwitcher/VSearchTypes.vue
index db4aea669..f4e0bb02a 100644
--- a/src/components/VContentSwitcher/VContentTypes.vue
+++ b/src/components/VContentSwitcher/VSearchTypes.vue
@@ -7,7 +7,7 @@
type="radiogroup"
class="z-10"
>
- <VContentItem
+ <VSearchTypeItem
v-for="(item, idx) in content.types"
:key="item"
class="md:mb-1"
@@ -20,16 +20,16 @@
</VItemGroup>
</template>
<script>
-import { supportedContentTypes } from '~/constants/media'
-import useContentType from '~/composables/use-content-type'
+import { supportedSearchTypes } from '~/constants/media'
+import useSearchType from '~/composables/use-search-type'
import VItemGroup from '~/components/VItemGroup/VItemGroup.vue'
-import VContentItem from '~/components/VContentSwitcher/VContentItem.vue'
+import VSearchTypeItem from '~/components/VContentSwitcher/VSearchTypeItem.vue'
import { computed, defineComponent } from '@nuxtjs/composition-api'
export default defineComponent({
- name: 'VContentTypes',
- components: { VItemGroup, VContentItem },
+ name: 'VSearchTypes',
+ components: { VItemGroup, VSearchTypeItem },
props: {
/**
* 'Small' size for mobile screens,
@@ -43,11 +43,11 @@ export default defineComponent({
activeItem: {
type: String,
required: true,
- validator: (val) => supportedContentTypes.includes(val),
+ validator: (val) => supportedSearchTypes.includes(val),
},
},
setup(props, { emit }) {
- const content = useContentType()
+ const content = useSearchType()
const bordered = computed(() => props.size === 'small')
const handleClick = (item) => {
emit('select', item)
diff --git a/src/components/VContentSwitcher/meta/VContentSwitcherPopover.stories.mdx b/src/components/VContentSwitcher/meta/VContentSwitcherPopover.stories.mdx
index f56c3e8eb..7dc9084c1 100644
--- a/src/components/VContentSwitcher/meta/VContentSwitcherPopover.stories.mdx
+++ b/src/components/VContentSwitcher/meta/VContentSwitcherPopover.stories.mdx
@@ -8,11 +8,11 @@ import {
import { ref } from '@nuxtjs/composition-api'
-import VContentSwitcherPopover from '~/components/VContentSwitcher/VContentSwitcherPopover.vue'
+import VSearchTypePopover from '~/components/VContentSwitcher/VSearchTypePopover.vue'
<Meta
- title="Components/VContentSwitcherPopover"
- components={VContentSwitcherPopover}
+ title="Components/VSearchTypePopover"
+ components={VSearchTypePopover}
argTypes={{
select: {
action: 'select',
@@ -21,16 +21,16 @@ import VContentSwitcherPopover from '~/components/VContentSwitcher/VContentSwitc
/>
export const Template = (args, { argTypes }) => ({
- template: `<VContentSwitcherPopover active-item="image" v-bind="$props" v-on="$props"/>`,
- components: { VContentSwitcherPopover },
+ template: `<VSearchTypePopover active-item="image" v-bind="$props" v-on="$props"/>`,
+ components: { VSearchTypePopover },
props: Object.keys(argTypes),
})
-# VContentSwitcherPopover
+# VSearchTypePopover
-<Description of={VContentSwitcherPopover} />
+<Description of={VSearchTypePopover} />
-<ArgsTable of={VContentSwitcherPopover} />
+<ArgsTable of={VSearchTypePopover} />
<Canvas>
<Story height="480px" name="Default">
@@ -46,10 +46,10 @@ export const vModelTemplate = () => ({
template: `
<div>
{{ item }}
- <VContentSwitcherPopover v-model="item"/>
+ <VSearchTypePopover v-model="item"/>
</div>
`,
- components: { VContentSwitcherPopover },
+ components: { VSearchTypePopover },
setup() {
const item = ref('all')
return { item }
diff --git a/src/components/VFilters/VFilterChecklist.vue b/src/components/VFilters/VFilterChecklist.vue
index a6f1bab49..ec4aed661 100644
--- a/src/components/VFilters/VFilterChecklist.vue
+++ b/src/components/VFilters/VFilterChecklist.vue
@@ -71,7 +71,7 @@ export default {
computed: {
itemName() {
return this.filterType === 'searchBy'
- ? this.$t('filters.searchBy.title')
+ ? this.$t('filters.search-by.title')
: this.title
},
},
diff --git a/src/components/VHeader/VHeader.vue b/src/components/VHeader/VHeader.vue
index 1ceed1299..e0bef89f5 100644
--- a/src/components/VHeader/VHeader.vue
+++ b/src/components/VHeader/VHeader.vue
@@ -67,7 +67,7 @@ import {
FETCH_MEDIA,
UPDATE_QUERY,
} from '~/constants/action-types'
-import { AUDIO, IMAGE } from '~/constants/media'
+import { supportedMediaTypes } from '~/constants/media'
import { isMinScreen } from '~/composables/use-media-query'
import { useMatchSearchRoutes } from '~/composables/use-match-routes'
import { useFilterSidebarVisibility } from '~/composables/use-filter-sidebar-visibility'
@@ -185,7 +185,7 @@ const VHeader = defineComponent({
const searchType = store.state.search.searchType
if (searchTermChanged) {
await Promise.all(
- [IMAGE, AUDIO].map((mediaType) =>
+ supportedMediaTypes.map((mediaType) =>
store.dispatch(`${MEDIA}/${CLEAR_MEDIA}`, { mediaType })
)
)
diff --git a/src/components/VHeader/VHeaderMenu.vue b/src/components/VHeader/VHeaderMenu.vue
index 699861978..b26cf84af 100644
--- a/src/components/VHeader/VHeaderMenu.vue
+++ b/src/components/VHeader/VHeaderMenu.vue
@@ -7,13 +7,13 @@ import {
useRouter,
useStore,
} from '@nuxtjs/composition-api'
-import useContentType from '~/composables/use-content-type'
+import useSearchType from '~/composables/use-search-type'
import VMobileMenuModal from '~/components/VContentSwitcher/VMobileMenuModal.vue'
-import VContentSwitcherPopover from '~/components/VContentSwitcher/VContentSwitcherPopover.vue'
+import VSearchTypePopover from '~/components/VContentSwitcher/VSearchTypePopover.vue'
import VDesktopPageMenu from '~/components/VHeader/VPageMenu/VDesktopPageMenu.vue'
import VMobilePageMenu from '~/components/VHeader/VPageMenu/VMobilePageMenu.vue'
-import { ALL_MEDIA, AUDIO, IMAGE } from '~/constants/media'
+import { ALL_MEDIA, supportedMediaTypes } from '~/constants/media'
import { FETCH_MEDIA } from '~/constants/action-types'
import { MEDIA } from '~/constants/store-modules'
import isEmpty from 'lodash.isempty'
@@ -22,7 +22,7 @@ export default {
name: 'VHeaderMenu',
components: {
VMobileMenuModal,
- VContentSwitcherPopover,
+ VSearchTypePopover,
VDesktopPageMenu,
VMobilePageMenu,
},
@@ -37,7 +37,7 @@ export default {
const isMinScreenMd = inject('isMinScreenMd')
/** @type {import('@nuxtjs/composition-api').Ref<null|HTMLElement>} */
const menuModalRef = ref(null)
- const content = useContentType()
+ const content = useSearchType()
const { app } = useContext()
const store = useStore()
const router = useRouter()
@@ -46,7 +46,7 @@ export default {
onMounted(() => {
isMounted.value = true
})
- const selectContentType = async (type) => {
+ const selectSearchType = async (type) => {
menuModalRef.value?.closeMenu()
await content.setActiveType(type)
@@ -62,7 +62,7 @@ export default {
const shouldFetchMedia =
type === ALL_MEDIA
- ? [AUDIO, IMAGE].every((type) => typeWithoutMedia(type))
+ ? supportedMediaTypes.every((type) => typeWithoutMedia(type))
: typeWithoutMedia(type)
if (shouldFetchMedia) {
@@ -78,7 +78,7 @@ export default {
isMounted,
content,
- selectContentType,
+ selectSearchType,
}
},
render(h) {
@@ -89,10 +89,10 @@ export default {
} else if (this.isMinScreenMd && this.isMounted) {
return h('div', { class: 'flex flex-grow justify-between gap-x-2' }, [
h(VDesktopPageMenu),
- h(VContentSwitcherPopover, {
+ h(VSearchTypePopover, {
props: { activeItem: this.content.activeType.value },
ref: 'menuModalRef',
- on: { select: this.selectContentType },
+ on: { select: this.selectSearchType },
}),
])
} else {
@@ -100,7 +100,7 @@ export default {
ref: 'menuModalRef',
props: { activeItem: this.content.activeType.value },
on: {
- select: this.selectContentType,
+ select: this.selectSearchType,
},
})
}
diff --git a/src/components/VSearchGrid.vue b/src/components/VSearchGrid.vue
index a71798d4c..fa62ae017 100644
--- a/src/components/VSearchGrid.vue
+++ b/src/components/VSearchGrid.vue
@@ -27,7 +27,7 @@
<script>
import { computed } from '@nuxtjs/composition-api'
-import { supportedContentTypes } from '~/constants/media'
+import { ALL_MEDIA, IMAGE, supportedSearchTypes } from '~/constants/media'
import VMetaSearchForm from '~/components/VMetaSearch/VMetaSearchForm.vue'
@@ -44,7 +44,9 @@ export default {
required: true,
},
searchType: {
- type: String,
+ type: /** @type {import('@nuxtjs/composition-api').PropType<import('../store/types').SupportedSearchType>} */ (
+ String
+ ),
required: true,
},
fetchState: {
@@ -64,13 +66,13 @@ export default {
: false
})
const isSupported = computed(() => {
- return supportedContentTypes.includes(props.searchType)
+ return supportedSearchTypes.includes(props.searchType)
})
const metaSearchFormType = computed(() => {
- return props.searchType === 'all' ? 'image' : props.searchType
+ return props.searchType === ALL_MEDIA ? IMAGE : props.searchType
})
const isAllView = computed(() => {
- return props.searchType === 'all'
+ return props.searchType === ALL_MEDIA
})
return {
diff --git a/src/composables/use-content-type.js b/src/composables/use-search-type.js
similarity index 61%
rename from src/composables/use-content-type.js
rename to src/composables/use-search-type.js
index f8aa22c32..823a2c033 100644
--- a/src/composables/use-content-type.js
+++ b/src/composables/use-search-type.js
@@ -1,5 +1,5 @@
import { computed, ref, useContext } from '@nuxtjs/composition-api'
-import { supportedContentTypes } from '~/constants/media'
+import { supportedSearchTypes } from '~/constants/media'
import { SEARCH } from '~/constants/store-modules'
import { UPDATE_QUERY } from '~/constants/action-types'
import allIcon from '~/assets/icons/all-content.svg'
@@ -11,24 +11,24 @@ const icons = {
audio: audioIcon,
image: imageIcon,
}
-const contentTypes = [...supportedContentTypes]
+const searchTypes = [...supportedSearchTypes]
-export default function useContentType() {
+export default function useSearchType() {
const { store } = useContext()
const activeType = computed(() => store.state.search.searchType)
- const previousContentType = ref(activeType.value)
- const setActiveType = async (contentType) => {
- if (previousContentType.value === contentType) return
+ const previousSearchType = ref(activeType.value)
+ const setActiveType = async (searchType) => {
+ if (previousSearchType.value === searchType) return
await store.dispatch(`${SEARCH}/${UPDATE_QUERY}`, {
- searchType: contentType,
+ searchType,
})
- previousContentType.value = contentType
+ previousSearchType.value = searchType
}
return {
setActiveType,
activeType,
- types: contentTypes,
+ types: searchTypes,
icons,
}
}
diff --git a/src/constants/action-types.js b/src/constants/action-types.js
index 0f0782ea5..0b3ed31b1 100644
--- a/src/constants/action-types.js
+++ b/src/constants/action-types.js
@@ -5,11 +5,9 @@ export const FETCH_MEDIA = 'FETCH_MEDIA'
export const FETCH_SINGLE_MEDIA_TYPE = 'FETCH_SINGLE_MEDIA_TYPE'
export const HANDLE_MEDIA_ERROR = 'HANDLE_MEDIA_ERROR'
export const TOGGLE_FILTER = 'TOGGLE_FILTER'
-export const UPDATE_SEARCH_TYPE = 'UPDATE_SEARCH_TYPE'
export const HANDLE_NO_MEDIA = 'HANDLE_NO_MEDIA'
export const UPDATE_QUERY = 'UPDATE_QUERY'
export const UPDATE_QUERY_FROM_FILTERS = 'UPDATE_QUERY_FROM_FILTERS'
export const SET_SEARCH_STATE_FROM_URL = 'SET_SEARCH_STATE_FROM_URL'
-export const SET_MEDIA_TYPE = 'SET_MEDIA_TYPE'
export const CLEAR_MEDIA = 'CLEAR_MEDIA'
export const CLEAR_FILTERS = 'CLEAR_FILTERS'
diff --git a/src/constants/media.js b/src/constants/media.js
index 78dc7f0bd..d6fb014e5 100644
--- a/src/constants/media.js
+++ b/src/constants/media.js
@@ -3,30 +3,31 @@ export const IMAGE = 'image'
export const VIDEO = 'video'
export const ALL_MEDIA = 'all'
-/** @typedef {typeof AUDIO | typeof IMAGE | typeof VIDEO | typeof ALL_MEDIA} MediaType */
-
/**
- * Media types that the API supports.
+ * Media types that the API supports and this only includes 'real' media. ALL is a special case not used in this list.
* These types also support custom filters.
- * @type {MediaType[]}
+ * Note: images should always be first here,
+ *
*/
-export const supportedMediaTypes = [IMAGE, AUDIO]
+export const supportedMediaTypes = /** @type {const} */ ([IMAGE, AUDIO])
/**
* The types of content that users can search. `All` is also an option here.
- * @type {MediaType[]}
*/
-export const supportedContentTypes = [ALL_MEDIA, IMAGE, AUDIO]
+export const supportedSearchTypes = /** @type {const} */ ([
+ ALL_MEDIA,
+ IMAGE,
+ AUDIO,
+])
/** @typedef {'supported'|'beta'|'additional'} SupportStatus */
-/** @type {{SUPPORTED: SupportStatus, ADDITIONAL: SupportStatus, BETA: SupportStatus}}*/
-export const statuses = {
+export const statuses = /** @type {const} */ ({
SUPPORTED: 'supported',
BETA: 'beta',
ADDITIONAL: 'additional',
-}
+})
-/** @type {Object.<MediaType, SupportStatus>} */
+/** @type {Record.<import('../store/types').SearchType, SupportStatus>} */
export const contentStatus = {
[ALL_MEDIA]: statuses.SUPPORTED,
[IMAGE]: statuses.SUPPORTED,
diff --git a/src/constants/mutation-types.js b/src/constants/mutation-types.js
index a7503e3b6..7a3b679c5 100644
--- a/src/constants/mutation-types.js
+++ b/src/constants/mutation-types.js
@@ -6,7 +6,6 @@ export const FETCH_MEDIA_ERROR = 'FETCH_MEDIA_ERROR'
export const MEDIA_NOT_FOUND = 'MEDIA_NOT_FOUND'
export const FETCH_START_MEDIA = 'FETCH_START_MEDIA'
export const SET_FILTER = 'SET_FILTER'
-export const SET_FILTER_IS_VISIBLE = 'SET_FILTER_IS_VISIBLE'
export const SET_MEDIA_ITEM = 'SET_MEDIA_ITEM'
export const SET_MEDIA_PROVIDERS = 'SET_MEDIA_PROVIDERS'
export const SET_PROVIDERS_FILTERS = 'SET_PROVIDERS_FILTERS'
diff --git a/src/constants/store-modules.js b/src/constants/store-modules.js
index 5b3d05fc6..609952806 100644
--- a/src/constants/store-modules.js
+++ b/src/constants/store-modules.js
@@ -2,7 +2,6 @@ export const RELATED = 'related'
export const ACTIVE = 'active'
export const PROVIDER = 'provider'
export const NAV = 'nav'
-export const NOTIFICATION = 'notification'
export const USAGE_DATA = 'usage-data'
export const SEARCH = 'search'
export const MEDIA = 'media'
diff --git a/src/locales/en.json b/src/locales/en.json
index cb9376a2e..d7069de08 100644
--- a/src/locales/en.json
+++ b/src/locales/en.json
@@ -320,7 +320,7 @@
"title": "Image type",
"photograph": "Photographs",
"illustration": "Illustrations",
- "digitized-artwork": "Digitized Artworks"
+ "digitized_artwork": "Digitized Artworks"
},
"audio-extensions": {
"title": "File type",
@@ -360,7 +360,7 @@
"creator": {
"title": "Search by Creator"
},
- "searchBy": {
+ "search-by": {
"title": "Search By",
"creator": "Creator"
},
diff --git a/src/locales/po-files/openverse.pot b/src/locales/po-files/openverse.pot
index cc348f969..424f67669 100644
--- a/src/locales/po-files/openverse.pot
+++ b/src/locales/po-files/openverse.pot
@@ -39,7 +39,7 @@ msgctxt "search-type.video"
msgid "Videos"
msgstr ""
-#: src/components/VContentSwitcher/VContentSwitcherPopover.vue:5
+#: src/components/VContentSwitcher/VSearchTypePopover.vue:5
msgctxt "search-type.label"
msgid "Type of content to search"
msgstr ""
@@ -49,7 +49,7 @@ msgctxt "search-type.heading"
msgid "Content types"
msgstr ""
-#: src/components/VContentSwitcher/VContentItem.vue:13
+#: src/components/VContentSwitcher/VSearchTypeItem.vue:13
msgctxt "search-type.status-beta"
msgid "Beta"
msgstr ""
@@ -885,11 +885,11 @@ msgid "here"
msgstr ""
#: src/components/VFilters/VFilterChecklist.vue:74
-msgctxt "filters.searchBy.title"
+msgctxt "filters.search-by.title"
msgid "Search By"
msgstr ""
-msgctxt "filters.searchBy.creator"
+msgctxt "filters.search-by.creator"
msgid "Creator"
msgstr ""
@@ -1001,7 +1001,7 @@ msgctxt "filters.image-categories.illustration"
msgid "Illustrations"
msgstr ""
-msgctxt "filters.image-categories.digitized-artwork"
+msgctxt "filters.image-categories.digitized_artwork"
msgid "Digitized Artworks"
msgstr ""
diff --git a/src/pages/index.vue b/src/pages/index.vue
index 9bc154480..7da47b1a4 100644
--- a/src/pages/index.vue
+++ b/src/pages/index.vue
@@ -33,12 +33,12 @@
{{ $t('hero.subtitle') }}
</h2>
<div class="flex justify-start gap-4 mt-4 md:hidden">
- <VContentTypeButton
- v-for="type in supportedContentTypes"
+ <VSearchTypeRadio
+ v-for="type in supportedSearchTypes"
:key="type"
- :content-type="type"
- :selected="type === contentType"
- @select="setContentType"
+ :search-type="type"
+ :selected="type === searchType"
+ @select="setSearchType"
/>
</div>
<VSearchBar
@@ -48,13 +48,13 @@
@submit="handleSearch"
>
<ClientOnly>
- <VContentSwitcherPopover
+ <VSearchTypePopover
v-if="isMinScreenMd"
ref="contentSwitcher"
class="mx-3"
- :active-item="contentType"
+ :active-item="searchType"
placement="searchbar"
- @select="setContentType"
+ @select="setSearchType"
/>
</ClientOnly>
</VSearchBar>
@@ -131,7 +131,7 @@ import { ref, useContext, useRouter, useStore } from '@nuxtjs/composition-api'
import { isMinScreen } from '~/composables/use-media-query'
-import { ALL_MEDIA, supportedContentTypes } from '~/constants/media'
+import { ALL_MEDIA, supportedSearchTypes } from '~/constants/media'
import { MEDIA, SEARCH } from '~/constants/store-modules'
import { FETCH_MEDIA, UPDATE_QUERY } from '~/constants/action-types'
@@ -139,8 +139,8 @@ import imageInfo from '~/assets/homepage_images/image_info.json'
import OpenverseLogo from '~/assets/logo.svg?inline'
import OpenverseBrand from '~/assets/brand.svg?inline'
-import VContentSwitcherPopover from '~/components/VContentSwitcher/VContentSwitcherPopover.vue'
-import VContentTypeButton from '~/components/VContentSwitcher/VContentTypeButton.vue'
+import VSearchTypePopover from '~/components/VContentSwitcher/VSearchTypePopover.vue'
+import VSearchTypeRadio from '~/components/VContentSwitcher/VSearchTypeRadio.vue'
import VSearchBar from '~/components/VHeader/VSearchBar/VSearchBar.vue'
import VLogoButton from '~/components/VHeader/VLogoButton.vue'
import VLink from '~/components/VLink.vue'
@@ -151,8 +151,8 @@ const HomePage = {
components: {
OpenverseLogo,
OpenverseBrand,
- VContentSwitcherPopover,
- VContentTypeButton,
+ VSearchTypePopover,
+ VSearchTypeRadio,
VSearchBar,
VLink,
VLogoButton,
@@ -191,10 +191,10 @@ const HomePage = {
const isMinScreenMd = isMinScreen('md', { shouldPassInSSR: true })
const contentSwitcher = ref(null)
- const contentType = ref(ALL_MEDIA)
+ const searchType = ref(ALL_MEDIA)
- const setContentType = async (type) => {
- contentType.value = type
+ const setSearchType = async (type) => {
+ searchType.value = type
contentSwitcher.value?.closeMenu()
await store.dispatch(`${SEARCH}/${UPDATE_QUERY}`, {
searchType: type,
@@ -206,11 +206,11 @@ const HomePage = {
if (!searchTerm.value) return
await store.dispatch(`${SEARCH}/${UPDATE_QUERY}`, {
q: searchTerm.value,
- searchType: contentType.value,
+ searchType: searchType.value,
})
const newPath = app.localePath({
path: `/search/${
- contentType.value === ALL_MEDIA ? '' : contentType.value
+ searchType.value === ALL_MEDIA ? '' : searchType.value
}`,
query: store.getters['search/searchQueryParams'],
})
@@ -227,9 +227,9 @@ const HomePage = {
isMinScreenMd,
contentSwitcher,
- contentType,
- setContentType,
- supportedContentTypes,
+ searchType,
+ setSearchType,
+ supportedSearchTypes,
searchTerm,
handleSearch,
diff --git a/src/pages/search.vue b/src/pages/search.vue
index de377cbf6..c22f9decf 100644
--- a/src/pages/search.vue
+++ b/src/pages/search.vue
@@ -32,9 +32,8 @@ import {
FETCH_MEDIA,
UPDATE_QUERY,
SET_SEARCH_STATE_FROM_URL,
- UPDATE_SEARCH_TYPE,
} from '~/constants/action-types'
-import { ALL_MEDIA, supportedContentTypes } from '~/constants/media'
+import { ALL_MEDIA, supportedSearchTypes } from '~/constants/media'
import { MEDIA, SEARCH } from '~/constants/store-modules'
import { queryStringToSearchType } from '~/utils/search-query-transform'
@@ -84,7 +83,6 @@ const BrowsePage = {
...mapGetters(SEARCH, ['searchQueryParams', 'isAnyFilterApplied']),
...mapGetters(MEDIA, ['results', 'resultCount', 'fetchState']),
mediaType() {
- // Default to IMAGE until media search/index is generalized
return this.searchType ?? ALL_MEDIA
},
/**
@@ -95,14 +93,13 @@ const BrowsePage = {
return this.supported ? this.resultCount : 0 ?? 0
},
supported() {
- return supportedContentTypes.includes(this.searchType)
+ return supportedSearchTypes.includes(this.searchType)
},
},
methods: {
...mapActions(MEDIA, { fetchMedia: FETCH_MEDIA }),
...mapActions(SEARCH, {
setSearchStateFromUrl: SET_SEARCH_STATE_FROM_URL,
- updateSearchType: UPDATE_SEARCH_TYPE,
updateQuery: UPDATE_QUERY,
}),
onSearchFormSubmit({ q }) {
@@ -112,13 +109,14 @@ const BrowsePage = {
watch: {
/**
* Updates the search type only if the route's path changes.
+ * This watcher is important when changing the search type via All grid's ContentLink.
* @param newRoute
* @param oldRoute
*/
$route(newRoute, oldRoute) {
if (newRoute.path !== oldRoute.path) {
const searchType = queryStringToSearchType(newRoute.path)
- this.updateSearchType({ searchType })
+ this.updateQuery({ searchType })
}
},
},
diff --git a/src/pages/search/audio.vue b/src/pages/search/audio.vue
index 9358702e0..4a042044f 100644
--- a/src/pages/search/audio.vue
+++ b/src/pages/search/audio.vue
@@ -30,16 +30,17 @@ import {
useStore,
} from '@nuxtjs/composition-api'
import { useLoadMore } from '~/composables/use-load-more'
+import { isMinScreen } from '~/composables/use-media-query'
+import { propTypes } from './search-page.types'
import VAudioTrack from '~/components/VAudioTrack/VAudioTrack.vue'
import VLoadMore from '~/components/VLoadMore.vue'
-
-import { propTypes } from './search-page.types'
-import { isMinScreen } from '~/composables/use-media-query'
+import GridSkeleton from '~/components/Skeleton/GridSkeleton.vue'
const AudioSearch = defineComponent({
name: 'AudioSearch',
components: {
+ GridSkeleton,
VAudioTrack,
VLoadMore,
},
diff --git a/src/store/media.js b/src/store/media.js
index 56a7618eb..a3d3f112d 100644
--- a/src/store/media.js
+++ b/src/store/media.js
@@ -21,21 +21,15 @@ import {
SEND_RESULT_CLICKED_EVENT,
SEND_SEARCH_QUERY_EVENT,
} from '~/constants/usage-data-analytics-types'
-import { AUDIO, IMAGE, VIDEO, ALL_MEDIA } from '~/constants/media'
+import { AUDIO, IMAGE, ALL_MEDIA, supportedMediaTypes } from '~/constants/media'
import { USAGE_DATA } from '~/constants/store-modules'
import AudioService from '~/data/audio-service'
import ImageService from '~/data/image-service'
-// Note: images should always be first here,
-// and this only includes 'real' media. ALL is a
-// special case not used in this list.
-const supportedTypes = [IMAGE, AUDIO]
-
/**
* @return {import('./types').MediaState}
*/
export const state = () => ({
- supportedTypes,
results: {
[IMAGE]: {
count: 0,
@@ -74,7 +68,7 @@ export const createActions = (services) => ({
* @return {Promise<void>}
*/
async [FETCH_MEDIA]({ dispatch, rootState }, payload = {}) {
- const mediaType = rootState.search.query.mediaType
+ const mediaType = rootState.search.searchType
const mediaToFetch = mediaType !== ALL_MEDIA ? [mediaType] : [IMAGE, AUDIO]
await Promise.all(
@@ -83,7 +77,13 @@ export const createActions = (services) => ({
)
)
},
- // Do not use with ALL_MEDIA
+ /**
+ * Do not use with ALL_MEDIA
+ * @param {import('vuex').ActionContext} context
+ * @param {object} payload
+ * @param {import('./types').SupportedMediaType} payload.mediaType
+ * @returns {Promise<void>}
+ */
async [CLEAR_MEDIA]({ commit }, payload = {}) {
const { mediaType } = payload
commit(RESET_MEDIA, { mediaType })
@@ -92,10 +92,9 @@ export const createActions = (services) => ({
*
* @param {import('vuex').ActionContext} context
* @param {Object} payload
- * @param {mediaType} payload.mediaType - the mediaType to fetch (do not use 'All_media' here)
+ * @param {import('./types').SupportedMediaType} payload.mediaType - the mediaType to fetch (do not use 'All_media' here)
* @param {number} [payload.page] - API page to load.
- * @param {boolean} [payload.shouldPersistMedia] - whether the existing media
- * should be added to or replaced.
+ * @param {boolean} [payload.shouldPersistMedia] - whether the existing media should be added to or replaced.
* @return {Promise<void>}
*/
async [FETCH_SINGLE_MEDIA_TYPE](
@@ -192,8 +191,8 @@ export const createActions = (services) => ({
*
* @param {import('vuex').ActionContext} context
* @param {object} payload
- * @param {mediaType} payload.mediaType
- * @param payload.error
+ * @param {import('./types').SupportedMediaType} payload.mediaType
+ * @param {unknown} payload.error
* @return {Promise<void>}
*/
async [HANDLE_MEDIA_ERROR]({ commit }, { mediaType, error }) {
@@ -213,7 +212,7 @@ export const createActions = (services) => ({
*
* @param {import('vuex').ActionContext} context
* @param {number} mediaCount
- * @param {'audio'|'image'} mediaType
+ * @param {import('./types').SupportedMediaType} mediaType
*/
[HANDLE_NO_MEDIA]({ commit }, { mediaCount, mediaType }) {
if (!mediaCount) {
@@ -236,8 +235,8 @@ export const getters = {
if (getters.searchType === ALL_MEDIA) {
return { [IMAGE]: state.results[IMAGE], [AUDIO]: state.results[AUDIO] }
} else {
- return getters.mediaType
- ? { [getters.mediaType]: state.results[getters.mediaType] }
+ return getters.searchType
+ ? { [getters.searchType]: state.results[getters.searchType] }
: {}
}
},
@@ -249,7 +248,7 @@ export const getters = {
}
} else {
return {
- [getters.mediaType]: state.results[getters.mediaType].items ?? {},
+ [getters.searchType]: state.results[getters.searchType].items ?? {},
}
}
},
@@ -259,7 +258,7 @@ export const getters = {
* API returns 10 000 if there are more than 10 000 results,
* Count for all media also returns at most 10 000.
*/
- const count = supportedTypes
+ const count = supportedMediaTypes
.map((type) => state.results[type].count)
.reduce((a, b) => a + b, 0)
return count > 10000 ? 10000 : count
@@ -288,7 +287,7 @@ export const getters = {
}
} else {
return (
- state.fetchState[getters.mediaType] || {
+ state.fetchState[getters.searchType] || {
isFetching: false,
fetchError: false,
isFinished: true,
@@ -299,28 +298,13 @@ export const getters = {
searchType(state, getters, rootState) {
return rootState.search.searchType
},
- mediaType(state, getters, rootState) {
- return rootState.search.query.mediaType
- },
- /**
- * Returns true for media types that are not supported in the API: video and currently audio.
- *
- * @param state
- * @param getters
- * @param rootState
- * @returns {boolean}
- */
- unsupportedMediaType(state, getters, rootState) {
- const mediaType = rootState.search.searchType
- return mediaType === VIDEO
- },
}
export const mutations = {
/**
* Sets the fetchState for all passed mediaTypes at the beginning of fetching.
* @param _state
- * @param {MediaType} mediaTypes
+ * @param {import('./types').MediaType} mediaType
*/
[FETCH_START_MEDIA](_state, { mediaType }) {
_state.fetchState[mediaType].isFetching = true
@@ -331,7 +315,7 @@ export const mutations = {
* Sets the fetchState.isFetching to false for all passed mediaTypes at the end of fetching.
* @param _state
* @param {object} params
- * @param {MediaType} params.mediaType
+ * @param {import('./types').MediaType} params.mediaType
*/
[FETCH_END_MEDIA](_state, { mediaType }) {
_state.fetchState[mediaType].isFetching = false
@@ -374,7 +358,7 @@ export const mutations = {
/**
* Clears the items for all passed media types, and resets fetch state.
* @param _state
- * @param {MediaType} mediaTypes
+ * @param {import('./types').MediaType} mediaType
*/
[RESET_MEDIA](_state, { mediaType }) {
_state.results[mediaType].items = {}
diff --git a/src/store/search.js b/src/store/search.js
index f110333d9..4f5ed1ee1 100644
--- a/src/store/search.js
+++ b/src/store/search.js
@@ -1,7 +1,6 @@
import findIndex from 'lodash.findindex'
import clonedeep from 'lodash.clonedeep'
-import local from '~/utils/local'
import {
filtersToQueryData,
queryStringToSearchType,
@@ -11,22 +10,19 @@ import {
ALL_MEDIA,
AUDIO,
IMAGE,
- supportedContentTypes,
+ supportedSearchTypes,
VIDEO,
} from '~/constants/media'
import {
UPDATE_QUERY,
- SET_MEDIA_TYPE,
SET_SEARCH_STATE_FROM_URL,
TOGGLE_FILTER,
UPDATE_QUERY_FROM_FILTERS,
- UPDATE_SEARCH_TYPE,
CLEAR_FILTERS,
} from '~/constants/action-types'
import {
SET_FILTER,
SET_PROVIDERS_FILTERS,
- SET_FILTER_IS_VISIBLE,
CLEAR_OTHER_MEDIA_TYPE_FILTERS,
REPLACE_FILTERS,
SET_QUERY,
@@ -34,11 +30,11 @@ import {
} from '~/constants/mutation-types'
/**
- * List of filters available for each content type. The order of the keys
+ * List of filters available for each search type. The order of the keys
* is the same as in the filter checklist display (sidebar or modal).
*/
export const mediaFilterKeys = {
- image: [
+ [IMAGE]: [
'licenseTypes',
'licenses',
'imageCategories',
@@ -49,7 +45,7 @@ export const mediaFilterKeys = {
'searchBy',
'mature',
],
- audio: [
+ [AUDIO]: [
'licenseTypes',
'licenses',
'audioCategories',
@@ -59,9 +55,15 @@ export const mediaFilterKeys = {
'searchBy',
'mature',
],
- video: [],
- all: ['licenseTypes', 'licenses', 'searchBy', 'mature'],
+ [VIDEO]: [],
+ [ALL_MEDIA]: ['licenseTypes', 'licenses', 'searchBy', 'mature'],
}
+const createInitialFilters = (category, items) =>
+ items.map((item) => ({
+ code: item,
+ name: `filters.${category}.${item}`,
+ checked: false,
+ }))
/**
* A list of filters that are only used for the specific content type.
@@ -82,103 +84,54 @@ export const mediaSpecificFilters = {
/** @type {import('./types').Filters} */
export const filterData = {
- licenses: [
- { code: 'cc0', name: 'filters.licenses.cc0', checked: false },
- { code: 'pdm', name: 'filters.licenses.pdm', checked: false },
- { code: 'by', name: 'filters.licenses.by', checked: false },
- { code: 'by-sa', name: 'filters.licenses.by-sa', checked: false },
- { code: 'by-nc', name: 'filters.licenses.by-nc', checked: false },
- { code: 'by-nd', name: 'filters.licenses.by-nd', checked: false },
- { code: 'by-nc-sa', name: 'filters.licenses.by-nc-sa', checked: false },
- { code: 'by-nc-nd', name: 'filters.licenses.by-nc-nd', checked: false },
- ],
- licenseTypes: [
- {
- code: 'commercial',
- name: 'filters.license-types.commercial',
- checked: false,
- },
- {
- code: 'modification',
- name: 'filters.license-types.modification',
- checked: false,
- },
- ],
- audioCategories: [
- {
- code: 'music',
- name: 'filters.audio-categories.music',
- checked: false,
- },
- {
- code: 'soundEffects',
- name: 'filters.audio-categories.sound',
- checked: false,
- },
- {
- code: 'podcast',
- name: 'filters.audio-categories.podcast',
- checked: false,
- },
- ],
- imageCategories: [
- {
- code: 'photograph',
- name: 'filters.image-categories.photograph',
- checked: false,
- },
- {
- code: 'illustration',
- name: 'filters.image-categories.illustration',
- checked: false,
- },
- {
- code: 'digitized_artwork',
- name: 'filters.image-categories.digitized-artwork',
- checked: false,
- },
- ],
- audioExtensions: [
- { code: 'mp3', name: 'filters.audio-extensions.mp3', checked: false },
- { code: 'ogg', name: 'filters.audio-extensions.ogg', checked: false },
- { code: 'flac', name: 'filters.audio-extensions.flac', checked: false },
- ],
- imageExtensions: [
- { code: 'jpg', name: 'filters.image-extensions.jpg', checked: false },
- { code: 'png', name: 'filters.image-extensions.png', checked: false },
- { code: 'gif', name: 'filters.image-extensions.gif', checked: false },
- { code: 'svg', name: 'filters.image-extensions.svg', checked: false },
- ],
- aspectRatios: [
- { code: 'tall', name: 'filters.aspect-ratios.tall', checked: false },
- { code: 'wide', name: 'filters.aspect-ratios.wide', checked: false },
- { code: 'square', name: 'filters.aspect-ratios.square', checked: false },
- ],
- durations: [
- { code: 'short', name: 'filters.durations.short', checked: false },
- { code: 'medium', name: 'filters.durations.medium', checked: false },
- { code: 'long', name: 'filters.durations.long', checked: false },
- ],
- sizes: [
- { code: 'small', name: 'filters.sizes.small', checked: false },
- { code: 'medium', name: 'filters.sizes.medium', checked: false },
- { code: 'large', name: 'filters.sizes.large', checked: false },
- ],
+ licenses: createInitialFilters('licenses', [
+ 'cc0',
+ 'pdm',
+ 'by',
+ 'by-sa',
+ 'by-nc',
+ 'by-nd',
+ 'by-nc-sa',
+ 'by-nc-nd',
+ ]),
+ licenseTypes: createInitialFilters('license-types', [
+ 'commercial',
+ 'modification',
+ ]),
+ audioCategories: createInitialFilters('audio-categories', [
+ 'music',
+ 'sound',
+ 'podcast',
+ ]),
+ imageCategories: createInitialFilters('image-categories', [
+ 'photograph',
+ 'illustration',
+ 'digitized_artwork',
+ ]),
+ audioExtensions: createInitialFilters('audio-extensions', [
+ 'mp3',
+ 'ogg',
+ 'flac',
+ ]),
+ imageExtensions: createInitialFilters('image-extensions', [
+ 'jpg',
+ 'png',
+ 'gif',
+ 'svg',
+ ]),
+ aspectRatios: createInitialFilters('aspect-ratios', [
+ 'tall',
+ 'wide',
+ 'square',
+ ]),
+ durations: createInitialFilters('durations', ['short', 'medium', 'long']),
+ sizes: createInitialFilters('sizes', ['small', 'medium', 'large']),
audioProviders: [],
imageProviders: [],
- searchBy: [
- { code: 'creator', name: 'filters.searchBy.creator', checked: false },
- ],
+ searchBy: createInitialFilters('search-by', ['creator']),
mature: false,
}
-const searchTabToMediaType = {
- [ALL_MEDIA]: ALL_MEDIA,
- [AUDIO]: AUDIO,
- [IMAGE]: IMAGE,
- [VIDEO]: null,
-}
-
/**
* Returns true if any of the filters' checked property is true
* except for `mature` filter, as it is not displayed as a tag
@@ -197,10 +150,6 @@ const anyFilterApplied = (filters = {}) =>
})
/**
- * Search type is the media tab that is currently open in the UI. Some types
- * are not supported by the API (video), or default to a different type (all - image).
- * The media type that is actually queried is saved as `query.mediaType`, and can
- * be null for unsupported type.
* `query` has the API request parameters for search filtering. Locally, some filters
* have different names, and some query parameters correspond to different filter parameters
* depending on the media type. For example, `extension` query parameter can be `audioExtension`
@@ -210,11 +159,9 @@ const anyFilterApplied = (filters = {}) =>
*/
export const state = () => ({
filters: clonedeep(filterData),
- isFilterVisible: false,
searchType: IMAGE,
query: {
q: '',
- mediaType: IMAGE,
license: '',
license_type: '',
categories: '',
@@ -231,19 +178,16 @@ export const state = () => ({
export const getters = {
/**
* Returns the search query parameters for API request:
- * drops `mediaType` parameter, and all parameters with blank values.
+ * drops all parameters with blank values.
* @param {import('./types').SearchState} state
* @return {import('./types').ApiQueryParams}
*/
searchQueryParams: (state) => {
- const params = {}
// Ensure that q filter always comes first
- if (state.query.q.trim() !== '') {
- params.q = state.query.q.trim()
- }
- // Remove the mediaType parameter, and handle mature filter separately
+ const params = { q: state.query.q.trim() }
+ // Handle mature filter separately
const filterKeys = Object.keys(state.query).filter(
- (key) => !['q', 'mediaType', 'mature'].includes(key)
+ (key) => !['q', 'mature'].includes(key)
)
filterKeys.forEach((key) => {
if (state.query[key].length) {
@@ -265,23 +209,22 @@ export const getters = {
*/
appliedFilterTags: (state) => {
let appliedFilters = []
- if (state.query.mediaType) {
- const filterKeys = mediaFilterKeys[state.query.mediaType]
- filterKeys.forEach((filterType) => {
- if (filterType !== 'mature') {
- const newFilters = state.filters[filterType]
- .filter((f) => f.checked)
- .map((f) => {
- return {
- code: f.code,
- name: f.name,
- filterType: filterType,
- }
- })
- appliedFilters = [...appliedFilters, ...newFilters]
- }
- })
- }
+ const filterKeys = mediaFilterKeys[state.searchType]
+ filterKeys.forEach((filterType) => {
+ if (filterType !== 'mature') {
+ const newFilters = state.filters[filterType]
+ .filter((f) => f.checked)
+ .map((f) => {
+ return {
+ code: f.code,
+ name: f.name,
+ filterType: filterType,
+ }
+ })
+ appliedFilters = [...appliedFilters, ...newFilters]
+ }
+ })
+
return appliedFilters
},
/**
@@ -294,7 +237,7 @@ export const getters = {
return anyFilterApplied(
getMediaTypeFilters({
filters: state.filters,
- mediaType: state.query.mediaType,
+ mediaType: state.searchType,
})
)
},
@@ -307,7 +250,7 @@ export const getters = {
mediaFiltersForDisplay: (state) => {
return getMediaTypeFilters({
filters: state.filters,
- mediaType: state.query.mediaType,
+ mediaType: state.searchType,
includeMature: false,
})
},
@@ -315,34 +258,25 @@ export const getters = {
const actions = {
/**
- * Called when `q` search term or `searchType` (ie. the search tab in the UI)
- * are changed.
- * We avoid adding changes to `q` or `searchType` separately, because every
- * change to the state `query` object causes an API call.
+ * Called when `q` search term or `searchType` are changed.
* @param {import('vuex').ActionContext} context
* @param {import('vuex').ActionPayload} params
* @param {string} [params.q]
- * @param {('all'|'audio'|'image'|'video')} [params.searchType]
+ * @param {import('./types').SupportedSearchType} [params.searchType]
* @return {Promise<void>}
*/
async [UPDATE_QUERY]({ commit, dispatch, state }, params = {}) {
const { q, searchType } = params
- /** @type {{ q: string?, mediaType: string? }} */
+ /** @type {{ q: string? }} */
const queryParams = {}
if (q) {
queryParams.q = q.trim()
}
if (searchType && searchType !== state.searchType) {
commit(SET_SEARCH_TYPE, { searchType })
- const newMediaType = searchTabToMediaType[searchType]
- if (newMediaType !== state.query.mediaType) {
- queryParams.mediaType = newMediaType
- }
commit(CLEAR_OTHER_MEDIA_TYPE_FILTERS, { searchType })
}
- if (Object.keys(queryParams).length !== 0) {
- await dispatch(UPDATE_QUERY_FROM_FILTERS, queryParams)
- }
+ await dispatch(UPDATE_QUERY_FROM_FILTERS, queryParams)
},
/**
* Toggles a filter's checked parameter
@@ -392,8 +326,7 @@ const actions = {
{ path, query }
) {
const searchType = queryStringToSearchType(path)
- const mediaType = searchTabToMediaType[searchType]
- const queryParams = { mediaType }
+ const queryParams = {}
if (query.q) {
queryParams.q = query.q
}
@@ -403,27 +336,9 @@ const actions = {
defaultFilters: state.filters,
})
commit(REPLACE_FILTERS, { newFilterData })
- commit(SET_SEARCH_TYPE, { searchType: searchType })
+ commit(SET_SEARCH_TYPE, { searchType })
await dispatch(UPDATE_QUERY_FROM_FILTERS, queryParams)
},
-
- /**
- * On selecting a search tab, updates the search type and
- * sets the filters that are applicable for this media type.
- * @param {import('vuex').ActionContext} context
- * @param {'all'|'audio'|'image'|'video'} searchType
- */
- async [UPDATE_SEARCH_TYPE]({ commit, state }, { searchType }) {
- if (state.searchType !== searchType) {
- commit(SET_SEARCH_TYPE, { searchType })
- commit(CLEAR_OTHER_MEDIA_TYPE_FILTERS, { searchType })
-
- const newMediaType = searchTabToMediaType[searchType]
- if (state.query.mediaType !== newMediaType) {
- commit(SET_MEDIA_TYPE, { mediaType: newMediaType })
- }
- }
- },
/**
* After a change in filters, updates the query.
* @param {import('vuex').ActionContext} context
@@ -434,19 +349,17 @@ const actions = {
async [UPDATE_QUERY_FROM_FILTERS]({ state, commit }, params = {}) {
const queryFromFilters = filtersToQueryData(
state.filters,
- params.mediaType || state.query.mediaType,
+ params.mediaType || state.searchType,
false
)
const query = { ...queryFromFilters }
query.q = params?.q || state.query.q
- query.mediaType = params?.mediaType || state.query.mediaType
-
commit(SET_QUERY, { query })
},
}
function getMediaTypeFilters({ filters, mediaType, includeMature = false }) {
- if (![ALL_MEDIA, AUDIO, IMAGE, VIDEO].includes(mediaType)) {
+ if (!supportedSearchTypes.includes(mediaType)) {
mediaType = ALL_MEDIA
}
let filterKeys = mediaFilterKeys[mediaType]
@@ -465,11 +378,11 @@ const mutations = {
* After a search type is changed, unchecks all the filters that are not
* applicable for this Media type.
* @param {import('./types').SearchState} state
- * @param {'all'|'audio'|'image'|'video'} searchType
+ * @param {import('./types').SearchType} searchType
*/
[CLEAR_OTHER_MEDIA_TYPE_FILTERS](state, { searchType }) {
- const mediaTypesToClear = supportedContentTypes.filter(
- (media) => media !== searchType
+ const mediaTypesToClear = supportedSearchTypes.filter(
+ (type) => type !== searchType
)
let filterKeysToClear = []
@@ -554,38 +467,20 @@ const mutations = {
}
})
},
- [SET_FILTER_IS_VISIBLE](state, params) {
- state.isFilterVisible = params.isFilterVisible
- local.set(process.env.filterStorageKey, params.isFilterVisible)
- },
/**
- * Sets the searchType (tab in the UI).
+ * Sets the content type to search.
* @param {import('./types').SearchState} state
- * @param {'all'|'image'|'audio'|'video'} searchType
+ * @param {import('./types').SearchType} searchType
*/
[SET_SEARCH_TYPE](state, { searchType }) {
state.searchType = searchType
},
- /**
- * Sets the query mediaType: the actual media type that is used in the API call.
- * @param {import('./types').SearchState} state
- * @param {'image'|'audio'} mediaType
- */
- [SET_MEDIA_TYPE](state, { mediaType }) {
- state.query.mediaType = mediaType
- },
/**
* Replaces the query object that is used for API calls.
* @param {import('./types').SearchState} state
* @param {Object} query
*/
[SET_QUERY](state, { query }) {
- if (!query.mediaType) {
- query = {
- ...query,
- mediaType: state.query.mediaType,
- }
- }
state.query = query
},
}
diff --git a/src/store/types.d.ts b/src/store/types.d.ts
index 33636451f..34fe3a1f8 100644
--- a/src/store/types.d.ts
+++ b/src/store/types.d.ts
@@ -1,3 +1,7 @@
+export type SupportedMediaType = 'audio' | 'image'
+export type SupportedSearchType = 'all' | SupportedMediaType
+export type MediaType = 'audio' | 'image' | 'video'
+export type SearchType = 'all' | MediaType
/**
* The search result object
*/
@@ -9,7 +13,7 @@ export interface MediaResult<T> {
}
export type Query = {
- mediaType: 'audio' | 'image'
+ mediaType: SupportedMediaType
q: string
license: string
license_type: string
@@ -117,14 +121,13 @@ export interface FetchState {
}
export interface SearchState {
- isFilterVisible: boolean
- searchType: 'all' | 'audio' | 'image' | 'video'
+ searchType: SupportedSearchType
query: Query
filters: Filters
}
export interface ActiveMediaState {
- type: 'image' | 'audio' | null
+ type: SupportedMediaType | null
id: string | null
status: 'ejected' | 'playing' | 'paused' // 'ejected' means player is closed
}
@@ -133,7 +136,7 @@ export interface MediaStoreResult {
count: number
page?: number
pageCount: number
- items: AudioDetail[] | ImageDetail[]
+ items: { [key: SupportedMediaType]: AudioDetail | ImageDetail }
}
export interface MediaState {
diff --git a/src/utils/prepare-search-query-params.js b/src/utils/prepare-search-query-params.js
index 2147c1898..27e7b9b38 100644
--- a/src/utils/prepare-search-query-params.js
+++ b/src/utils/prepare-search-query-params.js
@@ -1,4 +1,4 @@
-const NON_API_PARAMS = ['mediaType', 'shouldPersistMedia']
+const NON_API_PARAMS = ['shouldPersistMedia']
export default function prepareSearchQueryParams(searchParams) {
const params = {
diff --git a/src/utils/search-query-transform.js b/src/utils/search-query-transform.js
index c43d38441..3f764781a 100644
--- a/src/utils/search-query-transform.js
+++ b/src/utils/search-query-transform.js
@@ -19,7 +19,7 @@ const filterPropertyMappings = {
mature: 'mature',
}
-const getMediaFilterTypes = (contentType) => [...mediaFilterKeys[contentType]]
+const getMediaFilterTypes = (searchType) => [...mediaFilterKeys[searchType]]
// {
// license: 'cc0,pdm,by,by-sa,by-nc,by-nd,by-nc-sa,by-nc-nd',
// imageCategories: 'photograph,illustration,digitized_artwork',
@@ -45,7 +45,7 @@ const filterToString = (filter) =>
* converts the filter store object to the data format accepted by the API,
* which has slightly different property names
* @param {object} filters object containing the filter data that comes from the filter store
- * @param {string} searchType
+ * @param {import('../store/types').SearchType} searchType
* @param hideEmpty
* @todo Refactor all of these 'reduce' calls to just use lodash methods :)
*/
@@ -81,12 +81,12 @@ export const filtersToQueryData = (
}
/**
- * Extract search type from the url. Returns the the last part
+ * Extract search type from the url. Returns the last part
* of the path between `/search/` and query, or `all` by default.
* `/search/?q=test`: all
* `/search/image?q=test`: image
* @param {string} queryString
- * @return {('all'|'audio'|'image'|'video')}
+ * @return {import('../store/types').SearchType}
*/
export const queryStringToSearchType = (queryString) => {
const searchTypePattern = /\/search\/(image|audio|video)\?*/
@@ -101,7 +101,7 @@ export const queryStringToSearchType = (queryString) => {
* `extensions` - audioExtensions/imageExtensions
* `categories` - audioCategories/imageCategories
* This function sets only filters that are possible for current
- * media type. Eg., for queryString `search/audio?extensions=ogg`
+ * media type. E.g., for queryString `search/audio?extensions=ogg`
* the `audioExtensions.ogg.checked` is set to true,
* but for `search/images?extensions=ogg`, the extensions query parameter
* is discarded, because `ogg` is not a valid extension for images.
@@ -129,9 +129,10 @@ const getMediaTypeApiFilters = (filterParameter, parameterFilters) => {
/**
* converts the browser filter query string into the internal filter store data format
- * @param {Object} query browser filter query
- * @param {'all'|'audio'|'image'|'video'} searchType
- * @param {Object} defaultFilters default filters for testing purposes
+ * @param {object} params
+ * @param {object} params.query - browser filter query
+ * @param {import('../store/types').SearchType} [params.searchType]
+ * @param {object} params.defaultFilters default filters for testing purposes
*/
export const queryToFilterData = ({
query,
diff --git a/test/e2e/content-types.spec.js b/test/e2e/content-types.spec.js
deleted file mode 100644
index e47e6ad2d..000000000
--- a/test/e2e/content-types.spec.js
+++ /dev/null
@@ -1,113 +0,0 @@
-const { test, expect } = require('@playwright/test')
-const { mockAllSearch, changeContentType } = require('./utils')
-
-/**
- * Using SSR:
- * 1. Can open 'all' content type page, and see Meta, image grid and Meta search form.
- * 2. Can open 'image' content type page, and see Meta, image grid and Meta search form.
- * 3. Can open 'audio' content type page, and see Meta, audio grid and Meta search form.
- * 4. Can open 'video' content type page, and see Meta, and Meta search form.
- *
- * On client side:
- * 1. Can open 'all' content type page, and see Meta, image grid and Meta search form; can load more images.
- * 2. Can open 'image' content type page, and see Meta, image grid and Meta search form; can load more images.
- * 3. Can open 'audio' content type page, and see Meta, audio grid and Meta search form; can not (currently) load more audios.
- * 4. Can open 'video' content type page, and see Meta, and Meta search form; can not see load more button.
- */
-
-test.beforeEach(async ({ context }) => {
- // Block any audio (jamendo.com) requests for each test in this file.
- await context.route('**.jamendo.com**', (route) => route.abort())
- await mockAllSearch(context)
-})
-
-const contentTypes = [
- {
- id: 'all',
- name: 'All content',
- url: '/search/?q=cat',
- supported: true,
- sources: 6,
- },
- {
- id: 'image',
- name: 'Images',
- url: '/search/image/?q=cat',
- supported: true,
- sources: 6,
- },
- {
- id: 'audio',
- name: 'Audio',
- url: '/search/audio/?q=cat',
- supported: false,
- sources: 3,
- },
-]
-
-for (const contentType of contentTypes) {
- test(`Can open ${contentType.name} search page on SSR`, async ({ page }) => {
- await page.goto(contentType.url)
-
- if (contentType.supported) {
- const searchResult = await page.locator('[data-testid="search-results"]')
- await expect(searchResult).toBeVisible()
- await expect(searchResult).not.toBeEmpty()
- }
-
- // Load more
- if (contentType.supported) {
- const loadMoreBtn = await page.locator(
- 'button:has-text("Load more results")'
- )
- await expect(loadMoreBtn).toHaveCount(1)
- }
-
- // MetaSearch form
- const metaSearchForm = await page.locator(
- '[data-testid="meta-search-form"]'
- )
- await expect(metaSearchForm).toHaveCount(1)
-
- const sourceButtons = await page.locator('.meta-search a')
- await expect(sourceButtons).toHaveCount(contentType.sources)
- })
- test(`Can open ${contentType.name} page client-side`, async ({ page }) => {
- // Audio is loading a lot of files, so we do not use it for the first SSR page
- const pageToOpen =
- contentType.id === 'all' ? contentTypes[1] : contentTypes[0]
- await page.goto(pageToOpen.url)
- await changeContentType(page, contentType.name)
-
- const urlParam = contentType.id === 'all' ? '' : contentType.id
- const expectedURL = `/search/${urlParam}?q=cat`
- await expect(page).toHaveURL(expectedURL)
-
- // Meta data
- if (contentType.supported) {
- const searchResult = await page.locator('[data-testid="search-results"]')
- await expect(searchResult).toBeVisible()
- await expect(searchResult).not.toBeEmpty()
- }
-
- // Load more
- if (contentType.supported) {
- const loadMoreSection = await page.locator('[data-testid="load-more"]')
- await expect(loadMoreSection).toHaveCount(1)
- const expectedText =
- contentType.id === 'audio' ? 'No more audio' : 'Load more'
- await expect(loadMoreSection).toContainText(expectedText)
- } else {
- await expect(page.locator('[data-testid="load-more"]')).toHaveCount(0)
- }
-
- // MetaSearch form
- const metaSearchForm = await page.locator(
- '[data-testid="meta-search-form"]'
- )
- await expect(metaSearchForm).toHaveCount(1)
-
- const sourceButtons = await page.locator('.meta-search a')
- await expect(sourceButtons).toHaveCount(contentType.sources)
- })
-}
diff --git a/test/e2e/search-types.spec.js b/test/e2e/search-types.spec.js
new file mode 100644
index 000000000..63b7972b9
--- /dev/null
+++ b/test/e2e/search-types.spec.js
@@ -0,0 +1,119 @@
+const { test, expect } = require('@playwright/test')
+const { mockAllSearch, changeContentType } = require('./utils')
+
+/**
+ * Using SSR:
+ * 1. Can open 'all content' search page, and see search results.
+ * 2. Can open 'image' search page, and see search results.
+ * 3. Can open 'audio' content type page, and see search results.
+ *
+ * On client side:
+ * 1. Can open 'all content' search page, and see search results.
+ * 2. Can open 'image' search page, and see search results.
+ * 3. Can open 'audio' search page, and see search results.
+ * 4. Can open 'image' search page from the 'all content' page.
+ * 5. Can open 'audio' search from the 'all content' page.
+ *
+ * Results include search meta information, media grid and Meta search form, can load more media if there are more media items.
+ */
+
+test.beforeEach(async ({ context }) => {
+ // Block any audio (jamendo.com) requests for each test in this file.
+ await context.route('**.jamendo.com**', (route) => route.abort())
+ await mockAllSearch(context)
+})
+
+const searchTypes = [
+ {
+ id: 'all',
+ name: 'All content',
+ url: '/search?q=cat',
+ supported: true,
+ sources: 6,
+ },
+ {
+ id: 'image',
+ name: 'Images',
+ url: '/search/image?q=cat',
+ supported: true,
+ sources: 6,
+ results: /Over 10,000 results/,
+ },
+ {
+ id: 'audio',
+ name: 'Audio',
+ url: '/search/audio?q=cat',
+ supported: true,
+ sources: 3,
+ results: /13 results/,
+ },
+]
+
+async function checkLoadMore(page, searchType) {
+ const loadMoreSection = await page.locator('[data-testid="load-more"]')
+ if (!searchType.supported || searchType.id === 'audio') {
+ await expect(loadMoreSection).toHaveCount(0)
+ } else {
+ await expect(loadMoreSection).toHaveCount(1)
+ await expect(loadMoreSection).toContainText('Load more')
+ }
+}
+async function checkMetasearchForm(page, searchType) {
+ const metaSearchForm = await page.locator('[data-testid="meta-search-form"]')
+ await expect(metaSearchForm).toHaveCount(1)
+
+ const sourceButtons = await page.locator('.meta-search a')
+ await expect(sourceButtons).toHaveCount(searchType.sources)
+}
+
+async function checkSearchMetadata(page, searchType) {
+ if (searchType.supported) {
+ const searchResult = await page.locator('[data-testid="search-results"]')
+ await expect(searchResult).toBeVisible()
+ await expect(searchResult).not.toBeEmpty()
+ }
+}
+
+async function checkSearchResult(page, searchType) {
+ await checkSearchMetadata(page, searchType)
+ await checkLoadMore(page, searchType)
+ await checkMetasearchForm(page, searchType)
+}
+
+for (const searchType of searchTypes) {
+ test(`Can open ${searchType.name} search page on SSR`, async ({ page }) => {
+ await page.goto(searchType.url)
+
+ await checkSearchResult(page, searchType)
+ })
+
+ test(`Can open ${searchType.name} page client-side`, async ({ page }) => {
+ // Audio is loading a lot of files, so we do not use it for the first SSR page
+ const pageToOpen = searchType.id === 'all' ? searchTypes[1] : searchTypes[0]
+ await page.goto(pageToOpen.url)
+ await changeContentType(page, searchType.name)
+
+ const urlParam = searchType.id === 'all' ? '' : searchType.id
+ const expectedURL = `/search/${urlParam}?q=cat`
+ await expect(page).toHaveURL(expectedURL)
+
+ await checkSearchResult(page, searchType)
+ })
+}
+
+for (let searchTypeName of ['audio', 'image']) {
+ const searchType = searchTypes.find((type) => type.id === searchTypeName)
+ test(`Can open ${searchTypeName} page from the all view`, async ({
+ page,
+ }) => {
+ await page.goto('/search/?q=cat')
+ const contentLink = await page.locator(
+ `a[href*="/search/${searchTypeName}"][href$="q=cat"]`
+ )
+ await expect(contentLink).toContainText(searchType.results)
+ await page.click(`a[href*="/search/${searchTypeName}"][href$="q=cat"]`)
+
+ await expect(page).toHaveURL(searchType.url)
+ await checkSearchResult(page, searchType)
+ })
+}
diff --git a/test/unit/specs/components/search-grid-filter.spec.js b/test/unit/specs/components/search-grid-filter.spec.js
index f3747f297..e773489dd 100644
--- a/test/unit/specs/components/search-grid-filter.spec.js
+++ b/test/unit/specs/components/search-grid-filter.spec.js
@@ -50,10 +50,7 @@ describe('SearchGridFilter', () => {
searchType: IMAGE,
isFilterVisible: true,
filters,
- query: {
- q: '',
- mediaType: IMAGE,
- },
+ query: { q: '' },
},
mutations: store.mutations,
actions: store.actions,
diff --git a/test/unit/specs/components/search-grid.spec.js b/test/unit/specs/components/search-grid.spec.js
index 72cdbbf83..acb4744a3 100644
--- a/test/unit/specs/components/search-grid.spec.js
+++ b/test/unit/specs/components/search-grid.spec.js
@@ -25,7 +25,7 @@ describe('VSearchGrid', () => {
search: {
namespaced: true,
state: {
- query: { q: 'foo', mediaType: IMAGE },
+ query: { q: 'foo' },
filters: {
licenseTypes: [
{ code: 'commercial', name: 'Commercial usage' },
@@ -91,8 +91,8 @@ describe('VSearchGrid', () => {
},
propsData: {
supported: true,
- query: { q: 'foo', mediaType: IMAGE },
- searchType: 'image',
+ query: { q: 'foo' },
+ searchType: IMAGE,
fetchState: {
isFetching: false,
isFinished: true,
diff --git a/test/unit/specs/pages/browse-page.spec.js b/test/unit/specs/pages/browse-page.spec.js
index 7dfb3b897..07510c5ca 100644
--- a/test/unit/specs/pages/browse-page.spec.js
+++ b/test/unit/specs/pages/browse-page.spec.js
@@ -16,7 +16,7 @@ describe('SearchIndex', () => {
search: {
namespaced: true,
state: {
- query: { q: 'foo', mediaType: 'image' },
+ query: { q: 'foo' },
searchType: 'image',
},
getters: {
diff --git a/test/unit/specs/store/media-store.spec.js b/test/unit/specs/store/media-store.spec.js
index 00a907071..7b316038d 100644
--- a/test/unit/specs/store/media-store.spec.js
+++ b/test/unit/specs/store/media-store.spec.js
@@ -233,10 +233,10 @@ describe('Search Store', () => {
dispatch: jest.fn(),
rootState: {
user: { usageSessionId: 'foo' },
- search: { query: { q: 'cat', mediaType: IMAGE } },
+ search: { query: { q: 'cat' } },
},
rootGetters: {
- search: { searchQueryParams: () => ({ q: 'cat', mediaType: IMAGE }) },
+ search: { searchQueryParams: () => ({ q: 'cat' }) },
},
state: state,
}
diff --git a/test/unit/specs/store/search-store.spec.js b/test/unit/specs/store/search-store.spec.js
index dab916247..60fb71f9d 100644
--- a/test/unit/specs/store/search-store.spec.js
+++ b/test/unit/specs/store/search-store.spec.js
@@ -4,15 +4,12 @@ import {
SET_SEARCH_STATE_FROM_URL,
TOGGLE_FILTER,
UPDATE_QUERY_FROM_FILTERS,
- UPDATE_SEARCH_TYPE,
} from '~/constants/action-types'
import {
SET_FILTER,
SET_PROVIDERS_FILTERS,
- SET_FILTER_IS_VISIBLE,
REPLACE_FILTERS,
SET_SEARCH_TYPE,
- CLEAR_OTHER_MEDIA_TYPE_FILTERS,
SET_QUERY,
} from '~/constants/mutation-types'
import { ALL_MEDIA, AUDIO, IMAGE } from '~/constants/media'
@@ -24,23 +21,6 @@ describe('Filter Store', () => {
expect(defaultState.filters).toEqual(filterData)
})
-
- it('state has filter hidden', () => {
- const defaultState = store.state()
-
- expect(defaultState.isFilterVisible).toBeFalsy()
- })
-
- it('isFilterVisible should be false when innerWidth property is undefined', () => {
- window.innerWidth = undefined
- const state = store.state()
- expect(state.isFilterVisible).toBeFalsy()
- })
- it('isFilterVisible should be false when window width is less then 800', () => {
- window.innerWidth = 500
- const state = store.state()
- expect(state.isFilterVisible).toBeFalsy()
- })
})
describe('mutations', () => {
@@ -137,13 +117,6 @@ describe('Filter Store', () => {
{ code: 'flickr', name: 'Flickr', checked: false },
])
})
-
- it('SET_FILTER_IS_VISIBLE updates state', () => {
- const params = { isFilterVisible: 'bar' }
- mutations[SET_FILTER_IS_VISIBLE](state, params)
-
- expect(state.isFilterVisible).toBe(params.isFilterVisible)
- })
})
describe('actions', () => {
@@ -166,14 +139,14 @@ describe('Filter Store', () => {
}
})
- xit.each`
- searchType | path | mediaType
- ${'all'} | ${'/search/'} | ${'image'}
- ${'image'} | ${'/search/image/'} | ${'image'}
- ${'audio'} | ${'/search/audio/'} | ${'audio'}
- ${'video'} | ${'/search/video'} | ${null}
+ it.each`
+ searchType | path
+ ${'all'} | ${'/search/'}
+ ${'image'} | ${'/search/image/'}
+ ${'audio'} | ${'/search/audio/'}
+ ${'video'} | ${'/search/video'}
`(
- "SET_SEARCH_STATE_FROM_URL should set searchType '$searchType' and mediaType '$mediaType' from path '$path'",
+ "SET_SEARCH_STATE_FROM_URL should set searchType '$searchType' from path '$path'",
({ searchType, path, mediaType }) => {
actions[SET_SEARCH_STATE_FROM_URL](
{ commit: commitMock, dispatch: dispatchMock, state },
@@ -188,63 +161,26 @@ describe('Filter Store', () => {
}
)
- xit.each`
- query | path | mediaType
- ${{ license: 'cc0,by' }} | ${'/search/'} | ${'image'}
- ${{ searchBy: 'creator' }} | ${'/search/image/'} | ${'image'}
- ${{ mature: 'true' }} | ${'/search/audio/'} | ${'audio'}
- ${{ durations: 'medium' }} | ${'/search/image'} | ${'image'}
+ it.each`
+ query | path | searchType
+ ${{ license: 'cc0,by' }} | ${'/search/'} | ${ALL_MEDIA}
+ ${{ searchBy: 'creator' }} | ${'/search/image/'} | ${IMAGE}
+ ${{ mature: 'true' }} | ${'/search/audio/'} | ${AUDIO}
+ ${{ durations: 'medium' }} | ${'/search/image'} | ${IMAGE}
`(
- "SET_SEARCH_STATE_FROM_URL should set query '$searchType' from query '$path'",
- ({ path, query, mediaType }) => {
+ "SET_SEARCH_STATE_FROM_URL should set '$searchType' from query '$path'",
+ ({ query, path, searchType }) => {
actions[SET_SEARCH_STATE_FROM_URL](
{ commit: commitMock, dispatch: dispatchMock, state },
{ path: path, query: query }
)
- expect(dispatchMock).toHaveBeenCalledWith(UPDATE_QUERY_FROM_FILTERS, {
- mediaType,
+ expect(dispatchMock).toHaveBeenCalledWith(UPDATE_QUERY_FROM_FILTERS, {})
+ expect(context.commit).toHaveBeenLastCalledWith(SET_SEARCH_TYPE, {
+ searchType,
})
}
)
- it('SET_SEARCH_STATE_FROM_URL sets search type to image', () => {
- const path = '/search/image'
- const query = { q: 'cat', source: 'met' }
- actions[SET_SEARCH_STATE_FROM_URL](context, { path, query })
-
- expect(context.commit).toHaveBeenLastCalledWith(SET_SEARCH_TYPE, {
- searchType: IMAGE,
- })
- })
-
- it('SET_SEARCH_STATE_FROM_URL sets search type to ALL_MEDIA if URL param is not set', () => {
- const action = actions[SET_SEARCH_STATE_FROM_URL]
-
- action(context, {
- path: '/search/',
- query: { q: 'cat', source: 'met' },
- })
- const searchType = ALL_MEDIA
- expect(context.commit).toHaveBeenLastCalledWith(SET_SEARCH_TYPE, {
- searchType,
- })
- })
-
- it('UPDATE_SEARCH_TYPE sets search type to ALL_MEDIA if URL param is not set', () => {
- const action = actions[UPDATE_SEARCH_TYPE]
-
- action(context, { searchType: ALL_MEDIA })
- expect(context.commit).toHaveBeenCalledWith(SET_SEARCH_TYPE, {
- searchType: ALL_MEDIA,
- })
- expect(context.commit).toHaveBeenCalledWith(
- CLEAR_OTHER_MEDIA_TYPE_FILTERS,
- {
- searchType: 'all',
- }
- )
- })
-
it('CLEAR_FILTERS resets filters to initial state', async () => {
state.filters.licenses = [
{ code: 'by', checked: true },
diff --git a/test/unit/specs/utils/search-query-transform.spec.js b/test/unit/specs/utils/search-query-transform.spec.js
index d8f216147..1da5209d3 100644
--- a/test/unit/specs/utils/search-query-transform.spec.js
+++ b/test/unit/specs/utils/search-query-transform.spec.js
@@ -5,7 +5,7 @@ import {
queryStringToQueryData,
} from '~/utils/search-query-transform'
import { filterData } from '~/store/search'
-import { IMAGE } from '~/constants/media'
+import { AUDIO, IMAGE } from '~/constants/media'
describe('searchQueryTransform', () => {
it('converts initial filters to query data', () => {
@@ -60,7 +60,7 @@ describe('searchQueryTransform', () => {
checked: false,
},
{
- code: 'digitized_artwork',
+ code: 'digitized-artwork',
name: 'filters.image-categories.digitized-artwork',
checked: false,
},
@@ -264,7 +264,7 @@ describe('searchQueryTransform', () => {
]
const result = queryToFilterData({
query,
- searchType: 'audio',
+ searchType: AUDIO,
defaultFilters: testFilters,
})
expect(result).toEqual(filters) // toEqual checks for value equality
diff --git a/tsconfig.json b/tsconfig.json
index 33381b6ae..e5bf8bd6a 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -39,6 +39,7 @@
"src/composables/use-browser-detection.js",
"src/composables/use-media-query.js",
"src/composables/window.js",
+ "src/constants/media.js",
"src/constants/screens.js",
"src/data/api-service.js",
"src/data/usage-data-service.js",