rewrite USerAutoSuggest without any dependency

This commit is contained in:
taehoon 2019-04-02 12:31:45 -04:00
parent da5844205c
commit 94e67ff118
2 changed files with 29 additions and 102 deletions

View File

@ -1,41 +1,34 @@
import { VueAutosuggest } from 'vue-autosuggest'
import BasicUserCard from '../basic_user_card/basic_user_card.vue' import BasicUserCard from '../basic_user_card/basic_user_card.vue'
import userSearchApi from '../../services/new_api/user_search.js' import userSearchApi from '../../services/new_api/user_search.js'
const debounceMilliseconds = 500
export default { export default {
components: { components: {
VueAutosuggest,
BasicUserCard BasicUserCard
}, },
data () { data () {
return { return {
query: '',
results: [], results: [],
timeout: null, timeout: null
selected: null, }
debounceMilliseconds: 500, },
inputProps: { watch: {
id: 'autosuggest__input', query (val) {
onInputChange: this.fetchResults, this.fetchResults(val)
placeholder: 'Search...',
class: 'form-control'
},
suggestions: []
} }
}, },
methods: { methods: {
fetchResults (query) { fetchResults (query) {
clearTimeout(this.timeout) clearTimeout(this.timeout)
this.timeout = setTimeout(() => { this.timeout = setTimeout(() => {
userSearchApi.search({query, store: this.$store}) this.results = []
.then((data) => { this.suggestions = [{ data }] }) if (query) {
}, this.debounceMilliseconds) userSearchApi.search({query, store: this.$store})
}, .then((data) => { this.results = data })
clickHandler (item) { }
return false }, debounceMilliseconds)
},
clickUserHandler () {
console.log('clickUserHandler')
return false
} }
} }
} }

View File

@ -1,93 +1,27 @@
<template> <template>
<div class="user-autosuggest"> <div class="user-autocomplete-search">
<VueAutosuggest <input v-model="query" placeholder="Search..." />
:suggestions="suggestions" <div class="user-autocomplete-search-results">
:inputProps="inputProps" <BasicUserCard v-for="user in results" :key="user.id" :user="user"/>
@click="clickHandler" </div>
>
<template slot-scope="{suggestion}">
<BasicUserCard :user="suggestion.item" />
</template>
</VueAutosuggest>
</div> </div>
</template> </template>
<script src="./user_autosuggest.js"></script> <script src="./user_autosuggest.js"></script>
<style lang="scss"> <style lang="scss">
.user-autosuggest { .user-autocomplete-search {
.avatar { position: relative;
height: 25px;
width: 25px;
border-radius: 20px;
margin-right: 10px;
}
#autosuggest__input {
outline: none;
position: relative;
display: block;
border: 1px solid #616161;
padding: 10px;
width: 100%;
box-sizing: border-box;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
}
#autosuggest__input.autosuggest__input-open { &-results {
border-bottom-left-radius: 0;
border-bottom-right-radius: 0;
}
.autosuggest__results-container {
position: relative;
width: 100%;
}
.autosuggest__results {
font-weight: 300;
margin: 0;
position: absolute; position: absolute;
z-index: 10000001; left: 0;
width: 100%; top: 100%;
border: 1px solid #e0e0e0; right: 0;
border-bottom-left-radius: 4px; background: #FFF;
border-bottom-right-radius: 4px;
background: white;
padding: 0px;
max-height: 400px; max-height: 400px;
overflow-y: scroll; overflow-y: auto;
} z-index: 1;
.autosuggest__results ul {
list-style: none;
padding-left: 0;
margin: 0;
}
.autosuggest__results .autosuggest__results_item {
cursor: pointer;
padding: 15px;
}
#autosuggest ul:nth-child(1) > .autosuggest__results_title {
border-top: none;
}
.autosuggest__results .autosuggest__results_title {
color: gray;
font-size: 11px;
margin-left: 0;
padding: 15px 13px 5px;
border-top: 1px solid lightgray;
}
.autosuggest__results .autosuggest__results_item:active,
.autosuggest__results .autosuggest__results_item:hover,
.autosuggest__results .autosuggest__results_item:focus,
.autosuggest__results
.autosuggest__results_item.autosuggest__results_item-highlighted {
background-color: #f6f6f6;
} }
} }
</style> </style>