-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
77 lines (62 loc) · 1.73 KB
/
App.tsx
File metadata and controls
77 lines (62 loc) · 1.73 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
import React from 'react';
import '../styles/ui-compiled.css';
function App() {
onmessage = async (event) => {
if(event.data.pluginMessage.type === "fetchedLicense") {
checkLicense()
}
}
async function getLicense() {
parent.postMessage({
pluginMessage: {
action: "fetchLicense"
}
}, "*")
}
async function checkLicense() {
const req = await fetch("http://localhost:3000/api/checkLicense", {
method: "POST",
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
"license": (document.getElementById("license-input") as HTMLInputElement).value
})
})
const json = await req.json()
const license = json.license
const isPremium = json.canGenerate
console.log(json)
if(isPremium) {
const assetReq = await fetch("http://localhost:3000/api/generate", {
method: "POST",
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
text: (document.getElementById("prompt-input") as HTMLInputElement).value,
license
})
})
const assets = await assetReq.json()
console.log(assets)
parent.postMessage({
pluginMessage: {
action: "createPage",
assets
},
}, "*")
} else {
console.log("You can't do this!")
}
}
return (
<>
<h1 className="text-3xl font-bold underline">demo 🪄</h1>
<input id="prompt-input" type="text" placeholder="Enter your idea." />
<input id="license-input" type="text" placeholder="Enter your license." />
<button onClick={getLicense}>Create</button>
</>
);
}
export default App;