Created
September 17, 2022 00:13
-
-
Save ChristianOConnor/cf86b2a9d9f498f848e0cb19d6e97b87 to your computer and use it in GitHub Desktop.
fresh app Creator Island 092622
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// import { useState } from "preact/hooks"; | |
import { useState, useEffect } from "preact/hooks"; | |
import { Handlers, PageProps } from "$fresh/server.ts"; | |
import UserDb from "../database.ts"; | |
interface CreatorProps { | |
email: string, | |
key: string | |
} | |
export default function Creator(props: CreatorProps) { | |
const handleSubmit = async (event) => { | |
event.preventDefault(); | |
const emailInput = event.target.email; | |
const ageInput = event.target.key; | |
console.log(emailInput.value); | |
console.log(ageInput.value); | |
const resp = await createNewUser(emailInput.value, ageInput.value); | |
return resp | |
}; | |
async function createNewUser(email, key) { | |
const rawPosts = await fetch('http://localhost:8000/api/createUser', { | |
"method": "POST", | |
"headers": { | |
"content-type": "application/x-www-form-urlencoded" | |
}, | |
"body": JSON.stringify({ | |
email: email, | |
key: key, | |
}) | |
}); | |
console.log(rawPosts); | |
} | |
return ( | |
<div> | |
<form onsubmit={(event) => handleSubmit(event)}> | |
<h1 class="text rounded-lg p-4 my-8"> Search </h1> | |
<input class="center rounded-lg p-4 my-8" type="text" name="email" /> | |
<input class="center rounded-lg p-4 my-8" type="text" name="key" /> | |
<br /> | |
<button | |
class="px-5 py-2.5 text-sm font-medium bg-blue-600 rounded-md shadow disabled:(bg-gray-800 border border-blue-600 opacity-50 cursor-not-allowed)" | |
type="submit">Submit | |
</button> | |
</form> | |
<br /> | |
{/* <ul> | |
{results.map((name) => <li key={name}>{name}</li>)} | |
</ul> */} | |
</div> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment