Skip to content

Commit d55a933

Browse files
committed
Add direct link to product from search result
1 parent 58753d6 commit d55a933

File tree

1 file changed

+34
-24
lines changed

1 file changed

+34
-24
lines changed

components/Search/SearchResults.component.jsx

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import Link from 'next/link';
2+
13
/**
24
* Displays search results from Algolia
35
* @param {Object} props
@@ -10,34 +12,42 @@ const SearchResults = ({
1012
sale_price,
1113
on_sale,
1214
short_description,
15+
objectID,
1316
},
1417
}) => {
1518
return (
16-
<article className="hit">
17-
<div className="flex p-6 bg-white">
18-
<header className="hit-image-container">
19-
<img
20-
src={product_image}
21-
alt={product_name}
22-
className="w-12 hit-image"
23-
/>
24-
</header>
25-
<div className="pl-4 text-left">
26-
{product_name && (
27-
<span class="text-lg font-bold">{product_name}</span>
28-
)}
29-
<br />
30-
{on_sale && (
31-
<>
32-
<span className="text-base line-through">kr {regular_price}</span>
33-
<span className="ml-2 text-base">kr {sale_price}</span>
34-
</>
35-
)}
36-
{!on_sale && <span className="text-base">kr {regular_price}</span>}
37-
<br />
38-
<span className="text-base">{short_description}</span>
19+
<article className="cursor-pointer hit">
20+
<Link
21+
href="/produkt/[post]"
22+
as={`/produkt/${product_name}?productId=${objectID}`}
23+
>
24+
<div className="flex p-6 bg-white">
25+
<header className="hit-image-container">
26+
<img
27+
src={product_image}
28+
alt={product_name}
29+
className="w-12 hit-image"
30+
/>
31+
</header>
32+
<div className="pl-4 text-left">
33+
{product_name && (
34+
<span class="text-lg font-bold">{product_name}</span>
35+
)}
36+
<br />
37+
{on_sale && (
38+
<>
39+
<span className="text-base line-through">
40+
kr {regular_price}
41+
</span>
42+
<span className="ml-2 text-base">kr {sale_price}</span>
43+
</>
44+
)}
45+
{!on_sale && <span className="text-base">kr {regular_price}</span>}
46+
<br />
47+
<span className="text-base">{short_description}</span>
48+
</div>
3949
</div>
40-
</div>
50+
</Link>
4151
</article>
4252
);
4353
};

0 commit comments

Comments
 (0)