From 5151204c6a9333246b2e11dbf56622c0a0401b58 Mon Sep 17 00:00:00 2001 From: Dhruv Bhanushali Date: Wed, 14 Feb 2024 14:34:36 +0400 Subject: [PATCH 1/8] Add emit and handling for single-clear event --- .../VHeader/VSearchBar/VSearchBar.vue | 7 +++++++ .../VRecentSearches/VRecentSearches.vue | 17 ++++++++++++++++- .../meta/VRecentSearches.stories.mdx | 3 +++ frontend/src/locales/scripts/en.json5 | 3 +++ frontend/src/stores/search.ts | 3 +++ 5 files changed, 32 insertions(+), 1 deletion(-) diff --git a/frontend/src/components/VHeader/VSearchBar/VSearchBar.vue b/frontend/src/components/VHeader/VSearchBar/VSearchBar.vue index 54fcba7dc9a..250050b20cc 100644 --- a/frontend/src/components/VHeader/VSearchBar/VSearchBar.vue +++ b/frontend/src/components/VHeader/VSearchBar/VSearchBar.vue @@ -50,6 +50,7 @@ :class="recentClasses" @select="handleSelect" @clear="handleClear" + @clear-single="handleClearSingle" @keydown.tab.native="hideRecentSearches" /> @@ -227,6 +228,11 @@ export default defineComponent({ inputFieldRef.value?.focusInput() searchStore.clearRecentSearches() } + /* Clear a specific recent search from the store. */ + const handleClearSingle = (idx: number) => { + inputFieldRef.value?.focusInput() + searchStore.clearRecentSearch(idx) + } return { searchBarEl, @@ -247,6 +253,7 @@ export default defineComponent({ handleKeydown, handleSelect, handleClear, + handleClearSingle, } }, }) diff --git a/frontend/src/components/VRecentSearches/VRecentSearches.vue b/frontend/src/components/VRecentSearches/VRecentSearches.vue index 1e7b76d8b39..851be483b18 100644 --- a/frontend/src/components/VRecentSearches/VRecentSearches.vue +++ b/frontend/src/components/VRecentSearches/VRecentSearches.vue @@ -43,6 +43,15 @@ @click="handleClick(idx)" > {{ entry }} + @@ -62,6 +71,7 @@ import { defineComponent, type PropType } from "vue" import { defineEvent } from "~/types/emits" import VButton from "~/components/VButton.vue" +import VIconButton from "~/components/VIconButton/VIconButton.vue" /** * List the recent searches of the user allowing them to go back to a previous @@ -69,7 +79,7 @@ import VButton from "~/components/VButton.vue" */ export default defineComponent({ name: "VRecentSearches", - components: { VButton }, + components: { VIconButton, VButton }, props: { /** * the list of saved past searches @@ -95,6 +105,7 @@ export default defineComponent({ emits: { select: defineEvent<[number]>(), clear: defineEvent(), + "clear-single": defineEvent<[number]>(), }, setup(_, { emit }) { const handleClick = (idx: number) => { @@ -103,10 +114,14 @@ export default defineComponent({ const handleClear = () => { emit("clear") } + const handleClearSingle = (idx: number) => { + emit("clear-single", idx) + } return { handleClick, handleClear, + handleClearSingle, } }, }) diff --git a/frontend/src/components/VRecentSearches/meta/VRecentSearches.stories.mdx b/frontend/src/components/VRecentSearches/meta/VRecentSearches.stories.mdx index a5a6c4a10a2..5a6c5d1ef67 100644 --- a/frontend/src/components/VRecentSearches/meta/VRecentSearches.stories.mdx +++ b/frontend/src/components/VRecentSearches/meta/VRecentSearches.stories.mdx @@ -18,6 +18,9 @@ import VRecentSearches from "~/components/VRecentSearches/VRecentSearches.vue" clear: { action: "clear", }, + clearSingle: { + action: "clearSingle", + }, }} /> diff --git a/frontend/src/locales/scripts/en.json5 b/frontend/src/locales/scripts/en.json5 index 9cab04500bf..4c07c8328e5 100644 --- a/frontend/src/locales/scripts/en.json5 +++ b/frontend/src/locales/scripts/en.json5 @@ -744,6 +744,9 @@ text: "Clear", label: "Clear recent searches", }, + clearSingle: { + label: "Clear recent search '{entry}'", + }, none: "No recent searches to show.", disclaimer: "Openverse does not store your recent searches, this information is kept locally in your browser.", }, diff --git a/frontend/src/stores/search.ts b/frontend/src/stores/search.ts index 6c15534fb10..9c26eddfa28 100644 --- a/frontend/src/stores/search.ts +++ b/frontend/src/stores/search.ts @@ -331,6 +331,9 @@ export const useSearchStore = defineStore("search", { clearRecentSearches() { this.recentSearches = [] }, + clearRecentSearch(idx: number) { + this.recentSearches.splice(idx, 1) + }, /** * Initial filters do not include the provider filters. We create the provider filters object * when we fetch the provider data on the Nuxt server initialization. From 072fb4e4c69c49bedc2a3452b08d2689b6e712f2 Mon Sep 17 00:00:00 2001 From: Dhruv Bhanushali Date: Wed, 14 Feb 2024 21:43:07 +0400 Subject: [PATCH 2/8] Update appearance to match mockups --- .../VRecentSearches/VRecentSearches.vue | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/frontend/src/components/VRecentSearches/VRecentSearches.vue b/frontend/src/components/VRecentSearches/VRecentSearches.vue index 851be483b18..e5a0381d960 100644 --- a/frontend/src/components/VRecentSearches/VRecentSearches.vue +++ b/frontend/src/components/VRecentSearches/VRecentSearches.vue @@ -1,15 +1,15 @@