From 625cc0f1763968b9fb71426b43a7878a6a66f4aa Mon Sep 17 00:00:00 2001 From: AuroraHuang22 Date: Thu, 26 Dec 2024 22:41:43 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E2=9C=A8=20Add=20random=20keyword=20search?= =?UTF-8?q?=20feature=20to=20homepage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/index.vue | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/pages/index.vue b/src/pages/index.vue index dccfd3088..38afcd522 100644 --- a/src/pages/index.vue +++ b/src/pages/index.vue @@ -347,9 +347,9 @@ > Math.random() - 0.5 + ); + const randomTerms = shuffled.slice(0, 3); + this.randomKeywords = randomTerms; + return randomTerms.join('、'); } + return this.$t('gutenberg_search_placeholder'); }, }, }; From 754a2a13427587e7b9fc7b4cddbca97d77348386 Mon Sep 17 00:00:00 2001 From: AuroraHuang22 Date: Fri, 27 Dec 2024 12:05:51 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Refactor=20randomKeywo?= =?UTF-8?q?rds=20into=20a=20computed=20prop?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/index.vue | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/pages/index.vue b/src/pages/index.vue index 38afcd522..61eb5055d 100644 --- a/src/pages/index.vue +++ b/src/pages/index.vue @@ -848,7 +848,6 @@ export default { isSiteHeaderFixed: false, searchQuery: '', placeholderText: '', - randomKeywords: [], }; }, async fetch({ store }) { @@ -1004,11 +1003,23 @@ export default { answer, })); }, + randomKeywords() { + if (this.$i18n.locale === 'zh-Hant') { + const shuffled = [...SEARCH_SUGGESTIONS].sort( + () => Math.random() - 0.5 + ); + const randomTerms = shuffled.slice(0, 3); + return randomTerms; + } + return []; + }, }, mounted() { logRetailEvent(this, 'home-page-view'); window.addEventListener('scroll', this.handleScroll); - this.placeholderText = this.getRandomPlaceholder(); + this.placeholderText = this.randomKeywords?.length + ? this.randomKeywords.join('、') + : this.$t('gutenberg_search_placeholder'); }, beforeDestroy() { window.removeEventListener('scroll', this.handleScroll); @@ -1111,17 +1122,6 @@ export default { ); } }, - getRandomPlaceholder() { - if (this.$i18n.locale === 'zh-Hant') { - const shuffled = [...SEARCH_SUGGESTIONS].sort( - () => Math.random() - 0.5 - ); - const randomTerms = shuffled.slice(0, 3); - this.randomKeywords = randomTerms; - return randomTerms.join('、'); - } - return this.$t('gutenberg_search_placeholder'); - }, }, }; From 69a6555e5af3f7f24d8e847f380660e341ff84e0 Mon Sep 17 00:00:00 2001 From: AuroraHuang22 Date: Fri, 27 Dec 2024 13:11:00 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Refactor=20placeholder?= =?UTF-8?q?Text=20into=20a=20computed=20prop?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/index.vue | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/pages/index.vue b/src/pages/index.vue index 61eb5055d..120874174 100644 --- a/src/pages/index.vue +++ b/src/pages/index.vue @@ -847,7 +847,6 @@ export default { dialogNFTClassList: [], isSiteHeaderFixed: false, searchQuery: '', - placeholderText: '', }; }, async fetch({ store }) { @@ -1013,13 +1012,15 @@ export default { } return []; }, + placeholderText() { + return this.randomKeywords?.length + ? this.randomKeywords.join('、') + : this.$t('gutenberg_search_placeholder'); + }, }, mounted() { logRetailEvent(this, 'home-page-view'); window.addEventListener('scroll', this.handleScroll); - this.placeholderText = this.randomKeywords?.length - ? this.randomKeywords.join('、') - : this.$t('gutenberg_search_placeholder'); }, beforeDestroy() { window.removeEventListener('scroll', this.handleScroll);