i hate nim
This commit is contained in:
parent
6e222f7529
commit
4f40e59b17
17 changed files with 1439 additions and 31 deletions
73
web/src/pages/Home/index.tsx
Normal file
73
web/src/pages/Home/index.tsx
Normal file
|
@ -0,0 +1,73 @@
|
|||
import { useEffect, useState } from 'preact/hooks';
|
||||
|
||||
type EntryBody = {
|
||||
err: boolean;
|
||||
referral: string;
|
||||
key: string;
|
||||
}
|
||||
|
||||
|
||||
export const Home = () => {
|
||||
const [referral, setReferral] = useState('');
|
||||
const [entryBody, setEntryBody] = useState<EntryBody | null>({
|
||||
err: true,
|
||||
referral: '',
|
||||
key: ''
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
console.log('Referral:', referral);
|
||||
}, [referral]);
|
||||
|
||||
const entry = async () => {
|
||||
let res = await fetch("http://localhost:8080/entry", {
|
||||
method: 'GET',
|
||||
headers: { referral }
|
||||
})
|
||||
|
||||
if (!res.ok) {
|
||||
console.error('Error:', res.status);
|
||||
return
|
||||
}
|
||||
|
||||
let body: EntryBody = await res.json();
|
||||
|
||||
if (body.err) {
|
||||
console.error('Error:', body.referral);
|
||||
window.location.href = '/error';
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
console.log('Entry:', body);
|
||||
|
||||
setEntryBody(body);
|
||||
|
||||
setReferral('');
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<h1>???</h1>
|
||||
<div>
|
||||
<span>
|
||||
Referral: <input type="text" value={referral} onInput={(e) => setReferral(e.currentTarget.value)} />
|
||||
</span>
|
||||
<div>
|
||||
<button onClick={async () => await entry()}>Submit</button>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
{
|
||||
!entryBody.err && (
|
||||
<>
|
||||
<h2>Key: {entryBody?.key}</h2>
|
||||
<h2>Referral: {entryBody?.referral}</h2>
|
||||
</>
|
||||
)
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue