Fix enter handling
This commit is contained in:
parent
2c44979078
commit
e32c976d87
@ -1,11 +1,10 @@
|
|||||||
import {LowSync} from 'lowdb';
|
const { LowSync } = require('lowdb');
|
||||||
//const { JSONFileSync } = require('lowdb/node');
|
const { JSONFileSync } = require('lowdb/node');
|
||||||
import {JSONFileSync} from 'lowdb/node';
|
|
||||||
|
|
||||||
const db = new LowSync(new JSONFileSync('file.json'), {})
|
const db = new LowSync(new JSONFileSync('file.json'), {})
|
||||||
|
|
||||||
import {createServer} from 'node:http';
|
const { createServer } = require('node:http');
|
||||||
//const { createServer } = require('node:http');
|
import * as http from 'node:http';
|
||||||
|
|
||||||
const key = "c3dpZ2dpdHlzd29vdHkK";
|
const key = "c3dpZ2dpdHlzd29vdHkK";
|
||||||
const reStoreWrite = new RegExp(`/write/${key}/?`)
|
const reStoreWrite = new RegExp(`/write/${key}/?`)
|
||||||
|
25
src/App.tsx
25
src/App.tsx
@ -26,6 +26,14 @@ export const App : React.FC = () => {
|
|||||||
const [showAPIField, setShowAPIField] = useState(false);
|
const [showAPIField, setShowAPIField] = useState(false);
|
||||||
|
|
||||||
|
|
||||||
|
const formSubmit = async () => {
|
||||||
|
const newst = addEntry(store, {variant: "eats", date: new Date().toString(), item: input} );
|
||||||
|
console.log("newstore is", newst);
|
||||||
|
await API.write(JSON.stringify(store))
|
||||||
|
const fromserver = await API.read();
|
||||||
|
setStore({...fromserver} );
|
||||||
|
setInput("");
|
||||||
|
};
|
||||||
const [input, setInput] = useState<string>("");
|
const [input, setInput] = useState<string>("");
|
||||||
|
|
||||||
|
|
||||||
@ -42,16 +50,15 @@ export const App : React.FC = () => {
|
|||||||
:null}
|
:null}
|
||||||
<form>
|
<form>
|
||||||
<div>
|
<div>
|
||||||
<input type="text" placeholder='Stinking Fish' onChange={(e) => setInput(e.target.value)} value={input} />
|
<input type="text" placeholder='Stinking Fish' onChange={(e) => {
|
||||||
|
setInput(e.target.value);}
|
||||||
|
} onKeyDown={async (e) =>{
|
||||||
|
if (e.key === "Enter") {
|
||||||
|
await formSubmit();
|
||||||
|
}
|
||||||
|
}} value={input} />
|
||||||
<button
|
<button
|
||||||
onClick={ async () => {
|
onClick={formSubmit}
|
||||||
const newst = addEntry(store, {variant: "eats", date: new Date().toString(), item: input} );
|
|
||||||
console.log("newstore is", newst);
|
|
||||||
await API.write(JSON.stringify(store))
|
|
||||||
const fromserver = await API.read();
|
|
||||||
setStore({...fromserver} );
|
|
||||||
setInput("");
|
|
||||||
}}
|
|
||||||
disabled={input.trim().length < 2}
|
disabled={input.trim().length < 2}
|
||||||
>Submit</button>
|
>Submit</button>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user