-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
49 lines (39 loc) · 1.16 KB
/
main.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
const button = document.querySelector('#submit')
button.addEventListener('click', async () => {
startAnimation()
const prompt = document.getElementById('prompt').value
const response = await fetch('http://localhost:8080/magic', {
method: "POST",
headers: {
"Content-type": "application/json"
},
body: JSON.stringify({
prompt
})
})
if (response.ok) {
const data = await response.json();
console.log(data);
const imageContainer = document.querySelector('.image-container')
imageContainer.innerHTML = `<img src="${data.imageUrl}" alt="Image" id="image" >`
} else {
const err = await response.text();
alert(err)
console.log(err);
}
stopAnimation()
})
const startAnimation = () => {
button.disabled = true
const emoji1 = document.querySelector('.emoji-l')
const emoji2 = document.querySelector('.emoji-r')
emoji1.classList.add('spin')
emoji2.classList.add('spin')
}
const stopAnimation = () => {
button.disabled = false
const emoji1 = document.querySelector('.emoji-l')
const emoji2 = document.querySelector('.emoji-r')
emoji1.classList.remove('spin')
emoji2.classList.remove('spin')
}