Use editions

This commit is contained in:
Adrien Vannson 2023-03-06 11:50:33 +01:00
parent 8cd553e68c
commit 1ab7f7654e
No known key found for this signature in database
GPG Key ID: FE2E66FD978C1A55

View File

@ -14,6 +14,7 @@ import API_URL from './config.js';
export default function EditDialog({ isOpen, setIsOpen, room }) {
const [names, setNames] = React.useState([]);
const [users, setUsers] = React.useState([]);
const [pendingUpdates, setPendingUpdates] = React.useState([]);
const [newPlaceName, setNewPlaceName] = React.useState("");
const [newUserName, setNewUserName] = React.useState("");
@ -28,6 +29,24 @@ export default function EditDialog({ isOpen, setIsOpen, room }) {
setNames(data.names);
setUsers(data.users);
});
fetch(API_URL + "get_all_editions")
.then(response => response.json())
.then(data => {
var updates = [];
data.forEach(update => {
if (update.placeId === room) {
updates.push({
id: update.id,
text: (update.mode[10] === 'n' ? 'Nom : ' : 'Utilisateur : ') + update.editorValue,
color: update.mode[0] === 'a' ? 'success' : 'error'
});
}
});
setPendingUpdates(updates);
});
}
}, [room, updatesCount]);
@ -36,28 +55,39 @@ export default function EditDialog({ isOpen, setIsOpen, room }) {
};
const addName = () => {
fetch(API_URL + "add_place_name/" + room + "/" + encodeURI(newPlaceName))
fetch(API_URL + "create_edition/add_place_name/" + room + "/" + encodeURI(newPlaceName))
.then(response => refresh());
};
const removeName = (placeName) => {
fetch(API_URL + "del_place_name/" + room + "/" + encodeURI(placeName))
fetch(API_URL + "create_edition/del_place_name/" + room + "/" + encodeURI(placeName))
.then(response => refresh());
}
const addUser = () => {
fetch(API_URL + "add_room_user_name/" + room + "/" + encodeURI(newUserName))
fetch(API_URL + "create_edition/add_room_user_name/" + room + "/" + encodeURI(newUserName))
.then(response => refresh());
};
const removeUser = (userName) => {
fetch(API_URL + "del_room_user_name/" + room + "/" + encodeURI(userName))
fetch(API_URL + "create_edition/del_room_user_name/" + room + "/" + encodeURI(userName))
.then(response => refresh());
}
return <Dialog open={isOpen} onClose={() => { setIsOpen(false) }}>
<DialogTitle>Salle n°{room}</DialogTitle>
<DialogContent>
Modifications en attente :<br/>
{pendingUpdates.map(update => {
return <Chip
label={update.text}
key={update.id}
color={update.color}
/>
})}
<Divider />
Noms :<br />
{names.map(name => {
return <Chip