-
-
Notifications
You must be signed in to change notification settings - Fork 366
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
refactor: search bar component #3894
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
3d32741
refactor: search bar component
Jarsen136 d528ba1
refactor: searchbar range slider
Jarsen136 1414a75
Merge branch 'main' into issue-3883
Jarsen136 c39392f
refactor: searchbar input component
Jarsen136 42dd7e1
refactor: rename price range component
Jarsen136 263b5a2
Merge branch 'main' into issue-3883
prachi00 9083711
refactor(searchbar): suggestion component
Jarsen136 af0f228
Merge branch 'issue-3883' of github.com:Jarsen136/nft-gallery into is…
Jarsen136 f271944
chore: search bar component rename
Jarsen136 9621372
Merge branch 'main' into issue-3883
prachi00 ded3588
fix: e2e search test
Jarsen136 ff2752a
Merge branch 'issue-3883' of github.com:Jarsen136/nft-gallery into is…
Jarsen136 8e604a7
fix: search enter event listener
Jarsen136 31adfbd
refactor: search enter
Jarsen136 472c9dd
Merge branch 'main' into issue-3883
Jarsen136 2dadca8
Merge branch 'main' into issue-3883
Jarsen136 ecb32a9
Merge branch 'issue-3883' of github.com:Jarsen136/nft-gallery into is…
Jarsen136 6f5c08e
Merge branch 'main' into issue-3883
petersopko 7d151d3
refactor: simplify search component
Jarsen136 cdf9d79
Merge branch 'main' into issue-3883
yangwao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,304 @@ | ||
<template> | ||
<div class="mb-3"> | ||
<div v-if="!isVisible && !hideSearchInput" class="row"> | ||
<div v-if="priceRangeDirty && !hideFilter" class="is-size-7"> | ||
<PriceRange inline /> | ||
</div> | ||
</div> | ||
<div class="columns mb-0"> | ||
<b-field class="column is-8 mb-0 mr-2" :class="searchColumnClass"> | ||
<b-button | ||
v-if="!hideFilter" | ||
icon-left="filter" | ||
aria-controls="sortAndFilter" | ||
type="is-primary is-bordered-light" | ||
class="is-hidden-mobile mr-2" | ||
data-cy="expand-search" | ||
@click="isVisible = !isVisible" /> | ||
<slot name="next-filter"></slot> | ||
<SearchBarInput | ||
v-if="!hideSearchInput" | ||
v-model="name" | ||
:query="query" | ||
@enter="nativeSearch" | ||
@blur="onBlur"></SearchBarInput> | ||
<div v-if="!isVisible && hideSearchInput"> | ||
<div v-if="priceRangeDirty" class="is-size-7"> | ||
<PriceRange inline /> | ||
</div> | ||
</div> | ||
</b-field> | ||
<b-field | ||
v-if="!hideFilter" | ||
expanded | ||
position="is-right" | ||
class="column is-4"> | ||
<b-button | ||
icon-left="filter" | ||
aria-controls="sortAndFilter" | ||
type="is-primary" | ||
class="is-hidden-tablet mr-2" | ||
@click="isVisible = !isVisible" /> | ||
<slot /> | ||
</b-field> | ||
</div> | ||
<b-collapse | ||
v-model="isVisible" | ||
aria-id="sortAndFilter" | ||
animation="opacitySlide"> | ||
<div class="columns mb-0"> | ||
<Sort | ||
multiple-select | ||
class="column is-4 mb-0" | ||
:value="sortByMultiple" | ||
@input="updateSortBy($event, sortByMultiple)" /> | ||
<BasicSwitch | ||
v-model="vListed" | ||
class="is-flex column is-4" | ||
:label="!replaceBuyNowWithYolo ? 'sort.listed' : 'YOLO'" | ||
size="is-medium" | ||
label-color="has-text-success" /> | ||
</div> | ||
<SearchPriceRange | ||
v-if="!hideFilter" | ||
:range="priceRange" | ||
@input="priceRangeChange"></SearchPriceRange> | ||
<div v-if="priceRangeDirty" class="is-size-7"> | ||
<PriceRange inline /> | ||
</div> | ||
</b-collapse> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { Component, Emit, Prop, mixins } from 'nuxt-property-decorator' | ||
import { Debounce } from 'vue-debounce-decorator' | ||
import { exist, existArray } from './exist' | ||
import { SearchQuery } from './types' | ||
import PrefixMixin from '~/utils/mixins/prefixMixin' | ||
import KeyboardEventsMixin from '~/utils/mixins/keyboardEventsMixin' | ||
import { NFT_SQUID_SORT_CONDITION_LIST } from '@/utils/constants' | ||
import ChainMixin from '~/utils/mixins/chainMixin' | ||
|
||
@Component({ | ||
components: { | ||
Sort: () => import('./SearchSortDropdown.vue'), | ||
SearchBarInput: () => import('./SearchBar.vue'), | ||
SearchPriceRange: () => import('./SearchPriceRange.vue'), | ||
Pagination: () => import('@/components/rmrk/Gallery/Pagination.vue'), | ||
BasicSwitch: () => import('@/components/shared/form/BasicSwitch.vue'), | ||
BasicImage: () => import('@/components/shared/view/BasicImage.vue'), | ||
PriceRange: () => import('@/components/shared/format/PriceRange.vue'), | ||
Money: () => import('@/components/shared/format/Money.vue'), | ||
}, | ||
}) | ||
export default class Search extends mixins( | ||
PrefixMixin, | ||
KeyboardEventsMixin, | ||
ChainMixin | ||
) { | ||
@Prop(String) public search!: string | ||
@Prop(String) public type!: string | ||
@Prop({ type: Array, default: () => [] }) public sortByMultiple!: string[] | ||
@Prop(String) public searchColumnClass!: string | ||
@Prop({ type: Boolean, default: false }) public listed!: boolean | ||
@Prop(Boolean) public hideFilter!: boolean | ||
@Prop(Boolean) public hideSearchInput!: boolean | ||
public isVisible = false | ||
public query: SearchQuery = { | ||
search: this.$route.query?.search?.toString() ?? '', | ||
type: this.$route.query?.type?.toString() ?? '', | ||
sortByMultiple: this.sortByMultiple ?? [], | ||
listed: this.$route.query?.listed?.toString() === 'true', | ||
} | ||
public name = '' | ||
public priceRange: [ | ||
number | string | undefined, | ||
number | string | undefined | ||
] = [undefined, undefined] | ||
public priceRangeDirty = false | ||
|
||
public created() { | ||
this.initKeyboardEventHandler({ | ||
f: this.bindFilterEvents, | ||
}) | ||
} | ||
|
||
public mounted(): void { | ||
exist(this.$route.query.search, this.updateSearch) | ||
exist(this.$route.query.min, (v) => this.updatePriceRangeByQuery(v)) | ||
exist(this.$route.query.max, (v) => | ||
this.updatePriceRangeByQuery(undefined, v) | ||
) | ||
existArray(this.$route.query.sort as string[], this.updateSortBy) | ||
exist(this.$route.query.listed, this.updateListed) | ||
} | ||
|
||
private bindFilterEvents(event) { | ||
switch (event.key) { | ||
case 'b': | ||
this.updateListed(!this.vListed) | ||
break | ||
case 'n': | ||
this.updateSortBy(['BLOCK_NUMBER_DESC']) | ||
break | ||
case 'o': | ||
this.updateSortBy(['BLOCK_NUMBER_ASC']) | ||
break | ||
case 'e': | ||
this.updateSortBy(['PRICE_DESC']) | ||
break | ||
case 'c': | ||
this.updateSortBy(['PRICE_ASC']) | ||
break | ||
} | ||
} | ||
|
||
get vListed(): boolean { | ||
this.query.listed = this.listed | ||
return this.listed | ||
} | ||
|
||
set vListed( | ||
listed: boolean | { listed: boolean; min?: string; max?: string } | ||
) { | ||
this.updateListed(listed) | ||
} | ||
|
||
get searchQuery(): string { | ||
return this.search | ||
} | ||
|
||
set searchQuery(value: string) { | ||
this.updateSearch(value) | ||
} | ||
|
||
get replaceBuyNowWithYolo(): boolean { | ||
return this.$store.getters['preferences/getReplaceBuyNowWithYolo'] | ||
} | ||
|
||
@Emit('update:listed') | ||
@Debounce(50) | ||
updateListed( | ||
value: string | boolean | { listed: boolean; min?: string; max?: string } | ||
): boolean { | ||
let v = '' | ||
if (typeof value === 'string' || typeof value === 'boolean') { | ||
v = String(value) | ||
this.replaceUrl({ listed: v }) | ||
} else { | ||
const { listed, max, min } = value | ||
v = String(listed) | ||
this.replaceUrl({ | ||
listed, | ||
max, | ||
min, | ||
}) | ||
} | ||
return v === 'true' | ||
} | ||
|
||
@Emit('update:sortByMultiple') | ||
@Debounce(400) | ||
updateSortBy(value: string[] | string, $event?): string[] { | ||
const final = (Array.isArray(value) ? value : [value]).filter((condition) => | ||
NFT_SQUID_SORT_CONDITION_LIST.includes(condition) | ||
) | ||
const listed = final.some( | ||
(condition) => condition.toLowerCase().indexOf('price') > -1 | ||
) | ||
if (listed && !this.vListed) { | ||
this.vListed = true | ||
} | ||
|
||
if ($event?.length > final.length || !$event) { | ||
this.replaceUrl({ sort: final }) | ||
return final | ||
} | ||
let newFinal: string[] = [] | ||
if (final.length > 0) { | ||
const newlySelected = final[final.length - 1].split('_')[0] | ||
newFinal = $event.filter( | ||
(option) => option.split('_')[0] !== newlySelected | ||
) | ||
newFinal.push(final[final.length - 1]) | ||
} | ||
this.replaceUrl({ sort: newFinal }) | ||
return newFinal | ||
} | ||
|
||
onBlur() { | ||
this.updateSearch(this.name) | ||
} | ||
|
||
@Emit('update:search') | ||
@Debounce(50) | ||
updateSearch(value: string): string { | ||
if (value !== this.searchQuery) { | ||
this.replaceUrl({ search: value ?? undefined }) | ||
} | ||
return value | ||
} | ||
|
||
updatePriceRangeByQuery(minValue?: string, maxValue?: string) { | ||
const min = Number(minValue) | ||
const max = Number(maxValue) | ||
if (Number.isNaN(min) && Number.isNaN(max)) { | ||
return | ||
} | ||
this.priceRangeDirty = true | ||
if (minValue) { | ||
this.priceRange = [min, this.priceRange[1]] | ||
this.priceRangeChangeMin(min * 10 ** this.decimals) | ||
} else { | ||
this.priceRange = [this.priceRange[0], max] | ||
this.priceRangeChangeMax(max * 10 ** this.decimals) | ||
} | ||
} | ||
|
||
nativeSearch() { | ||
this.searchQuery = this.name | ||
this.updateSearch(this.name) | ||
} | ||
|
||
@Debounce(100) | ||
replaceUrl(queryCondition: { [key: string]: any }): void { | ||
this.$router | ||
.replace({ | ||
path: String(this.$route.path), | ||
query: { | ||
page: '1', | ||
...this.$route.query, | ||
search: this.searchQuery || undefined, | ||
...queryCondition, | ||
}, | ||
}) | ||
.catch(this.$consola.warn /*Navigation Duplicate err fix later */) | ||
// if searchbar request or filter is set, pagination should always revert to page 1 | ||
this.$emit('resetPage') | ||
} | ||
|
||
public priceRangeChange([min, max]: [ | ||
number | undefined, | ||
number | undefined | ||
]): void { | ||
this.priceRangeDirty = true | ||
this.priceRangeChangeMin(min ? min * 10 ** this.decimals : undefined) | ||
this.priceRangeChangeMax(max ? max * 10 ** this.decimals : undefined) | ||
const priceMin = min ? String(min) : undefined | ||
const priceMax = max ? String(max) : undefined | ||
this.query.listed = true | ||
this.vListed = { listed: true, min: priceMin, max: priceMax } | ||
} | ||
|
||
@Emit('update:priceMin') | ||
private priceRangeChangeMin(min?: number): void { | ||
this.query.priceMin = min | ||
} | ||
|
||
@Emit('update:priceMax') | ||
private priceRangeChangeMax(max?: number): void { | ||
this.query.priceMax = max | ||
} | ||
} | ||
</script> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this have like 400 LOC?