Skip to content
This repository was archived by the owner on Jan 14, 2024. It is now read-only.

Commit 387053b

Browse files
Merge branch 'MarkosKon-highlight-clear-input' into develop
2 parents fc31bac + a6e04c3 commit 387053b

File tree

4 files changed

+49
-18
lines changed

4 files changed

+49
-18
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"react": "^16.8.6",
3131
"react-dom": "^16.8.6",
3232
"react-helmet": "^5.2.0",
33+
"react-highlight-words": "^0.16.0",
3334
"react-typography": "^0.16.19",
3435
"typeface-merriweather": "0.0.72",
3536
"typeface-montserrat": "0.0.54",

src/components/searchResults.js

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,45 @@
1-
import React from 'react';
1+
import React from "react"
2+
import Highlighter from "react-highlight-words"
23

34
const SearchResults = ({ query, results }) => (
45
<section aria-label="Search results for all posts">
5-
{!!results.length && query &&
6+
{!!results.length && query && (
67
<h2
78
className="search-results-count"
89
id="search-results-count"
910
aria-live="assertive"
10-
>Found {results.length} posts on "{query}"</h2>
11-
}
12-
{!!results.length &&
11+
>
12+
Found {results.length} posts on "{query}"
13+
</h2>
14+
)}
15+
{!!results.length && (
1316
<ol className="search-results-list">
14-
{results.map(({
15-
title,
16-
url,
17-
date,
18-
description
19-
}) => (
17+
{results.map(({ title, url, date, description }) => (
2018
<li key={title}>
2119
<h3 className="search-results-list__heading">
2220
<a href={url} className="search-results-list__link">
23-
{title}
21+
<Highlighter
22+
searchWords={[query]}
23+
autoEscape={true}
24+
textToHighlight={title}
25+
/>
2426
</a>
2527
</h3>
26-
<small>{(new Date(date).toLocaleString('en-GB'))}</small>
27-
{description && <p>{description}</p>}
28+
<small>{new Date(date).toLocaleString("en-GB")}</small>
29+
{description && (
30+
<p>
31+
<Highlighter
32+
searchWords={[query]}
33+
autoEscape={true}
34+
textToHighlight={description}
35+
/>
36+
</p>
37+
)}
2838
</li>
2939
))}
3040
</ol>
31-
}
41+
)}
3242
</section>
33-
);
43+
)
3444

35-
export default SearchResults;
45+
export default SearchResults

src/pages/search.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const Search = ({
1818
setResults(posts);
1919
});
2020
}
21+
if (!searchQuery) setResults([])
2122
}, [location.search]);
2223

2324
return (

yarn.lock

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5628,6 +5628,11 @@ hex-color-regex@^1.1.0:
56285628
resolved "https://registry.yarnpkg.com/hex-color-regex/-/hex-color-regex-1.1.0.tgz#4c06fccb4602fe2602b3c93df82d7e7dbf1a8a8e"
56295629
integrity sha512-l9sfDFsuqtOqKDsQdqrMRk0U85RZc0RtOR9yPI7mRVOa4FsR/BVnZ0shmQRM96Ji99kYZP/7hn1cedc1+ApsTQ==
56305630

5631+
highlight-words-core@^1.2.0:
5632+
version "1.2.2"
5633+
resolved "https://registry.yarnpkg.com/highlight-words-core/-/highlight-words-core-1.2.2.tgz#1eff6d7d9f0a22f155042a00791237791b1eeaaa"
5634+
integrity sha512-BXUKIkUuh6cmmxzi5OIbUJxrG8OAk2MqoL1DtO3Wo9D2faJg2ph5ntyuQeLqaHJmzER6H5tllCDA9ZnNe9BVGg==
5635+
56315636
hmac-drbg@^1.0.0:
56325637
version "1.0.1"
56335638
resolved "https://registry.yarnpkg.com/hmac-drbg/-/hmac-drbg-1.0.1.tgz#d2745701025a6c775a6c545793ed502fc0c649a1"
@@ -7296,6 +7301,11 @@ mem@^4.0.0:
72967301
mimic-fn "^2.0.0"
72977302
p-is-promise "^2.0.0"
72987303

7304+
memoize-one@^4.0.0:
7305+
version "4.1.0"
7306+
resolved "https://registry.yarnpkg.com/memoize-one/-/memoize-one-4.1.0.tgz#a2387c58c03fff27ca390c31b764a79addf3f906"
7307+
integrity sha512-2GApq0yI/b22J2j9rhbrAlsHb0Qcz+7yWxeLG8h+95sl1XPUgeLimQSOdur4Vw7cUhrBHwaUZxWFZueojqNRzA==
7308+
72997309
memory-fs@^0.4.0, memory-fs@^0.4.1, memory-fs@~0.4.1:
73007310
version "0.4.1"
73017311
resolved "https://registry.yarnpkg.com/memory-fs/-/memory-fs-0.4.1.tgz#3a9a20b8462523e447cfbc7e8bb80ed667bfc552"
@@ -9088,7 +9098,7 @@ prompts@^2.0.4:
90889098
kleur "^3.0.2"
90899099
sisteransi "^1.0.0"
90909100

9091-
prop-types@^15.5.4, prop-types@^15.6.1, prop-types@^15.6.2:
9101+
prop-types@^15.5.4, prop-types@^15.5.8, prop-types@^15.6.1, prop-types@^15.6.2:
90929102
version "15.7.2"
90939103
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.7.2.tgz#52c41e75b8c87e72b9d9360e0206b99dcbffa6c5"
90949104
integrity sha512-8QQikdH7//R2vurIJSutZ1smHYTcLpRWEOlHnzcWHmBYrOGUysKwSsrC89BCiFj3CbrfJ/nXFdJepOVrY1GCHQ==
@@ -9320,6 +9330,15 @@ react-helmet@^5.2.0:
93209330
prop-types "^15.5.4"
93219331
react-side-effect "^1.1.0"
93229332

9333+
react-highlight-words@^0.16.0:
9334+
version "0.16.0"
9335+
resolved "https://registry.yarnpkg.com/react-highlight-words/-/react-highlight-words-0.16.0.tgz#4b4b9824e3d2b98789d3e3b3aedb5e961ae1b7cf"
9336+
integrity sha512-q34TwCSJOL+5pVDv6LUj3amaoyXdNDwd7zRqVAvceOrO9g1haWLAglK6WkGLMNUa3PFN8EgGedLg/k8Gpndxqg==
9337+
dependencies:
9338+
highlight-words-core "^1.2.0"
9339+
memoize-one "^4.0.0"
9340+
prop-types "^15.5.8"
9341+
93239342
react-hot-loader@^4.6.2:
93249343
version "4.8.4"
93259344
resolved "https://registry.yarnpkg.com/react-hot-loader/-/react-hot-loader-4.8.4.tgz#357ba342e367fd42d6a870a9c0601c23fa0730c6"

0 commit comments

Comments
 (0)