connect search box with result page
This commit is contained in:
@@ -70,6 +70,9 @@ export default {
|
|||||||
default: true,
|
default: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
mounted() {
|
||||||
|
// console.log(this.record)
|
||||||
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="fixed inset-0 h-16 bg-black">
|
<div class="fixed inset-0 h-16 bg-black">
|
||||||
<header class="container sm:flex sm:items-center sm:px-4 sm:py-3 mx-auto">
|
<header
|
||||||
|
class="flex items-center justify-between flex-wrap container mx-auto px-4 sm:px-0 py-4 transition-all transition-500"
|
||||||
|
v-bind:class="{
|
||||||
|
'opacity-100': !disableScroll && scrollPosition > headerHeight,
|
||||||
|
'opacity-0': !disableScroll && scrollPosition < headerHeight,
|
||||||
|
}"
|
||||||
|
>
|
||||||
<div class="flex items-center justify-between px-4 py-3 sm:p-0">
|
<div class="flex items-center justify-between px-4 py-3 sm:p-0">
|
||||||
<div class="inline-flex items-center flex-shrink-0 text-white mr-6">
|
<div class="inline-flex items-center flex-shrink-0 text-white mr-6">
|
||||||
<a href="/" class="flex">
|
<a href="/" class="flex">
|
||||||
@@ -94,16 +100,18 @@
|
|||||||
}}</g-link>
|
}}</g-link>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<div class="md:hidden inline-flex rounded-full border-grey-light border w-1/2">
|
<div
|
||||||
<button>
|
class="md:hidden inline-flex rounded-full border-grey-light border w-1/2"
|
||||||
<span class="w-auto flex justify-end items-center text-grey p-2">
|
>
|
||||||
<font-awesome :icon="['fas', 'search']" />
|
<span class="w-auto flex justify-end items-center text-grey p-2">
|
||||||
</span>
|
<font-awesome :icon="['fas', 'search']" />
|
||||||
</button>
|
</span>
|
||||||
<input
|
<input
|
||||||
class="w-full rounded mr-4 bg-black"
|
class="w-full rounded mr-4 bg-black"
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="Search..."
|
placeholder="Search..."
|
||||||
|
v-model="search"
|
||||||
|
@keyup.enter="result"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
@@ -111,15 +119,15 @@
|
|||||||
class="hidden text-gray-400 md:ml-auto md:inline-block md:order-last"
|
class="hidden text-gray-400 md:ml-auto md:inline-block md:order-last"
|
||||||
>
|
>
|
||||||
<div class="inline-flex rounded-full border-grey-light border w-1/2">
|
<div class="inline-flex rounded-full border-grey-light border w-1/2">
|
||||||
<button>
|
<span class="w-auto flex justify-end items-center text-grey p-2">
|
||||||
<span class="w-auto flex justify-end items-center text-grey p-2">
|
<font-awesome :icon="['fas', 'search']" />
|
||||||
<font-awesome :icon="['fas', 'search']" />
|
</span>
|
||||||
</span>
|
|
||||||
</button>
|
|
||||||
<input
|
<input
|
||||||
class="w-full rounded mr-4 bg-black"
|
class="w-full rounded mr-4 bg-black"
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="Search..."
|
placeholder="Search..."
|
||||||
|
v-model="search"
|
||||||
|
@keyup.enter="result"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<ul class="list-none inline-flex justify-center md:justify-end">
|
<ul class="list-none inline-flex justify-center md:justify-end">
|
||||||
@@ -176,6 +184,7 @@ export default {
|
|||||||
scrollPosition: null,
|
scrollPosition: null,
|
||||||
headerHeight: 0,
|
headerHeight: 0,
|
||||||
isOpen: false,
|
isOpen: false,
|
||||||
|
search: "",
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -186,6 +195,9 @@ export default {
|
|||||||
setHeaderHeight(height) {
|
setHeaderHeight(height) {
|
||||||
this.headerHeight = height;
|
this.headerHeight = height;
|
||||||
},
|
},
|
||||||
|
result() {
|
||||||
|
window.location.href = `/search?query=${this.search}`;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
@@ -216,7 +228,8 @@ query {
|
|||||||
</static-query>
|
</static-query>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
input:focus {
|
input:focus,
|
||||||
|
button:focus {
|
||||||
outline: 0;
|
outline: 0;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
@@ -2,10 +2,14 @@
|
|||||||
<Layout>
|
<Layout>
|
||||||
<div class="container sm:pxi-0 mx-auto overflow-x-hidden">
|
<div class="container sm:pxi-0 mx-auto overflow-x-hidden">
|
||||||
<div class="flex flex-wrap with-large pt-8 pb-8 mx-4 sm:-mx-4">
|
<div class="flex flex-wrap with-large pt-8 pb-8 mx-4 sm:-mx-4">
|
||||||
<PostListItem v-for="edge in searchResults" :key="edge.node.id" :record="edge.node" />
|
<PostListItem
|
||||||
|
v-for="edge in searchResults"
|
||||||
|
:key="edge.node.id"
|
||||||
|
:record="edge.node"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!-- <div class="pagination flex justify-center mb-8">
|
<!-- <div class="pagination flex justify-center mb-8">
|
||||||
<Pagination
|
<Pagination
|
||||||
:baseUrl="baseurl"
|
:baseUrl="baseurl"
|
||||||
:currentPage="searchResults.pageInfo.currentPage"
|
:currentPage="searchResults.pageInfo.currentPage"
|
||||||
@@ -14,32 +18,34 @@
|
|||||||
v-if="searchResults.pageInfo.totalPages > 1"
|
v-if="searchResults.pageInfo.totalPages > 1"
|
||||||
/>
|
/>
|
||||||
</div> -->
|
</div> -->
|
||||||
{{searchResults}}
|
{{ searchResults }}
|
||||||
</Layout>
|
</Layout>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import PostListItem from '~/components/PostListItem.vue';
|
import PostListItem from "~/components/PostListItem.vue";
|
||||||
import Pagination from "~/components/Pagination.vue";
|
import Pagination from "~/components/Pagination.vue";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
metaInfo: {
|
metaInfo: {
|
||||||
title: "Search"
|
title: "Search",
|
||||||
},
|
},
|
||||||
data: () => ({
|
data: () => ({
|
||||||
q: 'the'
|
q: "the",
|
||||||
}),
|
}),
|
||||||
computed: {
|
computed: {
|
||||||
searchResults () {
|
searchResults() {
|
||||||
const searchTerm = this.q
|
const searchTerm = this.q;
|
||||||
if (searchTerm.length < 3) return []
|
if (searchTerm.length < 3) return [];
|
||||||
return this.$search.search({ query: searchTerm, limit: 5 })
|
return this.$search.search({ query: searchTerm, limit: 5 });
|
||||||
}
|
},
|
||||||
|
},
|
||||||
|
mounted() {
|
||||||
|
this.q = new URL(location.href).searchParams.get("query");
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
PostListItem,
|
PostListItem,
|
||||||
Pagination
|
Pagination,
|
||||||
},
|
},
|
||||||
|
};
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user