forked from jheguevara/jheguevara.github.io
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsite-builder-x2.html
More file actions
371 lines (340 loc) · 18.4 KB
/
site-builder-x2.html
File metadata and controls
371 lines (340 loc) · 18.4 KB
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Miles Creative Nexus Zone: Website or Brand Analyzer</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-[#090825] text-white h-dvh">
<div class="flex flex-col h-full">
<header class="flex justify-between items-center mx-9 p-6 pt-9 border-b overflow-hidden shadow-lg bg-[#090825]">
<div class="flex items-center">
<div class="flex flex-col border-r border-white">
<img style="height: 30px; width: 150px;"
src="file:///Users/mylesgrant/Documents/projects/miles-ahead/images/miles-logo.png"
alt="MilesAhead Logo">
<span class="w-full tracking-[23.4px] mt-[3px]">AHEAD</span>
</div>
<h1 class="text-2xl slef-end ml-6">AI Website Builder</h1>
</div>
<nav>
<ul class="flex gap-x-6">
<li>
<a class="focus:border-b focus:border-white" href="#" onclick="showWebsites()">My Websites</a>
</li>
<li>
<a class="focus:border-b focus:border-white" href="#" onclick="showGenerateWebsites()">Generate
New
Website</a>
</li>
</ul>
</nav>
</header>
<main class="flex justify-center h-full overflow-y-scroll">
<div id="websites" class="hidden">
<span>Websites</span>
</div>
<div id="generate-websites" class="flex items-center justify-center">
<div class="flex gap-x-6">
<ul class="flex flex-col gap-y-3 border-r pr-6 border-white items-end">
<li id="step-1" class="flex gap-x-3 mt-9 opacity-25">
<span id="step-1-label">Generating HTML files...</span>
<svg id="step-1-loading" class="hidden animate-spin h-5 w-5 text-white"
xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor"
stroke-width="4"></circle>
<path class="opacity-75" fill="currentColor"
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z">
</path>
</svg>
<i id="step-1-complete" class="hidden bi bi-check-circle-fill"></i>
<i id="step-1-error" class="hidden bi bi-x-circle-fill text-red-500"></i>
</li>
<li id="step-2" class="flex gap-x-3 opacity-25">
<span id="step-2-label">Select Website Template</span>
<span id="step-2-loading" class="hidden relative self-center flex h-3 w-3">
<span
class="animate-ping absolute inline-flex h-full w-full rounded-full bg-sky-400 opacity-75"></span>
<span class="relative inline-flex rounded-full h-3 w-3 bg-sky-500"></span>
</span>
<i id="step-2-complete" class="hidden bi bi-check-circle-fill"></i>
<i id="step-2-error" class="hidden bi bi-x-circle-fill text-red-500"></i>
</li>
<li id="step-3" class="flex gap-x-3 opacity-25">
<span id="step-3-label">Uploading Files...</span>
<svg id="step-3-loading" class="hidden animate-spin h-5 w-5 text-white"
xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor"
stroke-width="4"></circle>
<path class="opacity-75" fill="currentColor"
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z">
</path>
</svg>
<i id="step-3-complete" class="hidden bi bi-check-circle-fill"></i>
<i id="step-3-error" class="hidden bi bi-x-circle-fill text-red-500"></i>
</li>
<li id="step-4" class="flex gap-x-3 mb-9 opacity-25">
<span id="step-4-label">Creating Custom Subdomain...</span>
<svg id="step-4-loading" class="hidden animate-spin h-5 w-5 text-white"
xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor"
stroke-width="4"></circle>
<path class="opacity-75" fill="currentColor"
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z">
</path>
</svg>
<i id="step-4-complete" class="hidden bi bi-check-circle-fill"></i>
<i id="step-4-error" class="hidden bi bi-x-circle-fill text-red-500"></i>
</li>
</ul>
<div id="generate-website-input-container" class="flex flex-col my-9">
<div class="flex flex-col mb-6">
<label for="generate-website-input-name" class="text-2xl">Website Name<br />or
Brand</label>
<span id="generate-website-input-label-error" class="text-red-500 hidden">Input is
required</span>
</div>
<div class="flex items-center gap-x-3">
<input class="w-[210px] p-2 rounded text-black" type="text" id="generate-website-input"
name="generate-website-input-name" placeholder="name here..." required />
<button id="generate-website-button" class="disabled:opacity-25"
onclick="generateWebsite()">
<i class="bi bi-arrow-right text-2xl"></i>
</button>
</div>
</div>
<div id="generate-website-templates-container" class="hidden flex flex-col my-9">
<h1 class="text-2xl mb-3">Templates</h1>
<ul id="generate-website-templates" class="grid grid-cols-4 gap-4">
</ul>
</div>
<div id="subdomain-completed-container"
class="hidden flex flex-col justify-center items-center my-9">
<i class="bi bi-check-circle text-4xl mb-9 text-green-300"></i>
<div>ITS FINISHED</div>
</div>
</div>
</div>
</main>
</div>
<script src="https://cdn.jsdelivr.net/npm/gsap@3.12.5/dist/gsap.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"
integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz"
crossorigin="anonymous"></script>
<script>
function el(id) {
return document.getElementById(id)
}
function showWebsites() {
addClass("generate-websites", "hidden")
el("websites").classList.remove("hidden")
}
function showGenerateWebsites() {
addClass("websites", "hidden")
el("generate-websites").classList.remove("hidden")
}
function addClass(id, _class) {
const element = el(id)
if (!element.classList.contains(_class)) {
element.classList.add(_class)
}
}
function gotToStep(step, state) {
console.log("Step: ", step, state)
const { error, isComplete, isLoading, reset } = state || {}
if (error) {
el(`step-${step}`).classList.remove("opacity-25")
addClass(`step-${step}-complete`, "hidden")
addClass(`step-${step}-loading`, "hidden")
addClass(`step-${step}-label`, "text-red-500")
el(`step-${step}-error`).classList.remove("hidden")
} else if (reset) {
addClass(`step-${step}`, "opacity-25")
el(`step-${step}-label`).classList.remove("text-red-500")
addClass(`step-${step}-complete`, "hidden")
addClass(`step-${step}-loading`, "hidden")
addClass(`step-${step}-error`, "hidden")
} else if (isLoading) {
el(`step-${step}`).classList.remove("opacity-25")
el(`step-${step}-label`).classList.remove("text-red-500")
el(`step-${step}-loading`).classList.remove("hidden")
addClass(`step-${step}-complete`, "hidden")
addClass(`step-${step}-error`, "hidden")
} else if (isComplete) {
el(`step-${step}`).classList.remove("opacity-25")
el(`step-${step}-label`).classList.remove("text-red-500")
el(`step-${step}-complete`).classList.remove("hidden")
addClass(`step-${step}-loading`, "hidden")
addClass(`step-${step}-error`, "hidden")
}
if (step === "2") {
addClass("generate-website-input-container", "hidden")
el("generate-website-templates-container").classList.remove("hidden")
addClass("subdomain-completed-container", "hidden")
} else if (step === "1") {
addClass("generate-website-templates-container", "hidden")
el("generate-website-input-container").classList.remove("hidden")
addClass("subdomain-completed-container", "hidden")
} else if (step === "4" && isComplete) {
addClass("generate-website-input-container", "hidden")
addClass("generate-website-templates-container", "hidden")
el("subdomain-completed-container", "hidden").classList.remove("hidden")
}
addClass("generate-website-input-label-error", "hidden")
}
function resetSteps() {
for (let i = 1; i < 5; i++) {
gotToStep(`${i}`, { reset: true })
}
}
async function generateWebsite() {
const generateWebsiteBtn = el("generate-website-button")
generateWebsiteBtn.disabled = true
try {
resetSteps()
gotToStep("1", { isLoading: true })
const websiteNameOrBrand = el("generate-website-input").value
if (websiteNameOrBrand) {
const response = await fetch('http://localhost:3001/api/generate-html-links', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ websiteNameOrBrand })
});
const data = await response.json();
if (data && data.filePaths) {
const statusPromiseAll = await Promise.all(Object.keys(data.filePaths).map((key) => {
return checkLinkStatus(key, data.filePaths[key])
}))
if (statusPromiseAll && statusPromiseAll.length > 0 && statusPromiseAll.every((req) => req === true)) {
gotToStep("1", { isComplete: true })
gotToStep("2", { isLoading: true })
el("generate-website-templates").innerHTML = Object.keys(data.filePaths).map((key) => {
return `
<li id="template-${key}-item">
<a href="${data.filePaths[key]}" target="_blank">
<img
class="rounded"
style="width: 250px; height: 200px;"
src="/Users/mylesgrant/Documents/projects/miles-ahead/images/${key}.png" />
</a>
<button id="template-${key}-button" class="flex rounded-full border border-2 border-white p-3 mt-3 gap-x-1 disabled:opacity-25" onclick='selectedGeneratedTemplate("${key}", ${JSON.stringify(data.filePaths)})'>
<span id="template-${key}-deselect">Select</span>
<i id="template-${key}-select" class="hidden bi bi-check2-all text-2xl"></i>
</button>
</li>`;
}).join('')
} else {
resetSteps()
gotToStep("1", { error: true })
generateWebsiteBtn.disable = false
}
} else {
resetSteps()
gotToStep("1", { error: true })
generateWebsiteBtn.disable = false
}
} else {
resetSteps()
gotToStep("1")
el("generate-website-input-label-error").classList.remove("hidden")
}
} catch (error) {
console.error(error)
generateWebsiteBtn.disabled = false
resetSteps()
gotToStep("1", { error: true })
}
}
function checkLinkStatus(key, url) {
return new Promise(async (resolve, reject) => {
try {
const checkStatus = async () => {
try {
console.log(`Checking status for ${url}`);
const response = await fetch(url, { method: 'GET' });
if (response.ok) {
console.log(`${url} is accessible`);
// Stop checking if the URL is accessible
clearInterval(interval);
// await processGithubLink(url)
resolve(true)
}
} catch (error) {
console.error(`Error checking ${url}: `, error);
reject(error)
}
};
// Set an interval to check the status periodically
const interval = setInterval(checkStatus, 5000);
// Run the check immediately as well
await checkStatus();
} catch (error) {
reject(error)
}
})
}
async function selectedGeneratedTemplate(key, data) {
Object.keys(data).forEach((_key) => {
if (key !== _key) {
addClass(`template-${_key}-item`, "hidden")
}
})
addClass(`template-${key}-deselect`, "hidden")
el(`template-${key}-select`).classList.remove("hidden")
el("generate-website-templates").className = "flex"
await uploadToS3Bucket(key, data[key], el("generate-website-input").value)
}
async function uploadToS3Bucket(key, githubLink, bucketName) {
const selectedTemplateButton = el(`template-${key}-button`)
selectedTemplateButton.disabled = true
try {
gotToStep("2", { isComplete: true })
gotToStep("3", { isLoading: true })
const response = await fetch('http://localhost:3001/api/process-github-link', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ githubLink, bucketName })
});
const data = await response.json();
if (data && data.bucketName && data.publicUrl) {
await processRoute53Link(data.bucketName)
} else {
selectedTemplateButton.disabled = false
gotToStep("3", { error: true })
}
} catch (error) {
console.error(error);
selectedTemplateButton.disabled = false
gotToStep("3", { error: true })
}
}
async function processRoute53Link(bucketName) {
try {
gotToStep("3", { isComplete: true })
gotToStep("4", { isLoading: true })
const response = await fetch('http://localhost:3001/api/process-route53-link', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ bucketName: bucketName.toLowerCase() })
});
const data = await response.json();
if (data && data.subdomainResult) {
gotToStep("4", { isComplete: true })
} else {
gotToStep("4", { error: true })
}
} catch (error) {
gotToStep("4", { error: true })
}
}
</script>
</body>
</html>