|
1 |
| -<div x-data="{ results: false, threads: [], articles: [] }"> |
| 1 | +<div x-data="searchConfig()"> |
2 | 2 | <label for="search" class="sr-only">Search</label>
|
3 | 3 |
|
4 | 4 | <div class="relative">
|
|
7 | 7 | </div>
|
8 | 8 |
|
9 | 9 | <input
|
10 |
| - @click.outside="results = false" |
11 |
| - @keyup="window.search(event).then(function({ results: hits }) { results = true; threads = hits[0].hits; articles = hits[1].hits; })" |
| 10 | + @click.outside="show = false" |
| 11 | + @keyup.escape="show = false" |
| 12 | + @keyup="search(event.target.value)" |
12 | 13 | type="search"
|
13 | 14 | name="search"
|
14 | 15 | id="search"
|
15 | 16 | class="border-0 border-t border-b block pl-10 border-gray-300 md:border md:rounded w-full"
|
16 | 17 | placeholder="Search for threads and articles..."
|
17 | 18 | />
|
18 | 19 |
|
19 |
| - <template x-if="results"> |
20 |
| - <div class="search absolute md:origin-top-right md:right-0 md:rounded md:shadow-lg bg-white md:mt-2 z-50"> |
21 |
| - <div class="flex flex-col md:flex-row"> |
22 |
| - <div class="w-full flex-none border-r border-b md:w-1/2"> |
23 |
| - <div class="flex text-lg font-medium border-b p-4"> |
24 |
| - <span class="text-gray-900 mr-3">Threads</span> |
| 20 | + <div x-show="show" x-cloak class="search absolute md:origin-top-right md:right-0 md:rounded md:shadow-lg bg-white md:mt-2 z-50"> |
| 21 | + <div class="flex flex-col md:flex-row"> |
| 22 | + <div class="w-full flex-none border-r border-b md:w-1/2"> |
| 23 | + <div class="flex text-lg font-medium border-b p-4"> |
| 24 | + <span class="text-gray-900 mr-3">Threads</span> |
25 | 25 |
|
26 |
| - <span class="text-gray-300" x-text="threads.length + ' Results'"></span> |
27 |
| - </div> |
28 |
| - |
29 |
| - <div class="max-h-72 overflow-y-scroll"> |
30 |
| - <template x-for="thread in threads" :key="thread.subject"> |
31 |
| - <a :href="'/forum/'+thread.slug" class="flex flex-col px-4 py-2 hover:bg-lio-100"> |
32 |
| - <span class="text-black-900 text-lg font-medium break-all" x-html="thread._highlightResult.subject.value"></span> |
33 |
| - <span class="text-black-900 break-all" x-html="thread._snippetResult.body.value"></span> |
34 |
| - </a> |
35 |
| - </template> |
36 |
| - </div> |
| 26 | + <span class="text-gray-300" x-text="threads.formattedTotal()"></span> |
| 27 | + </div> |
37 | 28 |
|
38 |
| - <span x-show="threads.length === 0" x-cloak class="p-4 text-gray-500 block"> |
39 |
| - No threads found |
40 |
| - </span> |
| 29 | + <div class="max-h-72 overflow-y-scroll"> |
| 30 | + <template x-for="thread in threads.threads"> |
| 31 | + <a :href="'/forum/'+thread.slug" class="flex flex-col px-4 py-2 hover:bg-lio-100"> |
| 32 | + <span class="text-black-900 text-lg font-medium break-all" x-html="thread._highlightResult.subject.value"></span> |
| 33 | + <span class="text-black-900 break-all" x-html="thread._snippetResult.body.value"></span> |
| 34 | + </a> |
| 35 | + </template> |
41 | 36 | </div>
|
42 | 37 |
|
43 |
| - <div class="w-full flex-none border-b md:w-1/2"> |
44 |
| - <div class="flex text-lg font-medium border-b p-4"> |
45 |
| - <span class="text-gray-900 mr-3">Articles</span> |
| 38 | + <span x-show="threads.length === 0" x-cloak class="p-4 text-gray-500 block"> |
| 39 | + No threads found |
| 40 | + </span> |
| 41 | + </div> |
46 | 42 |
|
47 |
| - <span class="text-gray-300" x-text="threads.length + ' Results'"></span> |
48 |
| - </div> |
| 43 | + <div class="w-full flex-none border-b md:w-1/2"> |
| 44 | + <div class="flex text-lg font-medium border-b p-4"> |
| 45 | + <span class="text-gray-900 mr-3">Articles</span> |
49 | 46 |
|
50 |
| - <div class="max-h-72 overflow-y-scroll"> |
51 |
| - <template x-for="article in articles" :key="article.title"> |
52 |
| - <a :href="'/articles/'+article.slug" class="flex flex-col px-4 py-2 hover:bg-lio-100"> |
53 |
| - <span class="text-black-900 text-lg font-medium break-all" x-html="article._highlightResult.title.value"></span> |
54 |
| - <span class="text-black-900 break-all" x-html="article._snippetResult.body.value"></span> |
55 |
| - </a> |
56 |
| - </template> |
57 |
| - </div> |
| 47 | + <span class="text-gray-300" x-text="articles.formattedTotal()"></span> |
| 48 | + </div> |
58 | 49 |
|
59 |
| - <span x-show="articles.length === 0" x-cloak class="p-4 text-gray-500 block"> |
60 |
| - No articles found |
61 |
| - </span> |
| 50 | + <div class="max-h-72 overflow-y-scroll"> |
| 51 | + <template x-for="article in articles.articles"> |
| 52 | + <a :href="'/articles/'+article.slug" class="flex flex-col px-4 py-2 hover:bg-lio-100"> |
| 53 | + <span class="text-black-900 text-lg font-medium break-all" x-html="article._highlightResult.title.value"></span> |
| 54 | + <span class="text-black-900 break-all" x-html="article._snippetResult.body.value"></span> |
| 55 | + </a> |
| 56 | + </template> |
62 | 57 | </div>
|
63 |
| - </div> |
64 | 58 |
|
65 |
| - <a href="https://algolia.com" class="flex justify-end px-4 py-2"> |
66 |
| - <img src="{{ asset('images/algolia.svg') }}" class="h-4 mx-4 my-2" /> |
67 |
| - </a> |
| 59 | + <span x-show="articles.length === 0" x-cloak class="p-4 text-gray-500 block"> |
| 60 | + No articles found |
| 61 | + </span> |
| 62 | + </div> |
68 | 63 | </div>
|
69 |
| - </template> |
| 64 | + |
| 65 | + <a href="https://algolia.com" class="flex justify-end px-4 py-2"> |
| 66 | + <img src="{{ asset('images/algolia.svg') }}" class="h-4 mx-4 my-2" /> |
| 67 | + </a> |
| 68 | + </div> |
70 | 69 | </div>
|
71 | 70 | </div>
|
0 commit comments