Skip to content

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

Update banner styles (#1184)

sarayourfriend983495bb1e0e
diff --git a/.eslintrc.js b/.eslintrc.js
index d9e7c0ac4..b22e46699 100644
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -1,7 +1,7 @@
// WebStorm fix for `~` alias not working:
// https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000771544-ESLint-does-not-work-with-webpack-import-resolver-in-2017-3
process.chdir(__dirname)
-// [id.properties:has([key.name="${methodName}"])]
+
const i18nDestructureRules = ['t', 'tc', 'te', 'td', 'd', 'n'].map(
(methodName) => ({
selector: `VariableDeclarator[id.type="ObjectPattern"]:has(Property[key.name="${methodName}"])[init.callee.name="useI18n"]`,
diff --git a/src/components/VDownloadButton.vue b/src/components/VDownloadButton.vue
index 20c0cacd6..5ca088670 100644
--- a/src/components/VDownloadButton.vue
+++ b/src/components/VDownloadButton.vue
@@ -91,7 +91,7 @@ export default {
},
data() {
const savedFormatExtension =
- local.get(LS_DOWNLOAD_FORMAT_EXTENSION_KEY) ?? null
+ local.getItem(LS_DOWNLOAD_FORMAT_EXTENSION_KEY) ?? null
let format = this.formats[0]
if (savedFormatExtension) {
const found = this.formats.find(
@@ -132,7 +132,7 @@ export default {
return filesize(size, { locale: this.$i18n.locale })
},
setSelectedFormat(format) {
- local.set(LS_DOWNLOAD_FORMAT_EXTENSION_KEY, format.extension_name)
+ local.setItem(LS_DOWNLOAD_FORMAT_EXTENSION_KEY, format.extension_name)
this.selectedFormat = format
},
},
diff --git a/src/components/VIconButton/VIconButton.vue b/src/components/VIconButton/VIconButton.vue
index 98e470366..85dec77ec 100644
--- a/src/components/VIconButton/VIconButton.vue
+++ b/src/components/VIconButton/VIconButton.vue
@@ -2,8 +2,8 @@
<VButton
v-bind="buttonProps"
size="disabled"
- class="icon-button flex flex-shrink-0 items-center justify-center border-1.5 active:shadow-ring"
- :class="[...buttonSizeClasses]"
+ class="icon-button flex flex-shrink-0 items-center justify-center active:shadow-ring border-1.5"
+ :class="buttonSizeClasses"
:type="type"
v-on="$listeners"
>
diff --git a/src/components/VMigrationNotice.vue b/src/components/VMigrationNotice.vue
index 376370239..fbcfea5b2 100644
--- a/src/components/VMigrationNotice.vue
+++ b/src/components/VMigrationNotice.vue
@@ -1,5 +1,9 @@
<template>
- <VNoticeBar class="cc-ov-migration">
+ <VNotificationBanner
+ id="cc-referral"
+ :enabled="isReferredFromCc"
+ variant="announcement"
+ >
{{
$t('migration-notice.intro', {
'cc-search': 'CC Search',
@@ -10,21 +14,30 @@
<i18n tag="span" path="migration-notice.more">
<template #read-more>
<VLink
- class="text-dark-blue hover:text-dark-blue underline"
+ class="text-white font-bold underline"
href="https://wordpress.org/news/2021/05/welcome-to-openverse/"
>{{ $t('migration-notice.read') }}</VLink
>
</template>
</i18n>
- </VNoticeBar>
+ </VNotificationBanner>
</template>
-<script>
-import VNoticeBar from '~/components/VNoticeBar/VNoticeBar.vue'
+<script lang="ts">
+import { defineComponent, computed } from '@nuxtjs/composition-api'
+
+import { useNavigationStore } from '~/stores/navigation'
+
+import VNotificationBanner from '~/components/VNotificationBanner.vue'
import VLink from '~/components/VLink.vue'
-export default {
+export default defineComponent({
name: 'VMigrationNotice',
- components: { VLink, VNoticeBar },
-}
+ components: { VLink, VNotificationBanner },
+ setup() {
+ const navigationStore = useNavigationStore()
+ const isReferredFromCc = computed(() => navigationStore.isReferredFromCc)
+ return { isReferredFromCc }
+ },
+})
</script>
diff --git a/src/components/VNotificationBanner.vue b/src/components/VNotificationBanner.vue
index 42ba6749e..4d9acf589 100644
--- a/src/components/VNotificationBanner.vue
+++ b/src/components/VNotificationBanner.vue
@@ -1,49 +1,88 @@
<template>
<div
- class="wrapper px-4 md:px-7 py-2 md:flex md:items-center md:justify-between"
- dir="ltr"
+ v-show="enabled && shouldShow"
+ class="px-4 md:px-7 py-2 flex items-center justify-between"
+ :class="$style[variant]"
+ :data-testid="`banner-${id}`"
>
- <p class="text-center md:text-left">
+ <p class="text-left">
<slot name="default" />
</p>
<div class="flex">
<slot name="buttons">
- <button
- class="button is-text small dismiss-button"
- type="button"
- :aria-label="$t('modal.close')"
- @click="$emit('close')"
- >
- <VIcon :icon-path="closeIcon" />
- </button>
+ <VIconButton
+ :class="variant === 'announcement' && 'text-white'"
+ class="border-none"
+ :button-props="{ variant: 'plain' }"
+ size="small"
+ :aria-label="closeLabel"
+ :icon-props="{
+ iconPath: closeIcon,
+ }"
+ @click="handleClose"
+ />
</slot>
</div>
</div>
</template>
-<script>
-import { defineComponent } from '@nuxtjs/composition-api'
+<script lang="ts">
+import { defineComponent, PropType } from '@nuxtjs/composition-api'
-import VIcon from '~/components/VIcon/VIcon.vue'
+import { useI18n } from '~/composables/use-i18n'
+import { useStorage } from '~/composables/use-storage'
+
+import VIconButton from '~/components/VIconButton/VIconButton.vue'
import closeIcon from '~/assets/icons/close.svg'
-const VNotificationBanner = defineComponent({
+export default defineComponent({
name: 'VNotificationBanner',
components: {
- VIcon,
+ VIconButton,
+ },
+ props: {
+ variant: {
+ type: String as PropType<'announcement' | 'informational'>,
+ required: true,
+ },
+ id: {
+ type: String,
+ required: true,
+ },
+ enabled: {
+ type: Boolean,
+ required: true,
+ },
},
- setup() {
- return { closeIcon }
+ emits: ['close'],
+ setup(props, { emit }) {
+ const i18n = useI18n()
+ const shouldShow = useStorage(`banner:show-${props.id}`, true)
+ const dismissBanner = () => (shouldShow.value = false)
+ const handleClose = () => {
+ dismissBanner()
+ emit('close')
+ }
+ const closeLabel = i18n.t('modal.close') as string
+ return {
+ closeIcon,
+ closeLabel,
+ handleClose,
+ shouldShow,
+ }
},
})
-export default VNotificationBanner
</script>
-<style scoped>
-/** Styles from learn.wordpress.org **/
-.wrapper {
+<style module>
+/* Styles from learn.wordpress.org */
+.informational {
background-color: #fff8e5;
border-left: 0.25rem solid #ffb900;
}
+
+.announcement {
+ @apply bg-trans-blue text-white;
+}
</style>
diff --git a/src/components/VTranslationStatusBanner.vue b/src/components/VTranslationStatusBanner.vue
index 6244621f5..feefde096 100644
--- a/src/components/VTranslationStatusBanner.vue
+++ b/src/components/VTranslationStatusBanner.vue
@@ -1,5 +1,9 @@
<template>
- <VNotificationBanner v-show="!shouldHideBanner" @close="dismissBanner">
+ <VNotificationBanner
+ :id="bannerKey"
+ :enabled="needsTranslationBanner"
+ variant="informational"
+ >
{{
// eslint-disable-next-line @intlify/vue-i18n/no-raw-text
'⚠️'
@@ -11,33 +15,37 @@
}}</VLink>
</template>
<template #locale>
- {{ bannerLocale.name }}
+ {{ name }}
</template>
</i18n>
</VNotificationBanner>
</template>
-<script>
-import useI18nSync from '~/composables/use-i18n-sync'
+
+<script lang="ts">
+import { computed, defineComponent } from '@nuxtjs/composition-api'
+
+import { useI18nSync } from '~/composables/use-i18n-sync'
import VLink from '~/components/VLink.vue'
import VNotificationBanner from '~/components/VNotificationBanner.vue'
-export default {
+export default defineComponent({
name: 'VTranslationStatusBanner',
components: {
VLink,
VNotificationBanner,
},
setup() {
- const { shouldHideBanner, bannerLocale, translationLink, dismissBanner } =
+ const { currentLocale, translationLink, needsTranslationBanner } =
useI18nSync()
-
+ const bannerKey = `translation-${currentLocale.value?.code ?? 'en'}`
+ const name = computed(() => currentLocale.value?.name ?? '')
return {
- dismissBanner,
- shouldHideBanner,
- bannerLocale,
+ needsTranslationBanner,
+ bannerKey,
+ name,
translationLink,
}
},
-}
+})
</script>
diff --git a/src/composables/use-event-listener.js b/src/composables/use-event-listener.js
deleted file mode 100644
index 9e7b6a1d7..000000000
--- a/src/composables/use-event-listener.js
+++ /dev/null
@@ -1,41 +0,0 @@
-import {
- isRef,
- watch,
- onMounted,
- onBeforeUnmount,
- unref,
-} from '@nuxtjs/composition-api'
-
-/**
- * Use an event listener. Shamelessly stolen from https://logaretm.com/blog/my-favorite-5-vuejs-composables/#useeventlistener
- *
- * @param {import('./types').MaybeRef<EventTarget | null> | EventTarget} target The target can be a reactive ref which adds flexibility
- * @param {string} event
- * @param {(e: Event) => void} handler
- * @param {any} options
- */
-export function useEventListener(target, event, handler, options = {}) {
- // if it's a reactive ref, use a watcher
- if (isRef(target)) {
- watch(target, (value, oldValue) => {
- const previous = oldValue?.$el ? oldValue.$el : oldValue
- const current = value?.$el ? value.$el : value
- previous?.removeEventListener(event, handler)
- current?.addEventListener(event, handler, options)
- })
- } else {
- // otherwise, use the mounted hook
- onMounted(() => {
- target.addEventListener(event, handler, options)
- })
- }
- // clean it up
- onBeforeUnmount(() => {
- const unreffed = unref(target)
- if (unreffed.$el) {
- unreffed.$el.removeEventListener(event, handler)
- } else {
- unreffed.removeEventListener(event, handler)
- }
- })
-}
diff --git a/src/composables/use-event-listener.ts b/src/composables/use-event-listener.ts
new file mode 100644
index 000000000..0cb76bb55
--- /dev/null
+++ b/src/composables/use-event-listener.ts
@@ -0,0 +1,52 @@
+import {
+ isRef,
+ watch,
+ onMounted,
+ onBeforeUnmount,
+ unref,
+ Ref,
+} from '@nuxtjs/composition-api'
+
+const isComponentInstance = (o: unknown): o is { $el: unknown } =>
+ !!o && typeof (o as { $el: unknown }).$el !== 'undefined'
+
+export type MaybeRef<T> = Ref<T> | T
+
+/**
+ * Use an event listener.
+ *
+ * @see https://logaretm.com/blog/my-favorite-5-vuejs-composables/#useeventlistener
+ */
+export function useEventListener<T extends EventTarget>(
+ target: MaybeRef<T | { $el: T }>,
+ event: Parameters<T['addEventListener']>[0],
+ handler: Parameters<T['addEventListener']>[1],
+ options = {}
+) {
+ // if it's a reactive ref, use a watcher
+ if (isRef(target)) {
+ watch(target, (value, oldValue) => {
+ const previous = isComponentInstance(oldValue) ? oldValue.$el : oldValue
+ const current = isComponentInstance(value) ? value.$el : value
+ previous?.removeEventListener(event, handler)
+ current?.addEventListener(event, handler, options)
+ })
+ } else {
+ // otherwise, use the mounted hook
+ onMounted(() => {
+ ;(isComponentInstance(target) ? target.$el : target).addEventListener(
+ event,
+ handler,
+ options
+ )
+ })
+ }
+ // clean it up
+ onBeforeUnmount(() => {
+ const unreffed = unref(target)
+ ;(isComponentInstance(unreffed)
+ ? unreffed.$el
+ : unreffed
+ ).removeEventListener(event, handler)
+ })
+}
diff --git a/src/composables/use-filter-sidebar-visibility.js b/src/composables/use-filter-sidebar-visibility.js
index 4217d955f..3b2d41077 100644
--- a/src/composables/use-filter-sidebar-visibility.js
+++ b/src/composables/use-filter-sidebar-visibility.js
@@ -28,12 +28,12 @@ export function useFilterSidebarVisibility({ mediaQuery } = {}) {
*/
const setVisibility = (val) => {
isVisible.value = val
- local.set(process.env.filterStorageKey, val)
+ local.setItem(process.env.filterStorageKey, val)
}
onMounted(() => {
const localFilterState = () =>
- local.get(process.env.filterStorageKey) === 'true'
+ local.getItem(process.env.filterStorageKey) === 'true'
setVisibility(mediaQuery.value && localFilterState())
})
diff --git a/src/composables/use-i18n-sync.js b/src/composables/use-i18n-sync.js
deleted file mode 100644
index 938a4a019..000000000
--- a/src/composables/use-i18n-sync.js
+++ /dev/null
@@ -1,64 +0,0 @@
-import { computed, reactive, useContext } from '@nuxtjs/composition-api'
-
-import { StorageSerializers, useStorage } from '~/composables/use-storage'
-
-const BASE_URL = 'https://translate.wordpress.org/projects/meta/openverse/'
-
-export default function useI18nSync() {
- const { app } = useContext()
-
- const currentLocale = computed(() => {
- return app.i18n.locales.find((item) => item.code === app.i18n.locale)
- })
-
- const bannerLocale = reactive({
- code: app.i18n.locale,
- name: currentLocale.value.name,
- })
-
- /**
- * Show banner inviting to contribute translations if fewer than 90%
- * of strings are translated for current locale.
- * Hard-coded to false for default locales: `en` and `en_US`.
- *
- * @param {string} localeCode - the slug for the current locale. This is the same as the locale `code`.
- * @returns {boolean}
- */
- const needsTranslationBanner = (localeCode) => {
- if (['en'].includes(localeCode)) return false
-
- let locale = app.i18n.locales.find((item) => item.code === localeCode)
-
- return !(locale?.translated && locale.translated > 90)
- }
-
- const bannerDismissedForLocales = useStorage(
- 'openverse-dismissed-banner-locales',
- [],
- {
- serializer: StorageSerializers.object,
- }
- )
- const shouldHideBanner = computed(() => {
- return (
- bannerDismissedForLocales.value.includes(bannerLocale.code) ||
- !needsTranslationBanner(bannerLocale.code)
- )
- })
- const dismissBanner = () => {
- bannerDismissedForLocales.value = [
- ...bannerDismissedForLocales.value,
- bannerLocale.code,
- ]
- }
- const translationLink = computed(
- () => `${BASE_URL}${bannerLocale.code}/default/`
- )
-
- return {
- shouldHideBanner,
- dismissBanner,
- bannerLocale,
- translationLink,
- }
-}
diff --git a/src/composables/use-storage.js b/src/composables/use-storage.js
deleted file mode 100644
index 0ddc20431..000000000
--- a/src/composables/use-storage.js
+++ /dev/null
@@ -1,125 +0,0 @@
-import { ref, unref, watch } from '@nuxtjs/composition-api'
-
-import { useEventListener } from '~/composables/use-event-listener'
-
-const defaultWindow =
- typeof window === 'undefined' || !('localStorage' in window)
- ? undefined
- : window
-
-/** @typedef {{read: (function(string): T), write: (function(T): string)}} Serializer<T> */
-
-export const StorageSerializers = {
- boolean: {
- read: (v) => v === 'true',
- write: (v) => String(v),
- },
- any: {
- read: (v) => v,
- write: (v) => String(v),
- },
- string: {
- read: (v) => v,
- write: (v) => String(v),
- },
- object: {
- read: (v) => JSON.parse(v),
- write: (v) => JSON.stringify(v),
- },
-}
-
-/**
- * Merges the options with the result of getDefaults.
- * If an error occurs during this process, it will return `null`
- * @template T
- * @param {T} options
- * @param {() => T} getDefaults
- * @returns {T | null}
- */
-const useSafeDefaultOptions = (options, getDefaults) => {
- try {
- return {
- ...getDefaults(),
- ...options,
- }
- } catch (e) {
- console.error(e)
- return null
- }
-}
-
-/**
- * Reactive LocalStorage.
- *
- * @see https://vueuse.org/useStorage
- * @param {string} key
- * @param {MaybeRef<T>} initialValue
- * @param options
- */
-export function useStorage(key, initialValue, options = {}) {
- const optionsWithDefaults = useSafeDefaultOptions(options, () => ({
- listenToStorageChanges: true,
- writeDefaults: true,
- window: defaultWindow,
- storage: defaultWindow?.localStorage,
- onError: (e) => {
- console.error(e)
- },
- }))
-
- if (optionsWithDefaults === null) {
- return ref(initialValue)
- }
-
- const { listenToStorageChanges, writeDefaults, window, storage, onError } =
- optionsWithDefaults
-
- const rawInit = unref(initialValue)
-
- const type =
- rawInit == null
- ? 'any'
- : typeof rawInit === 'boolean'
- ? 'boolean'
- : typeof rawInit === 'string'
- ? 'string'
- : 'any'
-
- const data = ref(initialValue)
- const serializer = options.serializer ?? StorageSerializers[type]
-
- function read(event) {
- if (!storage || (event && event.key !== key)) return
-
- try {
- const rawValue = event ? event.newValue : storage.getItem(key)
- if (rawValue == null) {
- data.value = rawInit
- if (writeDefaults && rawInit !== null)
- storage.setItem(key, serializer.write(rawInit))
- } else {
- data.value = serializer.read(rawValue)
- }
- } catch (e) {
- onError(e)
- }
- }
-
- read()
-
- if (window && listenToStorageChanges)
- useEventListener(window, 'storage', (e) => setTimeout(() => read(e), 0))
-
- if (storage) {
- watch(data, () => {
- try {
- if (data.value == null) storage.removeItem(key)
- else storage.setItem(key, serializer.write(data.value))
- } catch (e) {
- onError(e)
- }
- })
- }
-
- return data
-}
diff --git a/src/composables/use-storage.ts b/src/composables/use-storage.ts
new file mode 100644
index 000000000..e08522215
--- /dev/null
+++ b/src/composables/use-storage.ts
@@ -0,0 +1,125 @@
+import { ref, watch, Ref } from '@nuxtjs/composition-api'
+
+import local from '~/utils/local'
+
+import { useEventListener } from './use-event-listener'
+
+const defaultWindow =
+ typeof window === 'undefined' || !('localStorage' in window)
+ ? undefined
+ : window
+
+export type Serializer<T> = {
+ read(v: string): T
+ write(v: T): string
+}
+
+export const StorageSerializers = Object.freeze({
+ boolean: {
+ read: (v) => v === 'true',
+ write: (v) => String(v),
+ } as Serializer<boolean>,
+ number: {
+ read: (v) => parseFloat(v),
+ write: (v) => String(v),
+ } as Serializer<number>,
+ string: {
+ read: (v) => v,
+ write: (v) => String(v),
+ } as Serializer<string>,
+ object: {
+ read: (v) => JSON.parse(v),
+ write: (v) => JSON.stringify(v),
+ // Disable reason: We do actually mean `any` here, not unknown
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ } as Serializer<any>,
+} as const)
+
+export type UseStorageOptions<T> = {
+ listenToStorageChanges: boolean
+ writeDefaults: boolean
+ window: Window
+ storage: Storage
+ serializer: Serializer<T>
+ onError: (e: Error) => void
+}
+
+const defaultStorageOptions = Object.freeze({
+ listenToStorageChanges: true,
+ writeDefaults: true,
+ window: defaultWindow,
+ storage: local,
+ serializer: StorageSerializers.object,
+ onError: (e) => {
+ console.error(e)
+ },
+} as UseStorageOptions<unknown>)
+
+/**
+ * Reactive LocalStorage.
+ *
+ * @see https://vueuse.org/useStorage
+ */
+export function useStorage<T>(
+ key: string,
+ initialValue: T,
+ options: Partial<UseStorageOptions<T>> = {}
+): Ref<T> {
+ const optionsWithDefaults = {
+ ...defaultStorageOptions,
+ ...options,
+ }
+ const { listenToStorageChanges, writeDefaults, window, storage, onError } =
+ optionsWithDefaults
+
+ const type =
+ initialValue == null
+ ? 'object'
+ : typeof initialValue === 'boolean'
+ ? 'boolean'
+ : typeof initialValue === 'string'
+ ? 'string'
+ : typeof initialValue === 'number'
+ ? 'number'
+ : 'object'
+
+ const data = ref(initialValue) as Ref<T>
+ const serializer = options.serializer ?? StorageSerializers[type]
+
+ function read(event?: StorageEvent) {
+ if (!storage || (event && event.key !== key)) return
+
+ try {
+ const rawValue = event ? event.newValue : storage.getItem(key)
+ if (rawValue == null) {
+ data.value = initialValue as T
+ if (writeDefaults && initialValue !== null)
+ storage.setItem(key, serializer.write(initialValue))
+ } else {
+ data.value = serializer.read(rawValue) as T
+ }
+ } catch (e) {
+ onError(e as Error)
+ }
+ }
+
+ read()
+
+ if (window && listenToStorageChanges)
+ useEventListener(window, 'storage', (e: Event) =>
+ setTimeout(() => read(e as StorageEvent), 0)
+ )
+
+ if (storage) {
+ watch(data, () => {
+ try {
+ if (data.value == null) storage.removeItem(key)
+ else storage.setItem(key, serializer.write(data.value))
+ } catch (e) {
+ onError(e as Error)
+ }
+ })
+ }
+
+ return data
+}
diff --git a/src/layouts/blank.vue b/src/layouts/blank.vue
index 405c051c3..99f535e2c 100644
--- a/src/layouts/blank.vue
+++ b/src/layouts/blank.vue
@@ -1,15 +1,13 @@
<template>
<div>
- <VMigrationNotice v-show="isReferredFromCc" />
+ <VMigrationNotice />
<VTranslationStatusBanner />
<Nuxt />
</div>
</template>
<script>
-import { computed, defineComponent } from '@nuxtjs/composition-api'
-
-import { useNavigationStore } from '~/stores/navigation'
+import { defineComponent } from '@nuxtjs/composition-api'
import VTranslationStatusBanner from '~/components/VTranslationStatusBanner.vue'
import VMigrationNotice from '~/components/VMigrationNotice.vue'
@@ -17,11 +15,6 @@ import VMigrationNotice from '~/components/VMigrationNotice.vue'
export default defineComponent({
name: 'BlankLayout',
components: { VMigrationNotice, VTranslationStatusBanner },
- setup() {
- const navigationStore = useNavigationStore()
- const isReferredFromCc = computed(() => navigationStore.isReferredFromCc)
- return { isReferredFromCc }
- },
head() {
return this.$nuxtI18nHead({ addSeoAttributes: true, addDirAttribute: true })
},
diff --git a/src/layouts/default.vue b/src/layouts/default.vue
index 0e62e72cb..4893b6331 100644
--- a/src/layouts/default.vue
+++ b/src/layouts/default.vue
@@ -2,7 +2,7 @@
<div class="app grid h-screen overflow-hidden relative">
<div>
<VTeleportTarget name="skip-to-content" :force-destroy="true" />
- <VMigrationNotice v-show="isReferredFromCc" />
+ <VMigrationNotice />
<VTranslationStatusBanner />
<VHeader />
</div>
@@ -25,8 +25,6 @@ import { useMatchSearchRoutes } from '~/composables/use-match-routes'
import { isMinScreen } from '~/composables/use-media-query'
import { useFilterSidebarVisibility } from '~/composables/use-filter-sidebar-visibility'
-import { useNavigationStore } from '~/stores/navigation'
-
import VMigrationNotice from '~/components/VMigrationNotice.vue'
import VTranslationStatusBanner from '~/components/VTranslationStatusBanner.vue'
import VHeader from '~/components/VHeader/VHeader.vue'
@@ -54,9 +52,6 @@ const embeddedPage = {
const mainContentRef = ref(null)
const mainRef = ref(null)
- const navigationStore = useNavigationStore()
- const isReferredFromCc = computed(() => navigationStore.isReferredFromCc)
-
const { isVisible: isFilterVisible } = useFilterSidebarVisibility()
const isMinScreenMd = isMinScreen('md')
const { matches: isSearchRoute } = useMatchSearchRoutes()
@@ -88,7 +83,6 @@ const embeddedPage = {
return {
isHeaderScrolled,
isMinScreenMd,
- isReferredFromCc,
isSidebarVisible,
isSearchRoute,
headerHasTwoRows,
diff --git a/src/locales/po-files/openverse.pot b/src/locales/po-files/openverse.pot
index 343ba467d..7aa3b5740 100644
--- a/src/locales/po-files/openverse.pot
+++ b/src/locales/po-files/openverse.pot
@@ -4,7 +4,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Openverse \n"
"Report-Msgid-Bugs-To: https://github.com/wordpress/openverse/issues \n"
-"POT-Creation-Date: 2022-04-14T15:48:23+00:00\n"
+"POT-Creation-Date: 2022-04-15T05:40:30+00:00\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
@@ -109,18 +109,18 @@ msgid "Select the download file format"
msgstr ""
#. Do not translate words between ### ###.
-#: src/components/VMigrationNotice.vue:4
+#: src/components/VMigrationNotice.vue:8
msgctxt "migration-notice.intro"
msgid "###cc-search### is now called ###openverse### and joins ###wordpress### as an open source project."
msgstr ""
#. Do not translate words between ### ###.
-#: src/components/VMigrationNotice.vue:10
+#: src/components/VMigrationNotice.vue:14
msgctxt "migration-notice.more"
msgid "###read-more### about this announcement."
msgstr ""
-#: src/components/VMigrationNotice.vue:15
+#: src/components/VMigrationNotice.vue:19
msgctxt "migration-notice.read"
msgid "Read more"
msgstr ""
@@ -1856,12 +1856,12 @@ msgid "search button"
msgstr ""
#. Do not translate words between ### ###.
-#: src/components/VTranslationStatusBanner.vue:7
+#: src/components/VTranslationStatusBanner.vue:11
msgctxt "notification.translation.text"
msgid "The translation for ###locale### locale is incomplete. Help us get to 100 percent by ###link###."
msgstr ""
-#: src/components/VTranslationStatusBanner.vue:10
+#: src/components/VTranslationStatusBanner.vue:14
msgctxt "notification.translation.link"
msgid "contributing a translation"
msgstr ""
diff --git a/src/utils/env.ts b/src/utils/env.ts
index a30647ea2..54e65c356 100644
--- a/src/utils/env.ts
+++ b/src/utils/env.ts
@@ -8,7 +8,6 @@ const apiUrl = process.env.API_URL ?? 'https://api.openverse.engineering/'
export const env = {
apiUrl: apiUrl.endsWith('/') ? apiUrl : `${apiUrl}/`,
filterStorageKey: 'openverse-filter-visibility',
- notificationStorageKey: 'openverse-show-notification',
enableInternalAnalytics: process.env.ENABLE_INTERNAL_ANALYTICS ?? 'false',
providerUpdateFrequency: `${60 * 60 * 1000}`, // 1 hour
} as const
diff --git a/src/utils/local.ts b/src/utils/local.ts
index 3dcec2488..b8ec697ce 100644
--- a/src/utils/local.ts
+++ b/src/utils/local.ts
@@ -6,23 +6,33 @@ import { warn } from '~/utils/console'
const localStorageExists = () => process.client && window.localStorage !== null
-const local = {
- get(key: string) {
- try {
- return localStorageExists() ? localStorage.getItem(key) : null
- } catch (e) {
- // Probably a `SecurityError`
- warn('`localStorage` access denied', e)
- return null
- }
+const tryUse = <R>(fn: () => R, def: R) => {
+ try {
+ return localStorageExists() ? fn() : def
+ } catch (e) {
+ warn('`localStorage` access denied', e)
+ return def
+ }
+}
+
+const local: typeof localStorage = {
+ get length() {
+ return tryUse(() => localStorage.length, 0)
+ },
+ getItem(key: string) {
+ return tryUse(() => localStorage.getItem(key), null)
+ },
+ setItem(key: string, value: string) {
+ tryUse(() => localStorage.setItem(key, value), undefined)
+ },
+ clear() {
+ tryUse(() => localStorage.clear(), undefined)
+ },
+ removeItem(key) {
+ tryUse(() => localStorage.removeItem(key), undefined)
},
- set(key: string, value: string) {
- try {
- if (localStorageExists()) localStorage.setItem(key, value)
- } catch (e) {
- // Probably a `SecurityError`
- warn('`localStorage` access denied', e)
- }
+ key(index) {
+ return tryUse(() => localStorage.key(index), null)
},
}
diff --git a/test/playwright/e2e/migration-banner.spec.ts b/test/playwright/e2e/migration-banner.spec.ts
index 2b7145386..3f4f62831 100644
--- a/test/playwright/e2e/migration-banner.spec.ts
+++ b/test/playwright/e2e/migration-banner.spec.ts
@@ -1,25 +1,44 @@
import { test, expect } from '@playwright/test'
-test('shows migration banner on homepage', async ({ page }) => {
- await page.goto('/?referrer=creativecommons.org')
+test.describe('migration banner', () => {
+ test('shows migration banner on homepage', async ({ page }) => {
+ await page.goto('/?referrer=creativecommons.org')
- const migrationNotice = page.locator('.cc-ov-migration')
- const message = 'CC Search is now called Openverse'
+ const migrationNotice = page.locator('[data-testid="banner-cc-referral"]')
+ const message = 'CC Search is now called Openverse'
- await expect(migrationNotice).toContainText(message)
- await expect(migrationNotice).toBeVisible()
-})
+ await expect(migrationNotice).toContainText(message)
+ await expect(migrationNotice).toBeVisible()
+ })
+
+ test('migration banner goes away on navigation', async ({ page }) => {
+ await page.goto('/?referrer=creativecommons.org')
+
+ const migrationNotice = page.locator('[data-testid="banner-cc-referral"]')
+ await expect(migrationNotice).toBeVisible()
+
+ // Navigate away from the page
+ await Promise.all([
+ page.locator('a.homepage-image').first().click(),
+ page.waitForLoadState('domcontentloaded'),
+ ])
+ await expect(migrationNotice).toBeHidden()
+ })
+
+ test('migration banner is dismissable and stays dismissed', async ({
+ page,
+ }) => {
+ await page.goto('/?referrer=creativecommons.org')
-test('migration banner goes away on navigation', async ({ page }) => {
- await page.goto('/?referrer=creativecommons.org')
+ const migrationNotice = page.locator('[data-testid="banner-cc-referral"]')
+ await expect(migrationNotice).toBeVisible({ timeout: 500 })
- const migrationNotice = page.locator('.cc-ov-migration')
- await expect(migrationNotice).toBeVisible()
+ await migrationNotice
+ .locator('[aria-label="Close"]:visible')
+ .click({ timeout: 500 })
+ await expect(migrationNotice).not.toBeVisible({ timeout: 500 })
- // Navigate away from the page
- await Promise.all([
- page.locator('a.homepage-image').first().click(),
- page.waitForLoadState('domcontentloaded'),
- ])
- await expect(migrationNotice).toBeHidden()
+ await page.reload()
+ await expect(migrationNotice).not.toBeVisible({ timeout: 500 })
+ })
})
diff --git a/test/playwright/e2e/translation-banner.spec.ts b/test/playwright/e2e/translation-banner.spec.ts
index cee5733cc..710b2d598 100644
--- a/test/playwright/e2e/translation-banner.spec.ts
+++ b/test/playwright/e2e/translation-banner.spec.ts
@@ -1,33 +1,40 @@
import { test, expect } from '@playwright/test'
-test('Can see the translation banner and go to the correct link', async ({
- page,
-}) => {
- await page.goto('/ru/search/')
- await page.click(
- 'text=The translation for Russian locale is incomplete. Help us get to 100 percent by '
- )
+test.describe('translation banner', () => {
+ test('Can see the translation banner and go to the correct link', async ({
+ page,
+ }) => {
+ await page.goto('/ru/search/')
+ await expect(
+ page.locator(
+ 'text=The translation for Russian locale is incomplete. Help us get to 100 percent by'
+ )
+ ).toBeVisible({ timeout: 500 })
- const [page1] = await Promise.all([
- page.waitForEvent('popup'),
- page.click('text=contributing a translation'),
- ])
- await expect(page1).toHaveURL(
- 'https://translate.wordpress.org/projects/meta/openverse/ru/default/'
- )
-})
+ const [page1] = await Promise.all([
+ page.waitForEvent('popup'),
+ page.click('text=contributing a translation'),
+ ])
+ await expect(page1).toHaveURL(
+ 'https://translate.wordpress.org/projects/meta/openverse/ru/default/'
+ )
+ })
-test('Can close the translation banner', async ({ page }) => {
- await page.goto('/ru/search/')
- await page.click('[aria-label="Закрыть"]')
+ test('Can close the translation banner', async ({ page }) => {
+ await page.goto('/ru/search/')
+ await page.click(
+ '[data-testid="banner-translation-ru"] [aria-label="Закрыть"]:visible',
+ { timeout: 500 }
+ )
- const banner = page.locator('.span:has-text("Help us get to 100 percent")')
- await expect(banner).not.toBeVisible({ timeout: 100 })
- // Test that the banner does not re-appear when navigating to the 'About us' page
- await page.click('[aria-label="меню"]')
- await page.click('a[role="menuitemcheckbox"]:has-text("Наша история")')
- await expect(banner).not.toBeVisible({ timeout: 100 })
+ const banner = page.locator('.span:has-text("Help us get to 100 percent")')
+ await expect(banner).not.toBeVisible({ timeout: 500 })
+ // Test that the banner does not re-appear when navigating to the 'About us' page
+ await page.click('[aria-label="меню"]')
+ await page.click('a[role="menuitemcheckbox"]:has-text("Наша история")')
+ await expect(banner).not.toBeVisible({ timeout: 500 })
- await page.goto('/ru/search/')
- await expect(banner).not.toBeVisible({ timeout: 100 })
+ await page.goto('/ru/search/')
+ await expect(banner).not.toBeVisible({ timeout: 500 })
+ })
})
diff --git a/test/playwright/visual-regression/homepage.spec.ts b/test/playwright/visual-regression/homepage.spec.ts
index 96b386988..926bb4416 100644
--- a/test/playwright/visual-regression/homepage.spec.ts
+++ b/test/playwright/visual-regression/homepage.spec.ts
@@ -15,7 +15,7 @@ test.describe('homepage snapshots', () => {
await page.goto('/')
})
- breakpoints.describeEachDesktop(({ expectSnapshot }) =>
+ breakpoints.describeEvery(({ expectSnapshot }) =>
test('full page', async ({ page }) => {
await deleteImageCarousel(page)
await expectSnapshot('index-ltr', page)
@@ -48,7 +48,7 @@ test.describe('homepage snapshots', () => {
await page.goto('/ar')
})
- breakpoints.describeEachDesktop(({ expectSnapshot }) =>
+ breakpoints.describeEvery(({ expectSnapshot }) =>
test('full page', async ({ page }) => {
await deleteImageCarousel(page)
await expectSnapshot('index-rtl', page)
diff --git a/test/playwright/visual-regression/homepage.spec.ts-snapshots/index-ltr-sm-linux.png b/test/playwright/visual-regression/homepage.spec.ts-snapshots/index-ltr-sm-linux.png
new file mode 100644
index 000000000..930bb8e0d
Binary files /dev/null and b/test/playwright/visual-regression/homepage.spec.ts-snapshots/index-ltr-sm-linux.png differ
diff --git a/test/playwright/visual-regression/homepage.spec.ts-snapshots/index-ltr-xs-linux.png b/test/playwright/visual-regression/homepage.spec.ts-snapshots/index-ltr-xs-linux.png
new file mode 100644
index 000000000..26be80b36
Binary files /dev/null and b/test/playwright/visual-regression/homepage.spec.ts-snapshots/index-ltr-xs-linux.png differ
diff --git a/test/playwright/visual-regression/homepage.spec.ts-snapshots/index-rtl-2xl-linux.png b/test/playwright/visual-regression/homepage.spec.ts-snapshots/index-rtl-2xl-linux.png
index 45e6fe367..dedb129f0 100644
Binary files a/test/playwright/visual-regression/homepage.spec.ts-snapshots/index-rtl-2xl-linux.png and b/test/playwright/visual-regression/homepage.spec.ts-snapshots/index-rtl-2xl-linux.png differ
diff --git a/test/playwright/visual-regression/homepage.spec.ts-snapshots/index-rtl-lg-linux.png b/test/playwright/visual-regression/homepage.spec.ts-snapshots/index-rtl-lg-linux.png
index 665d9f609..53ae9b362 100644
Binary files a/test/playwright/visual-regression/homepage.spec.ts-snapshots/index-rtl-lg-linux.png and b/test/playwright/visual-regression/homepage.spec.ts-snapshots/index-rtl-lg-linux.png differ
diff --git a/test/playwright/visual-regression/homepage.spec.ts-snapshots/index-rtl-md-linux.png b/test/playwright/visual-regression/homepage.spec.ts-snapshots/index-rtl-md-linux.png
index 8191b8595..5419102eb 100644
Binary files a/test/playwright/visual-regression/homepage.spec.ts-snapshots/index-rtl-md-linux.png and b/test/playwright/visual-regression/homepage.spec.ts-snapshots/index-rtl-md-linux.png differ
diff --git a/test/playwright/visual-regression/homepage.spec.ts-snapshots/index-rtl-sm-linux.png b/test/playwright/visual-regression/homepage.spec.ts-snapshots/index-rtl-sm-linux.png
new file mode 100644
index 000000000..53aaed703
Binary files /dev/null and b/test/playwright/visual-regression/homepage.spec.ts-snapshots/index-rtl-sm-linux.png differ
diff --git a/test/playwright/visual-regression/homepage.spec.ts-snapshots/index-rtl-xl-linux.png b/test/playwright/visual-regression/homepage.spec.ts-snapshots/index-rtl-xl-linux.png
index fd58eea2e..3a341b9d2 100644
Binary files a/test/playwright/visual-regression/homepage.spec.ts-snapshots/index-rtl-xl-linux.png and b/test/playwright/visual-regression/homepage.spec.ts-snapshots/index-rtl-xl-linux.png differ
diff --git a/test/playwright/visual-regression/homepage.spec.ts-snapshots/index-rtl-xs-linux.png b/test/playwright/visual-regression/homepage.spec.ts-snapshots/index-rtl-xs-linux.png
new file mode 100644
index 000000000..5d3445299
Binary files /dev/null and b/test/playwright/visual-regression/homepage.spec.ts-snapshots/index-rtl-xs-linux.png differ
diff --git a/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-rtl-2xl-linux.png b/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-rtl-2xl-linux.png
index 2c4bbebd6..815361a05 100644
Binary files a/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-rtl-2xl-linux.png and b/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-rtl-2xl-linux.png differ
diff --git a/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-rtl-lg-linux.png b/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-rtl-lg-linux.png
index e9171cd74..46ecf8fe8 100644
Binary files a/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-rtl-lg-linux.png and b/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-rtl-lg-linux.png differ
diff --git a/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-rtl-md-linux.png b/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-rtl-md-linux.png
index fc2a1a458..8e71de233 100644
Binary files a/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-rtl-md-linux.png and b/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-rtl-md-linux.png differ
diff --git a/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-rtl-sm-linux.png b/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-rtl-sm-linux.png
index 9c375655e..e8d3f93fa 100644
Binary files a/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-rtl-sm-linux.png and b/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-rtl-sm-linux.png differ
diff --git a/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-rtl-xl-linux.png b/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-rtl-xl-linux.png
index 6456bd246..75947c96a 100644
Binary files a/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-rtl-xl-linux.png and b/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-rtl-xl-linux.png differ
diff --git a/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-rtl-xs-linux.png b/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-rtl-xs-linux.png
index 0a002d34b..044c1d255 100644
Binary files a/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-rtl-xs-linux.png and b/test/playwright/visual-regression/sources.spec.ts-snapshots/sources-rtl-xs-linux.png differ
diff --git a/test/unit/specs/components/v-download-button.spec.js b/test/unit/specs/components/v-download-button.spec.js
index afd9f9e62..57c4a776d 100644
--- a/test/unit/specs/components/v-download-button.spec.js
+++ b/test/unit/specs/components/v-download-button.spec.js
@@ -9,8 +9,8 @@ import VDownloadButton from '~/components/VDownloadButton.vue'
import render from '../../test-utils/render'
jest.mock('~/utils/local', () => ({
- get: jest.fn(),
- set: jest.fn(),
+ getItem: jest.fn(),
+ setItem: jest.fn(),
}))
const mockFilesizes = {
@@ -70,7 +70,7 @@ describe('VDownloadButton', () => {
})
it('should use the local storage default on first render', async () => {
- local.get.mockImplementationOnce(() => formats[1].extension_name)
+ local.getItem.mockImplementationOnce(() => formats[1].extension_name)
const wrapper = await doRender()
const downloadLink = wrapper.element.querySelector('a')
expect(downloadLink.getAttribute('href')).toEqual(formats[1].download_url)
@@ -80,7 +80,7 @@ describe('VDownloadButton', () => {
const wrapper = await doRender()
wrapper.find('[aria-haspopup="menu"]').trigger('click')
wrapper.findAll('[role="menuitem"]').wrappers[1].trigger('click')
- expect(local.set).toHaveBeenCalledWith(
+ expect(local.setItem).toHaveBeenCalledWith(
expect.any(String),
formats[1].extension_name
)
diff --git a/tsconfig.json b/tsconfig.json
index 6960bdc76..a821b97ec 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -48,6 +48,10 @@
"src/components/VLicense/VLicense.vue",
"src/components/VContentReport/VReportDescForm.vue",
"src/components/VErrorSection/VErrorImage.vue",
+ "src/components/VTranslationStatusBanner.vue",
+ "src/components/VNotificationBanner.vue",
+ "src/components/VMigrationNotice.vue",
+ "src/components/VVariations.vue",
"src/composables/types.js",
"src/composables/use-event-listener-outside.js",
"src/composables/use-active-audio.js",