-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
133 lines (124 loc) · 4.27 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import Head from 'next/head'
import { Center, Footer, Tag, Showcase, DisplaySmall, DisplayMedium } from '../components'
import { titleIfy, slugify } from '../utils/helpers'
import { fetchInventory } from '../utils/inventoryProvider'
import CartLink from '../components/CartLink'
const Home = ({ inventoryData = [], categories: categoryData = [] }) => {
const inventory = inventoryData.slice(0, 4)
const categories = categoryData.slice(0, 2)
return (
<>
<CartLink />
<div className="w-full">
<Head>
<title>Jamstack ECommerce</title>
<meta name="description" content="Jamstack ECommerce Next provides a way to quickly get up and running with a fully configurable ECommerce site using Next.js." />
<meta property="og:title" content="Jamstack ECommerce" key="title" />
</Head>
<div className="bg-blue-300
p-6 pb-10 smpb-6
flex lg:flex-row flex-col">
<div className="pt-4 pl-2 sm:pt-12 sm:pl-12 flex flex-col">
<Tag
year="2021"
category="SOFAS"
/>
<Center
price="200"
title={inventory[2].name}
link={`/product/${slugify(inventory[2].name)}`}
/>
<Footer
designer="Jason Bourne"
/>
</div>
<div className="flex flex-1 justify-center items-center relative">
<Showcase
imageSrc={inventory[2].image}
/>
<div className="absolute
w-48 h-48 sm:w-72 sm:h-72 xl:w-88 xl:h-88
bg-white z-0 rounded-full" />
</div>
</div>
</div>
<div className="
lg:my-8 lg:grid-cols-2
grid-cols-1
grid gap-4 my-4
">
<DisplayMedium
imageSrc={categories[0].image}
subtitle={`${categories[0].itemCount} items`}
title={titleIfy(categories[0].name)}
link={`/category/${slugify(categories[0].name)}`}
/>
<DisplayMedium
imageSrc={categories[1].image}
subtitle={`${categories[1].itemCount} items`}
title={titleIfy(categories[1].name)}
link={`/category/${slugify(categories[1].name)}`}
/>
</div>
<div className="pt-10 pb-6 flex flex-col items-center">
<h2 className="text-4xl mb-3">Trending Now</h2>
<p className="text-gray-600 text-sm">Find the perfect piece or accessory to finish off your favorite room in the house.</p>
</div>
<div className="my-8 flex flex-col lg:flex-row justify-between">
<DisplaySmall
imageSrc={inventory[0].image}
title={inventory[0].name}
subtitle={inventory[0].categories[0]}
link={`/product/${slugify(inventory[0].name)}`}
/>
<DisplaySmall
imageSrc={inventory[1].image}
title={inventory[1].name}
subtitle={inventory[1].categories[0]}
link={`/product/${slugify(inventory[1].name)}`}
/>
<DisplaySmall
imageSrc={inventory[2].image}
title={inventory[2].name}
subtitle={inventory[2].categories[0]}
link={`/product/${slugify(inventory[2].name)}`}
/>
<DisplaySmall
imageSrc={inventory[3].image}
title={inventory[3].name}
subtitle={inventory[3].categories[0]}
link={`/product/${slugify(inventory[3].name)}`}
/>
</div>
</>
)
}
export async function getStaticProps() {
const inventory = await fetchInventory()
const inventoryCategorized = inventory.reduce((acc, next) => {
const categories = next.categories
categories.forEach(c => {
const index = acc.findIndex(item => item.name === c)
if (index !== -1) {
const item = acc[index]
item.itemCount = item.itemCount + 1
acc[index] = item
} else {
const item = {
name: c,
image: next.image,
itemCount: 1
}
acc.push(item)
}
})
return acc
}, [])
return {
props: {
inventoryData: inventory,
categories: inventoryCategorized
}
}
}
export default Home