NOMERGE: Přenos změn
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import React, { useContext, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import 'bootstrap/dist/css/bootstrap.min.css';
|
||||
import { EVENT_DISCONNECT, EVENT_MESSAGE, SocketContext } from './context/socket';
|
||||
import { addPizza, createPizzaDay, deletePizzaDay, finishDelivery, finishOrder, getData, getFood, getPizzy, getQrUrl, lockPizzaDay, removePizza, unlockPizzaDay, updateChoice, updateNote } from './Api';
|
||||
import { addChoice, addPizza, createPizzaDay, deletePizzaDay, finishDelivery, finishOrder, getData, getFood, getPizzy, getQrUrl, lockPizzaDay, removeChoices, removePizza, unlockPizzaDay, updateNote } from './Api';
|
||||
import { useAuth } from './context/auth';
|
||||
import Login from './Login';
|
||||
import { Alert, Button, Col, Form, Row, Table } from 'react-bootstrap';
|
||||
@@ -74,14 +74,15 @@ function App() {
|
||||
return
|
||||
}
|
||||
// TODO tohle občas náhodně nezafunguje, nutno přepsat, viz https://medium.com/@teh_builder/ref-objects-inside-useeffect-hooks-eb7c15198780
|
||||
if (data?.choices && choiceRef.current) {
|
||||
for (let entry of Object.entries(data.choices)) {
|
||||
if (entry[1].includes(auth.login)) {
|
||||
const value = entry[0] as any as number; // TODO tohle je absurdní
|
||||
choiceRef.current.value = Object.values(Locations)[value];
|
||||
}
|
||||
}
|
||||
}
|
||||
// TODO nutno opravit
|
||||
// if (data?.choices && choiceRef.current) {
|
||||
// for (let entry of Object.entries(data.choices)) {
|
||||
// if (entry[1].includes(auth.login)) {
|
||||
// const value = entry[0] as any as number; // TODO tohle je absurdní
|
||||
// choiceRef.current.value = Object.values(Locations)[value];
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}, [auth, auth?.login, data?.choices])
|
||||
|
||||
// Reference na mojí objednávku
|
||||
@@ -92,16 +93,21 @@ function App() {
|
||||
}
|
||||
}, [auth?.login, data?.pizzaDay?.orders])
|
||||
|
||||
// TODO přejmenovat na addChoice
|
||||
const changeChoice = async (event: React.ChangeEvent<HTMLSelectElement>) => {
|
||||
const index = Object.values(Locations).indexOf(event.target.value as unknown as Locations);
|
||||
console.log("Target value", event.target.value)
|
||||
console.log("Change choices called with index", index);
|
||||
// TODO implementovat
|
||||
if (auth?.login) {
|
||||
await updateChoice(index > -1 ? index : null);
|
||||
await addChoice(index);
|
||||
}
|
||||
}
|
||||
|
||||
const removeChoice = async (key: string) => {
|
||||
if (auth?.login) {
|
||||
await updateChoice(null);
|
||||
console.log("Remove choice called with key", key)
|
||||
// await removeChoices(key); // TODO tohle je určitě blbě
|
||||
if (choiceRef?.current?.value) {
|
||||
choiceRef.current.value = "";
|
||||
}
|
||||
@@ -237,19 +243,22 @@ function App() {
|
||||
{Object.keys(data.choices).length > 0 ?
|
||||
<Table striped bordered hover className='results-table mt-5'>
|
||||
<tbody>
|
||||
{Object.keys(data.choices).map((key: string, index: number) =>
|
||||
<tr key={index}>
|
||||
<td>{Object.values(Locations)[Number(key)]}</td>
|
||||
<td>
|
||||
<ul>
|
||||
{data.choices[Number(key)].map((p: string, index: number) =>
|
||||
<li key={index}>{p} {p === auth.login && <FontAwesomeIcon onClick={() => {
|
||||
removeChoice(key);
|
||||
}} title='Odstranit' className='trash-icon' icon={faTrashCan} />}</li>
|
||||
)}
|
||||
</ul>
|
||||
</td>
|
||||
</tr>
|
||||
{Object.keys(data.choices).map((key: string, index: number) => {
|
||||
console.log("Rendering for key", key)
|
||||
return (
|
||||
<tr key={index}>
|
||||
<td>{Object.values(Locations)[Number(key)]}</td>
|
||||
<td>
|
||||
<ul>
|
||||
{/* {data.choices[Number(key)].map((p: string, index: number) =>
|
||||
<li key={index}>{p} {p === auth.login && <FontAwesomeIcon onClick={() => {
|
||||
removeChoice(key);
|
||||
}} title='Odstranit' className='trash-icon' icon={faTrashCan} />}</li>
|
||||
)} */}
|
||||
</ul>
|
||||
</td>
|
||||
</tr>)
|
||||
}
|
||||
)}
|
||||
</tbody>
|
||||
</Table>
|
||||
|
||||
Reference in New Issue
Block a user