From 1ab7f7654e9559abff49b8c201f7ffa436fe4112 Mon Sep 17 00:00:00 2001 From: Adrien Vannson Date: Mon, 6 Mar 2023 11:50:33 +0100 Subject: [PATCH] Use editions --- src/EditDialog.js | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/src/EditDialog.js b/src/EditDialog.js index 2a68fbd..ca94ea5 100644 --- a/src/EditDialog.js +++ b/src/EditDialog.js @@ -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 { setIsOpen(false) }}> Salle n°{room} + Modifications en attente :
+ {pendingUpdates.map(update => { + return + })} + + + Noms :
{names.map(name => { return