Fix enter handling

This commit is contained in:
Dominic Zimmer 2025-05-03 18:00:57 +02:00
parent 2c44979078
commit e32c976d87
2 changed files with 20 additions and 14 deletions

View File

@ -1,11 +1,10 @@
import {LowSync} from 'lowdb';
//const { JSONFileSync } = require('lowdb/node');
import {JSONFileSync} from 'lowdb/node';
const { LowSync } = require('lowdb');
const { JSONFileSync } = require('lowdb/node');
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 reStoreWrite = new RegExp(`/write/${key}/?`)

View File

@ -26,6 +26,14 @@ export const App : React.FC = () => {
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>("");
@ -42,16 +50,15 @@ export const App : React.FC = () => {
:null}
<form>
<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
onClick={ 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("");
}}
onClick={formSubmit}
disabled={input.trim().length < 2}
>Submit</button>
</div>