From 8fe720cfff44d067640e26f53d87d642da4974cc Mon Sep 17 00:00:00 2001 From: Lukas Gruber Date: Sat, 31 Aug 2024 16:26:03 +0200 Subject: [PATCH] Highlight lyrics that match search result --- assets/components/AppNavbar.vue | 7 +-- assets/components/HighlightWords.vue | 33 ++++++++++++++ assets/components/SearchForm.test.js | 4 +- assets/components/SearchForm.vue | 8 +++- assets/stores/index.js | 2 + assets/stores/search.js | 9 ++++ assets/views/TrackDetailView.vue | 11 +++-- package-lock.json | 68 ++++++++++++++++++++++------ package.json | 5 +- 9 files changed, 120 insertions(+), 27 deletions(-) create mode 100644 assets/components/HighlightWords.vue create mode 100644 assets/stores/index.js create mode 100644 assets/stores/search.js diff --git a/assets/components/AppNavbar.vue b/assets/components/AppNavbar.vue index 64f3f3d..09b3a60 100644 --- a/assets/components/AppNavbar.vue +++ b/assets/components/AppNavbar.vue @@ -16,7 +16,7 @@ is-nav > - + @@ -55,7 +55,7 @@ import SearchForm from './SearchForm.vue'; import {AuthApi} from '@/openapi'; import querystring from 'querystring'; -import {useAuthStore} from '@/stores/auth'; +import {useAuthStore, useSearchStore} from '@/stores'; import {mapStores} from 'pinia'; const authClient = new AuthApi(); @@ -65,10 +65,11 @@ export default { SearchForm, }, computed: { - ...mapStores(useAuthStore), + ...mapStores(useAuthStore, useSearchStore), }, methods: { search(query) { + this.searchStore.keywords = query; this.$router.push({name: 'search', params: {q: query}}).catch(() => {}); }, async logout() { diff --git a/assets/components/HighlightWords.vue b/assets/components/HighlightWords.vue new file mode 100644 index 0000000..7662e98 --- /dev/null +++ b/assets/components/HighlightWords.vue @@ -0,0 +1,33 @@ + + + + + diff --git a/assets/components/SearchForm.test.js b/assets/components/SearchForm.test.js index 91ef4a8..306739f 100644 --- a/assets/components/SearchForm.test.js +++ b/assets/components/SearchForm.test.js @@ -8,7 +8,7 @@ describe('SearchForm', () => { await fireEvent.click(getByRole('button')); - expect(emitted().search).toHaveLength(1); + expect(emitted().input).toHaveLength(1); }); test('Emitted event contains the entered input value', async () => { @@ -18,6 +18,6 @@ describe('SearchForm', () => { await fireEvent.update(getByRole('textbox'), query); await fireEvent.click(getByRole('button')); - expect(emitted().search[0][0]).toEqual(query); + expect(emitted().input[0][0]).toEqual(query); }); }); diff --git a/assets/components/SearchForm.vue b/assets/components/SearchForm.vue index d010339..b181f4d 100644 --- a/assets/components/SearchForm.vue +++ b/assets/components/SearchForm.vue @@ -1,7 +1,7 @@