11<template >
2- <form id =" search-form" class =" drawer-header__input" >
3- <input :value =" modelValue"
2+ <form id =" search-form" class =" drawer-header__input" @submit.prevent =" performSearch" >
3+ <input type =" text"
4+ :value =" modelValue"
45 @input =" $emit('update:modelValue', $event.target.value)"
56 id =" algolia-search-input"
67 :placeholder =" placeholder"
78 :class =" activeSearchClass"
8- @keypress.enter.prevent = " performSearch "
9+ maxlength = " 100 "
910 />
1011 <div :class =" activeSearchIconClass" >
11- <img @click =" performSearch" alt =" search icon" :src =" withBase(activeSearchIcon)" />
12+ <img v-if =" !loading" @click =" performSearch" alt =" search icon" :src =" withBase(activeSearchIcon)" />
13+ <div v-if =" loading" class =" spinner" ></div >
1214 </div >
1315 </form >
1416</template >
@@ -129,7 +131,8 @@ function parseDocs(api_response) {
129131
130132async function queryGlobalSearch (query , n_results = 10 ) {
131133 const baseUrl = ' https://global-search.cl-edu.com/search' ;
132- let url = ` ${ baseUrl} ?query=${ query} &collections=cloudlinux_docs&n_results=${ n_results} &source=cloudlinux_docs` ;
134+ let urlEncodedQuery = encodeURIComponent (query);
135+ let url = ` ${ baseUrl} ?query=${ urlEncodedQuery} &collections=cloudlinux_docs&n_results=${ n_results} &source=cloudlinux_docs` ;
133136 try {
134137 const response = await fetch (url);
135138 if (! response .ok ) {
@@ -143,11 +146,14 @@ async function queryGlobalSearch(query, n_results=10) {
143146 }
144147}
145148
149+ const loading = ref (false ); // Reactive variable for loading state
150+
146151const performSearch = async () => {
152+ loading .value = true ; // Set loading to true when search starts
147153 const data = await queryGlobalSearch (props .modelValue , MAX_HITS_PER_PAGE );
154+ loading .value = false ; // Set loading to false when search finishes
148155 if (data) {
149156 const hits = parseDocs (data);
150- console .log (hits); // Log the results data structure
151157 emit (' result' , hits);
152158 emit (' openDrawer' );
153159 }
@@ -222,4 +228,18 @@ watch(
222228 width 75 %
223229 .header - layout__search- title
224230 text- align center
231+
232+ .spinner
233+ border 4px solid rgba (0 , 0 , 0 , 0.1 )
234+ border- top 4px solid #3498db
235+ border- radius 50 %
236+ width 20px
237+ height 20px
238+ animation spin 1s linear infinite
239+
240+ @keyframes spin
241+ 0 %
242+ transform rotate (0deg )
243+ 100 %
244+ transform rotate (360deg )
225245< / style>
0 commit comments