Commit 3b3aa7e
committed
Merge #111: fix search error for no results
b6822db fix search error for no results (Graeme Byrne)
Pull request description:
Fix for [The search box in blog section does not work #108](#108). Search worked when there was a result but when the user entered something in search bar which had no result then searched again nothing would appear when the user searched for something which should return a result.
To prevent this issue, the functions in `lib/utils/search.ts` ensure that if there is no search term or no matching results, they return default values (like empty arrays or the original text) and properly handle new searches, ensuring the UI remains responsive and updates with results as expected.
```
export function searchPostsIndex(searchTerm: string) {
if (!searchTerm) {
return [];
}
```
```
function replaceTextWithMarker(text: string, match: string) {
if (!text) {
return '';
}
if (!match) {
return text;
}
```
```
function getMatches(text: string, searchTerm: string, limit = 1) {
if (!searchTerm) {
return [];
}
```
ACKs for top commit:
josecelano:
ACK b6822db
Tree-SHA512: aaa332b8b32219cca16bf5dbfa64e6ff60f61b8305d86dc424e40478837db2fc0496e1003ecfe0f697fb433db71082154f387492ff2034237c411df6ae678ba02 files changed
+18
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
33 | 37 | | |
34 | 38 | | |
35 | 39 | | |
36 | 40 | | |
37 | 41 | | |
38 | | - | |
| 42 | + | |
39 | 43 | | |
40 | 44 | | |
41 | 45 | | |
| |||
46 | 50 | | |
47 | 51 | | |
48 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
49 | 61 | | |
50 | | - | |
| 62 | + | |
51 | 63 | | |
52 | 64 | | |
53 | 65 | | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
54 | 70 | | |
55 | 71 | | |
56 | 72 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
27 | 26 | | |
28 | 27 | | |
29 | 28 | | |
| |||
0 commit comments