From c17af04cbf92c1092f796383c0b6e8086f34cfee Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Mon, 5 Jan 2026 16:58:18 +0100 Subject: [PATCH] Refactor vocabulary search functionality in VocabService and update UI components - Modified the searchVocabs method in VocabService to consolidate search parameters into a single query term for improved flexibility. - Updated VocabSearchDialog to replace separate input fields for mother tongue and learning language with a unified search term input. - Adjusted button logic to enable search only when a term is provided, enhancing user experience. - Added new translations for the search term in both German and English locales to support the updated UI. --- backend/services/vocabService.js | 17 ++++++------- .../socialnetwork/VocabSearchDialog.vue | 24 +++++++------------ .../src/i18n/locales/de/socialnetwork.json | 1 + .../src/i18n/locales/en/socialnetwork.json | 1 + 4 files changed, 19 insertions(+), 24 deletions(-) diff --git a/backend/services/vocabService.js b/backend/services/vocabService.js index 4a2fcb9..e9d5229 100644 --- a/backend/services/vocabService.js +++ b/backend/services/vocabService.js @@ -408,20 +408,23 @@ export default class VocabService { return { languageId: access.id, isOwner: access.isOwner, vocabs: rows }; } - async searchVocabs(hashedUserId, languageId, { learning = '', motherTongue = '' } = {}) { + async searchVocabs(hashedUserId, languageId, { q = '', learning = '', motherTongue = '' } = {}) { const user = await this._getUserByHashedId(hashedUserId); const access = await this._getLanguageAccess(user.id, languageId); + const query = typeof q === 'string' ? q.trim() : ''; + // Abwärtskompatibel: falls alte Parameter genutzt werden, zusammenfassen const learningTerm = typeof learning === 'string' ? learning.trim() : ''; const motherTerm = typeof motherTongue === 'string' ? motherTongue.trim() : ''; - if (!learningTerm && !motherTerm) { + const effective = query || learningTerm || motherTerm; + + if (!effective) { const err = new Error('Missing search term'); err.status = 400; throw err; } - const learningLike = learningTerm ? `%${learningTerm}%` : null; - const motherLike = motherTerm ? `%${motherTerm}%` : null; + const like = `%${effective}%`; const rows = await sequelize.query( ` @@ -436,16 +439,14 @@ export default class VocabService { JOIN community.vocab_lexeme l1 ON l1.id = cl.learning_lexeme_id JOIN community.vocab_lexeme l2 ON l2.id = cl.reference_lexeme_id WHERE c.language_id = :languageId - AND (:learningLike IS NULL OR l1.text ILIKE :learningLike) - AND (:motherLike IS NULL OR l2.text ILIKE :motherLike) + AND (l1.text ILIKE :like OR l2.text ILIKE :like) ORDER BY l2.text ASC, l1.text ASC, c.title ASC LIMIT 200 `, { replacements: { languageId: access.id, - learningLike, - motherLike, + like, }, type: sequelize.QueryTypes.SELECT, } diff --git a/frontend/src/dialogues/socialnetwork/VocabSearchDialog.vue b/frontend/src/dialogues/socialnetwork/VocabSearchDialog.vue index 6383b83..23e264c 100644 --- a/frontend/src/dialogues/socialnetwork/VocabSearchDialog.vue +++ b/frontend/src/dialogues/socialnetwork/VocabSearchDialog.vue @@ -16,14 +16,10 @@
- -
@@ -66,8 +62,7 @@ export default { return { languageId: null, languageName: '', - motherTongue: '', - learning: '', + term: '', loading: false, results: [], error: '', @@ -85,8 +80,7 @@ export default { open({ languageId, languageName = '' } = {}) { this.languageId = languageId; this.languageName = languageName || ''; - this.motherTongue = ''; - this.learning = ''; + this.term = ''; this.results = []; this.error = ''; this.loading = false; @@ -98,17 +92,15 @@ export default { }, async runSearch() { if (!this.languageId) return; - const mt = this.motherTongue.trim(); - const l = this.learning.trim(); - if (!mt && !l) return; + const q = this.term.trim(); + if (!q) return; this.loading = true; this.error = ''; try { const res = await apiClient.get(`/api/vocab/languages/${this.languageId}/search`, { params: { - motherTongue: mt || undefined, - learning: l || undefined, + q, }, }); this.results = res.data?.results || []; diff --git a/frontend/src/i18n/locales/de/socialnetwork.json b/frontend/src/i18n/locales/de/socialnetwork.json index 2add768..24e20b4 100644 --- a/frontend/src/i18n/locales/de/socialnetwork.json +++ b/frontend/src/i18n/locales/de/socialnetwork.json @@ -312,6 +312,7 @@ "search": { "open": "Suche", "title": "Vokabeln suchen", + "term": "Suchbegriff", "motherTongue": "Muttersprache", "learningLanguage": "Lernsprache", "lesson": "Lektion", diff --git a/frontend/src/i18n/locales/en/socialnetwork.json b/frontend/src/i18n/locales/en/socialnetwork.json index 2b5844e..76d2b8d 100644 --- a/frontend/src/i18n/locales/en/socialnetwork.json +++ b/frontend/src/i18n/locales/en/socialnetwork.json @@ -312,6 +312,7 @@ "search": { "open": "Search", "title": "Search vocabulary", + "term": "Search term", "motherTongue": "Mother tongue", "learningLanguage": "Learning language", "lesson": "Lesson",