Skip to content

Commit

Permalink
✨ Add random search placeholder
Browse files Browse the repository at this point in the history
  • Loading branch information
AuroraHuang22 committed Nov 24, 2024
1 parent 8a02cae commit 129c493
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 4 deletions.
24 changes: 21 additions & 3 deletions src/components/SearchBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@
preset="tertiary"
@click="toggleSearch"
>
<IconSearch />
<div class="flex flex-nowrap items-center gap-[8px]">
<IconSearch />
<p
class="text-medium-gray whitespace-nowrap"
v-text="$t('listing_page_search_label')"
/>
</div>
</ButtonV2>
<div
class="flex items-center justify-center cursor-pointer p-[8px] desktop:hidden"
Expand Down Expand Up @@ -42,10 +48,11 @@
>
<IconSearch />
<input
:value="searchQuery"
ref="searchInput"
class="w-full bg-transparent border-0 focus-visible:outline-none"
type="text"
:placeholder="$t('gutenberg_search_placeholder')"
:value="searchQuery"
:placeholder="placeholderText"
@input="debouncedUpdateSearchKeyword"
/>
<ButtonV2
Expand All @@ -63,6 +70,7 @@

<script>
import debounce from 'lodash.debounce';
import { SEARCH_SUGGESTIONS } from '@/constant/index';
export default {
name: 'SearchBar',
Expand All @@ -75,6 +83,7 @@ export default {
data() {
return {
isSearchOpen: false,
placeholderText: this.$t('gutenberg_search_placeholder'),
};
},
mounted() {
Expand All @@ -88,6 +97,10 @@ export default {
this.$emit('clear');
} else {
this.$emit('open');
this.placeholderText = this.getRandomPlaceholder();
this.$nextTick(() => {
this.$refs.searchInput?.focus();
});
}
this.isSearchOpen = !this.isSearchOpen;
},
Expand All @@ -97,6 +110,11 @@ export default {
},
200
),
getRandomPlaceholder() {
const shuffled = [...SEARCH_SUGGESTIONS].sort(() => Math.random() - 0.5);
const randomTerms = shuffled.slice(0, 3);
return randomTerms.join('');
},
},
};
</script>
15 changes: 15 additions & 0 deletions src/constant/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,3 +428,18 @@ export const SIGN_AUTHORIZATION_PERMISSIONS = [
'read:nftcollection',
'write:nftcollection',
];

export const SEARCH_SUGGESTIONS = [
'免費',
'小說',
'旅遊',
'報刊',
'心靈',
'運動',
'董啟章',
'李立峯',
'新聞',
'理財',
'區塊鏈',
'繪本',
];
1 change: 1 addition & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@
"listing_page_QA_label": "What is the difference between ebooks and paperbacks?",
"listing_page_QA_title": "FAQ",
"listing_page_search": "Search",
"listing_page_search_label": "book title or author",
"listing_page_search_not_found": "Please try different keywords.",
"listing_page_search_recommend": "Or explore our recommended books:",
"listing_page_search_result": "The search results for '{query}':",
Expand Down
1 change: 1 addition & 0 deletions src/locales/zh-Hant.json
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@
"listing_page_QA_label": "電子書和紙本書有什麼分別?",
"listing_page_QA_title": "常見問題",
"listing_page_search": "搜尋",
"listing_page_search_label": "搜尋書名或作者",
"listing_page_search_not_found": "請嘗試使用其他關鍵字。",
"listing_page_search_recommend": "或是您可以瀏覽我們的推薦書籍:",
"listing_page_search_result": "以下為 “{query}” 的搜尋結果:",
Expand Down
5 changes: 4 additions & 1 deletion src/pages/store/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,11 @@
'relative',
]"
>
<div class="flex items-center justify-center">
<div
class="flex items-center justify-center cursor-pointer px-[10px]"
>
<SearchBar
class="w-full"
:search-query="searchQuery"
@open="handleSearchBarOpen"
@clear="handleSearchBarClear"
Expand Down

0 comments on commit 129c493

Please sign in to comment.