Skip to content

Commit e818de0

Browse files
committed
added loading indicator for search bar
1 parent caa2cb6 commit e818de0

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

docs/.vuepress/theme/drawer/Drawer.vue

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
<div class="drawer-main">
1717
<div class="drawer-main__wrapper">
1818
<div class="drawer-main__breadcrumb">
19-
<p v-if="drawerArticleResult.length" class="drawer-main__breadcrumb__text">Home
20-
<img :src="withBase('/arrows/arrow-right-breadcrumb.svg')" alt="breadcrumb icon"/>
21-
Documentation
22-
</p>
19+
<!--
20+
<p v-if="drawerArticleResult.length" class="drawer-main__breadcrumb__text">Home
21+
<img :src="withBase('/arrows/arrow-right-breadcrumb.svg')" alt="breadcrumb icon"/>
22+
Documentation
23+
</p>
24+
-->
2325
</div>
2426
<DrawerSearchResult :modelValue="modelValue" :data="drawerArticleResult"/>
2527
</div>

docs/.vuepress/theme/drawer/DrawerSearch.vue

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
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
130132
async 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+
146151
const 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

Comments
 (0)