-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreator-collection.html
214 lines (182 loc) · 7.34 KB
/
creator-collection.html
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
<script src="https://cdn.tailwindcss.com"></script>
<script>
tailwind.config = {
theme: {
extend: {
fontFamily: {
sans: ['Inter', 'sans-serif'],
},
}
}
}
</script>
</head>
<body>
<nav
class="relative w-full flex flex-wrap items-center justify-between py-3 bg-gray-900 text-gray-200 shadow-lg navbar navbar-expand-lg navbar-light">
<div class="container-fluid w-full flex flex-wrap items-center justify-between px-6">
<div class="collapse navbar-collapse flex items-center" id="navbarSupportedContent1">
<a class="text-xl text-white pr-2 font-semibold" href="index.html">HOME</a>
</div>
<div id="middleContent"></div>
<div class="flex items-center flex-col relative">
<a class="text-white opacity-60 hover:opacity-80 focus:opacity-80 mr-4">
<p>Favs</p>
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24"
stroke="currentColor" stroke-width="2">
<path fill="currentColor" stroke-linecap="round" stroke-linejoin="round"
d="M4.318 6.318a4.5 4.5 0 000 6.364L12 20.364l7.682-7.682a4.5 4.5 0 00-6.364-6.364L12 7.636l-1.318-1.318a4.5 4.5 0 00-6.364 0z" />
</svg>
</a>
</div>
</nav>
<div
class="relative w-full flex flex-wrap items-center justify-between py-3 bg-gray-100 text-gray-500 hover:text-gray-700 focus:text-gray-700 shadow-lg">
<div class="container-fluid flex justify-around w-full px-6" id="subMenu"></div>
</div>
<script src="https://cdn.jsdelivr.net/npm/tw-elements/dist/js/index.min.js"></script>
</body>
<script type="text/javascript">
const root = document.querySelector('body');
function createElement(tag, config, parent = null) {
const {
product_sales,
product_image,
product_name,
creator,
creator_picture,
product_id,
token_id,
collection,
created_at
} = config || {};
const element = document.createElement(tag);
// Style du grid
element.className = 'flex font-sans';
element.href = "https://www.ethereum.org/";
element.classList.add("grid", "grid-cols-1");
element.style.display = 'grid';
element.style.border = '2px solid #eaeaea';
element.style.borderRadius = '10px';
element.style.backgroundColor = ' #f9fafc';
element.style.padding = ' 10px';
// Image du produit
if (product_image) {
const imgDiv = document.createElement('div');
imgDiv.style.display = 'flex';
imgDiv.style.justifyContent = 'center';
imgDiv.style.alignItems = 'center';
const imgElement = document.createElement('img');
imgElement.className = 'w-full aspect-w-1 aspect-h-1 rounded-lg overflow-hidden xl:aspect-w-7 xl:aspect-h-8';
imgElement.src = product_image;
imgElement.style.justifyContent = 'center';
imgDiv.appendChild(imgElement);
if (product_image !== '') {
element.appendChild(imgDiv);
}
}
// Nombre de ventes
if (product_sales) {
createLineLabelData("Sales : ", product_sales, element)
}
// Nom du produit
if (product_name) {
createLineLabelData("Product name : ", product_name, element)
}
// Créateur
if (creator) {
createLineLabelData("Creator : ", creator, element)
}
// Collection
if (collection) {
createLineLabelData("Collection : ", collection, element)
}
// Creation
if (created_at) {
let newCreated = created_at.substr(0, 10);
newCreated = newCreated.replaceAll('-', '/')
createLineLabelData("Created at : ", newCreated, element)
}
// Button
if (product_image) {
const button = document.createElement('button');
button.className = 'bg-blue-600 mt-4 text-sm inline-flex items-center px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500';
button.innerHTML = 'Voir le NFT';
button.style.maxWidth = '300px';
button.style.margin = 'auto';
button.style.marginTop = '20px';
button.style.marginBottom = '10px';
button.onclick = function () {
}
element.appendChild(button);
}
if (!parent) {
root.appendChild(element);
} else {
parent.appendChild(element);
}
return element;
}
const myDiv = createElement('div');
myDiv.style.display = 'grid';
myDiv.style.gridTemplateColumns = '1fr 1fr 1fr';
myDiv.style.gridGap = '50px';
myDiv.className = "max-w-2xl mx-auto py-16 px-4 sm:py-24 sm:px-6 lg:max-w-7xl lg:px-8";
myDiv.style.border = 'none';
myDiv.style.backgroundColor = 'white';
function createCards(assets) {
const div = document.createElement('div');
div.innerHTML = assets.length + ' résultat(s)';
div.classList.add('text-xl', 'p-2.5');
var bodyChildren = document.querySelector('body').children;
document.body.insertBefore(div, bodyChildren.item(4));
assets.forEach(el => {
if (el) {
createElement('div', {
product_sales: el.sales,
product_image: el.image_url,
product_name: el.name,
creator: el.creator.username,
creator_picture: el.creator.profile_url,
product_id: el.id,
token_id: el.token_id,
collection: el.collection.name,
created_at: el.contract.created_at
}, myDiv);
}
})
}
const username = window.location.search.split('=')[1];
console.log(username);
function createLineLabelData(labelString, data, element) {
const name = document.createElement('p');
const label = document.createElement('p');
const div = document.createElement('div');
div.appendChild(label);
div.appendChild(name);
label.innerHTML = labelString;
name.innerHTML = data;
div.style.display = 'flex';
name.style.padding = '5px 0px 5px 4px';
label.style.padding = '5px 0px';
label.className = "text-blue-600";
element.appendChild(div);
}
function getCollection() {
fetch(`https://awesome-nft-app.herokuapp.com/creators/${username}`)
.then(response => response.json())
.then(data => {
const assets = data.assets;
createCards(assets);
})
.catch(error => console.error(error))
}
getCollection();
</script>
</html>