Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TAS-2785] ✨ Add random keyword search feature to homepage #2003

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions src/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,9 @@
>
<input
v-model="searchQuery"
class="grow w-full bg-transparent border-0 text-dark-gray focus-visible:outline-none"
class="w-full bg-transparent border-0 grow text-dark-gray focus-visible:outline-none"
type="text"
:placeholder="$t('gutenberg_search_placeholder')"
:placeholder="placeholderText"
@keyup.enter="toggleSearch"
/>
<ButtonV2
Expand Down Expand Up @@ -755,7 +755,7 @@
{{ faq.question }}
</template>
<template #answer>
<div v-html="faq.answer" />

Check warning on line 758 in src/pages/index.vue

View workflow job for this annotation

GitHub Actions / CI

'v-html' directive can lead to XSS attack
</template>
</IndexPageFAQItem>
</li>
Expand Down Expand Up @@ -816,6 +816,8 @@
import { logTrackerEvent, logRetailEvent } from '~/util/EventLogger';
import { fisherShuffle } from '~/util/misc';

import { SEARCH_SUGGESTIONS } from '@/constant/index';

const SIGNATURE_BANNER_NAMES = [
'董啟章',
'陳健民',
Expand Down Expand Up @@ -845,6 +847,7 @@
dialogNFTClassList: [],
isSiteHeaderFixed: false,
searchQuery: '',
placeholderText: '',
};
},
async fetch({ store }) {
Expand Down Expand Up @@ -1000,10 +1003,23 @@
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.randomKeywords?.length
? this.randomKeywords.join('、')
: this.$t('gutenberg_search_placeholder');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be computed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

},
beforeDestroy() {
window.removeEventListener('scroll', this.handleScroll);
Expand Down Expand Up @@ -1096,6 +1112,14 @@
query: { q: this.searchQuery },
})
);
} else {
const fallbackKeyword = this.randomKeywords?.[0];
this.$router.push(
this.localeLocation({
name: 'store',
query: { q: fallbackKeyword },
})
);
}
},
},
Expand Down
Loading