Make search work correctly when clicking on results
This commit is contained in:
parent
31092df5df
commit
201c8a7c4c
|
@ -5,15 +5,14 @@
|
||||||
Pterodactyl
|
Pterodactyl
|
||||||
</router-link>
|
</router-link>
|
||||||
</div>
|
</div>
|
||||||
<div class="search-box flex-none" v-if="$route.name !== 'dashboard'">
|
<div class="search-box flex-none" v-if="$route.name !== 'dashboard'" ref="searchContainer">
|
||||||
<input type="text" class="search-input" id="searchInput" placeholder="Search..."
|
<input type="text" class="search-input" id="searchInput" placeholder="Search..."
|
||||||
:class="{ 'has-search-results': (servers.length > 0 || loadingResults) && searchActive }"
|
:class="{ 'has-search-results': ((servers.length > 0 && searchTerm.length >= 3) || loadingResults) && searchActive }"
|
||||||
v-on:focus="searchActive = true"
|
v-on:focus="searchActive = true"
|
||||||
v-on:blur="searchActive = false"
|
|
||||||
v-on:input="search"
|
v-on:input="search"
|
||||||
v-model="searchTerm"
|
v-model="searchTerm"
|
||||||
/>
|
/>
|
||||||
<div class="search-results select-none" :class="{ 'hidden': (servers.length === 0 && !loadingResults) || !searchActive }">
|
<div class="search-results select-none" :class="{ 'hidden': (servers.length === 0 && !loadingResults) || !searchActive || searchTerm.length < 3 }">
|
||||||
<div v-if="loadingResults">
|
<div v-if="loadingResults">
|
||||||
<a href="#">
|
<a href="#">
|
||||||
<div class="flex items-center">
|
<div class="flex items-center">
|
||||||
|
@ -26,12 +25,8 @@
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div v-else>
|
<div v-else v-for="server in servers" :key="server.identifier">
|
||||||
<router-link
|
<router-link :to="{ name: 'server', params: { id: server.identifier }}" v-on:click.native="searchActive = false">
|
||||||
v-for="server in servers"
|
|
||||||
:key="server.identifier"
|
|
||||||
:to="{ name: 'server', params: { id: server.identifier } }"
|
|
||||||
>
|
|
||||||
<div class="flex items-center">
|
<div class="flex items-center">
|
||||||
<div class="flex-1">
|
<div class="flex-1">
|
||||||
<span class="font-bold text-grey-darkest">{{ server.name }}</span><br />
|
<span class="font-bold text-grey-darkest">{{ server.name }}</span><br />
|
||||||
|
@ -100,9 +95,17 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
created: function () {
|
||||||
|
document.addEventListener('click', this.documentClick);
|
||||||
|
},
|
||||||
|
|
||||||
|
beforeDestroy: function () {
|
||||||
|
document.removeEventListener('click', this.documentClick);
|
||||||
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
search: debounce(function () {
|
search: debounce(function () {
|
||||||
if (this.searchTerm.length > 3) {
|
if (this.searchTerm.length >= 3) {
|
||||||
this.loadingResults = true;
|
this.loadingResults = true;
|
||||||
this.gatherSearchResults(this.searchTerm);
|
this.gatherSearchResults(this.searchTerm);
|
||||||
}
|
}
|
||||||
|
@ -110,10 +113,6 @@
|
||||||
|
|
||||||
gatherSearchResults: function () {
|
gatherSearchResults: function () {
|
||||||
this.$store.dispatch('dashboard/loadServers')
|
this.$store.dispatch('dashboard/loadServers')
|
||||||
.then(() => {
|
|
||||||
if (this.servers.length === 0) {
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
const response = err.response;
|
const response = err.response;
|
||||||
|
@ -132,6 +131,14 @@
|
||||||
this.$store.commit('auth/logout');
|
this.$store.commit('auth/logout');
|
||||||
return window.location = this.route('auth.logout');
|
return window.location = this.route('auth.logout');
|
||||||
},
|
},
|
||||||
|
|
||||||
|
documentClick: function (e) {
|
||||||
|
if (this.$refs.searchContainer) {
|
||||||
|
if (this.$refs.searchContainer !== e.target && !this.$refs.searchContainer.contains(e.target)) {
|
||||||
|
this.searchActive = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="mt-6 sidenav mr-6 bg-white border rounded">
|
<div class="mt-6 sidenav mr-6 bg-white border rounded">
|
||||||
<router-link :to="{ name: 'server', params: { id: this.$route.params.id } }">
|
<router-link :to="{ name: 'server', params: { id: $route.params.id } }">
|
||||||
<terminal-icon class="h-4"></terminal-icon> Console
|
<terminal-icon class="h-4"></terminal-icon> Console
|
||||||
</router-link>
|
</router-link>
|
||||||
<router-link :to="{ name: 'server-files' }">
|
<router-link :to="{ name: 'server-files' }">
|
||||||
|
@ -51,7 +51,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
-->
|
-->
|
||||||
<router-view></router-view>
|
<router-view :key="server.identifier"></router-view>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -87,6 +87,18 @@
|
||||||
...mapState('socket', ['connected', 'connectionError']),
|
...mapState('socket', ['connected', 'connectionError']),
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Watch for route changes that occur with different server parameters. This occurs when a user
|
||||||
|
// uses the search bar. Because of the way vue-router works, it won't re-mount the server component
|
||||||
|
// so we will end up seeing the wrong server data if we don't perform this watch.
|
||||||
|
watch: {
|
||||||
|
'$route': function (toRoute, fromRoute) {
|
||||||
|
if (toRoute.params.id !== fromRoute.params.id) {
|
||||||
|
this.loadingServerData = true;
|
||||||
|
this.loadServer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
data: function () {
|
data: function () {
|
||||||
return {
|
return {
|
||||||
loadingServerData: true,
|
loadingServerData: true,
|
||||||
|
|
Loading…
Reference in New Issue