Files
habitica/website/client/components/chat/autoComplete.vue
Keith Holliday a317b351be Sept 23 fixes (#9074)
* Discover challenges

* Fixed hero loading

* Moved add task button

* Fixed bailey showing

* Added logs for bad sub data

* Fixed blurb editing

* Added confirmation for deleteing message

* Reset invite modals on invite

* fixed group member sorting

* Fixed chat time styles

* Fixed hover on liked

* Fixed like count

* Added reverse

* Fixed editing party

* Added leader conditions

* Added search

* Added loading

* Reset members when leaving party

* Rounded pending

* Fixed overflow on collecting quests

* Added to invite friends

* Hid summary from party

* Fixed button styles

* Fixed button class

* Removed okay button

* Fixed renav for profile modal

* Added subscription back to menu

* Fixed static link

* Added daily due setting

* Added local auth adding

* Fixed centering of text

* Removed message locally

* Added count for new message

* Added style fix for profile pet

* Fixed achievement popovers

* Fixed white boxes

* Added plain color backgrounds

* fixed challenge mutability

* Fixed challenge editing

* Added notation for large numbers

* Add color text to guild sizes

* Removed membership filters from discover challenges

* Added invites to group

* Cmd + enter send message

* Made leader clickable

* Updated group validation

* Added cancelling autocomplete

* Added mention icon

* Added removing member

* Removed extra string
2017-09-25 13:02:12 -05:00

81 lines
2.1 KiB
Vue

<template lang="pug">
div.autocomplete-selection(v-if='searchResults.length > 0', :style='autocompleteStyle')
.autocomplete-results(v-for='result in searchResults', @click='select(result)') {{ result }}
</template>
<style scoped>
.autocomplete-results {
padding: .5em;
box-shadow: 1px 1px 1px #efefef;
}
</style>
<script>
import groupBy from 'lodash/groupBy';
export default {
props: ['selections', 'text', 'coords', 'chat'],
data () {
return {
currentSearch: '',
searchActive: false,
currentSearchPosition: 0,
tmpSelections: [],
};
},
computed: {
autocompleteStyle () {
return {
top: `${this.coords.TOP + 30}px`,
left: `${this.coords.LEFT + 30}px`,
position: 'absolute',
minWidth: '100px',
minHeight: '100px',
zIndex: 100,
backgroundColor: 'white',
};
},
searchResults () {
if (!this.searchActive) return [];
let currentSearch = this.text.substring(this.currentSearchPosition + 1, this.text.length);
return this.tmpSelections.filter((option) => {
return option.toLowerCase().indexOf(currentSearch.toLowerCase()) !== -1;
});
},
},
mounted () {
this.grabUserNames();
},
watch: {
text (newText) {
if (!newText[newText.length - 1] || newText[newText.length - 1] === ' ') {
this.searchActive = false;
}
if (newText[newText.length - 1] !== '@') return;
this.searchActive = true;
this.currentSearchPosition = newText.length - 1;
},
chat () {
this.grabUserNames();
},
},
methods: {
grabUserNames () {
let usersThatMessage = groupBy(this.chat, 'user');
for (let userName in usersThatMessage) {
let systemMessage = userName === 'undefined';
if (!systemMessage && this.tmpSelections.indexOf(userName) === -1) {
this.tmpSelections.push(userName);
}
}
},
select (result) {
let newText = this.text.slice(0, this.currentSearchPosition + 1) + result;
this.searchActive = false;
this.$emit('select', newText);
},
},
};
</script>