Fix race?
This commit is contained in:
parent
7438573c49
commit
b42097f4b8
135
src/App.tsx
135
src/App.tsx
@ -29,67 +29,70 @@ export const App : React.FC = () => {
|
|||||||
const formSubmit = async () => {
|
const formSubmit = async () => {
|
||||||
const newst = addEntry(store, {variant: "eats", date: new Date().toString(), item: input} );
|
const newst = addEntry(store, {variant: "eats", date: new Date().toString(), item: input} );
|
||||||
console.log("newstore is", newst);
|
console.log("newstore is", newst);
|
||||||
await API.write(JSON.stringify(store))
|
API.write(JSON.stringify(store)).then(async () => {
|
||||||
const fromserver = await API.read();
|
setTimeout(async () => {
|
||||||
setStore({...fromserver} );
|
const fromserver = await API.read();
|
||||||
setInput("");
|
setStore({...fromserver} );
|
||||||
};
|
setInput("");
|
||||||
const [input, setInput] = useState<string>("");
|
}, 150);
|
||||||
|
})
|
||||||
|
};
|
||||||
return (
|
const [input, setInput] = useState<string>("");
|
||||||
<div className="App">
|
|
||||||
<h1>SHULNEFF</h1>
|
|
||||||
<div className="toprow">
|
return (
|
||||||
<div className="eats">
|
<div className="App">
|
||||||
<h2 onContextMenu={(e) => {e.preventDefault(); setShowAPIField(!showAPIField);}}>I ate ...</h2>
|
<h1>SHULNEFF</h1>
|
||||||
{showAPIField?
|
<div className="toprow">
|
||||||
<input placeholder='API Token' onChange={(e) => {
|
<div className="eats">
|
||||||
localStorage.setItem("apikey", e.target.value);
|
<h2 onContextMenu={(e) => {e.preventDefault(); setShowAPIField(!showAPIField);}}>I ate ...</h2>
|
||||||
}}/>
|
{showAPIField?
|
||||||
:null}
|
<input placeholder='API Token' onChange={(e) => {
|
||||||
<form>
|
localStorage.setItem("apikey", e.target.value);
|
||||||
<div>
|
}}/>
|
||||||
<input type="text" placeholder='Stinking Fish' onChange={(e) => {
|
:null}
|
||||||
setInput(e.target.value);}
|
<form>
|
||||||
} onKeyDown={async (e) =>{
|
<div>
|
||||||
if (e.key === "Enter") {
|
<input type="text" placeholder='Stinking Fish' onChange={(e) => {
|
||||||
await formSubmit();
|
setInput(e.target.value);}
|
||||||
}
|
} onKeyDown={async (e) =>{
|
||||||
}} value={input} />
|
if (e.key === "Enter") {
|
||||||
<button
|
await formSubmit();
|
||||||
onClick={formSubmit}
|
}
|
||||||
disabled={input.trim().length < 2}
|
}} value={input} />
|
||||||
>Submit</button>
|
<button
|
||||||
</div>
|
onClick={formSubmit}
|
||||||
</form>
|
disabled={input.trim().length < 2}
|
||||||
</div>
|
>Submit</button>
|
||||||
<div className="reacts">
|
</div>
|
||||||
<button
|
</form>
|
||||||
onClick={ async () => {
|
</div>
|
||||||
const newst = addEntry(store, {variant: "allergy", date: new Date().toString()} );
|
<div className="reacts">
|
||||||
await API.write(JSON.stringify(store))
|
<button
|
||||||
const fromserver = await API.read();
|
onClick={ async () => {
|
||||||
setStore({...fromserver} );
|
const newst = addEntry(store, {variant: "allergy", date: new Date().toString()} );
|
||||||
}}
|
await API.write(JSON.stringify(store))
|
||||||
><h3>Allergy Alert!</h3></button>
|
const fromserver = await API.read();
|
||||||
</div>
|
setStore({...fromserver} );
|
||||||
</div>
|
}}
|
||||||
<hr/>
|
><h3>Allergy Alert!</h3></button>
|
||||||
{store ?
|
</div>
|
||||||
<div className={"entry-table"}>
|
</div>
|
||||||
<RenderTable API={API} store={store} setStore={setStore} />
|
<hr/>
|
||||||
</div>
|
{store ?
|
||||||
:null}
|
<div className={"entry-table"}>
|
||||||
<hr/>
|
<RenderTable API={API} store={store} setStore={setStore} />
|
||||||
<details name='foo'>
|
</div>
|
||||||
<summary>Raw Store</summary>
|
:null}
|
||||||
<pre>
|
<hr/>
|
||||||
{JSON.stringify(store, null, 4)}
|
<details name='foo'>
|
||||||
</pre>
|
<summary>Raw Store</summary>
|
||||||
</details>
|
<pre>
|
||||||
</div>
|
{JSON.stringify(store, null, 4)}
|
||||||
);
|
</pre>
|
||||||
|
</details>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const DATEFORMAT = "YYYY MM DD HH:mm";
|
const DATEFORMAT = "YYYY MM DD HH:mm";
|
||||||
@ -139,10 +142,12 @@ export const RenderTable : React.FC<{API: APIEndPoint, store: Store, setStore: (
|
|||||||
if (isSelected) {
|
if (isSelected) {
|
||||||
const newst = removeEntry(store, item );
|
const newst = removeEntry(store, item );
|
||||||
console.log("newstore is", newst);
|
console.log("newstore is", newst);
|
||||||
await API.write(JSON.stringify(store))
|
API.write(JSON.stringify(store)).then(async () => {
|
||||||
const fromserver = await API.read();
|
setTimeout(async () => {
|
||||||
setStore({...fromserver} );
|
const fromserver = await API.read();
|
||||||
}
|
setStore({...fromserver} );
|
||||||
|
}, 150);
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
key={index} className="reacts"><td>{datestring}</td>
|
key={index} className="reacts"><td>{datestring}</td>
|
||||||
{isSelected ?
|
{isSelected ?
|
||||||
|
Loading…
Reference in New Issue
Block a user