Put the URL of the API in a config file

This commit is contained in:
Adrien Vannson 2023-03-04 18:44:29 +01:00
parent 2044e53365
commit 9b13ede171
No known key found for this signature in database
GPG Key ID: FE2E66FD978C1A55
3 changed files with 13 additions and 9 deletions

View File

@ -28,6 +28,7 @@ import './App.css'
import Map from './Map.js';
import Rooms from './Rooms.js';
import API_URL from './config.js';
function ChangeFloor({ currentFloor, callbackFloorChanged }) {
const [sites, setSites] = React.useState([]);
@ -36,7 +37,7 @@ function ChangeFloor({ currentFloor, callbackFloorChanged }) {
};
React.useEffect(() => {
fetch("https://encartes.aliens-lyon.fr/api/map/get_all_floors/")
fetch(API_URL + "get_all_floors/")
.then(response => response.json())
.then(data => {
setSites(data);
@ -85,7 +86,7 @@ function RoomResearch({ callbackRoomSelected }) {
const [rooms, setRooms] = React.useState([]);
const startResearch = (event) => {
fetch("https://encartes.aliens-lyon.fr/api/map/find_place_by_name/" + currentRequest)
fetch(API_URL + "find_place_by_name/" + currentRequest)
.then(response => response.json())
.then(data => {
setRooms(data);
@ -125,7 +126,7 @@ function RoomInformation({ roomId, setIsEditDialogOpen }) {
React.useEffect(() => {
if (roomId !== undefined) {
fetch("https://encartes.aliens-lyon.fr/api/map/get_place_info/" + roomId)
fetch(API_URL + "get_place_info/" + roomId)
.then(response => response.json())
.then(data => {
setNames(data.names);
@ -231,7 +232,7 @@ function EditDialog({ isOpen, setIsOpen, room }) {
React.useEffect(() => {
if (room !== undefined) {
fetch("https://encartes.aliens-lyon.fr/api/map/get_place_info/" + room)
fetch(API_URL + "get_place_info/" + room)
.then(response => response.json())
.then(data => {
setNames(data.names);
@ -245,22 +246,22 @@ function EditDialog({ isOpen, setIsOpen, room }) {
};
const addName = () => {
fetch("https://encartes.aliens-lyon.fr/api/map/add_place_name/" + room + "/" + encodeURI(newPlaceName))
fetch(API_URL + "add_place_name/" + room + "/" + encodeURI(newPlaceName))
.then(response => refresh());
};
const removeName = (placeName) => {
fetch("https://encartes.aliens-lyon.fr/api/map/del_place_name/" + room + "/" + encodeURI(placeName))
fetch(API_URL + "del_place_name/" + room + "/" + encodeURI(placeName))
.then(response => refresh());
}
const addUser = () => {
fetch("https://encartes.aliens-lyon.fr/api/map/add_room_user_name/" + room + "/" + encodeURI(newUserName))
fetch(API_URL + "add_room_user_name/" + room + "/" + encodeURI(newUserName))
.then(response => refresh());
};
const removeUser = (userName) => {
fetch("https://encartes.aliens-lyon.fr/api/map/del_room_user_name/" + room + "/" + encodeURI(userName))
fetch(API_URL + "del_room_user_name/" + room + "/" + encodeURI(userName))
.then(response => refresh());
}

View File

@ -10,6 +10,7 @@ import stairs from "./stairs.png";
import lift from "./lift.png";
import toilet from "./toilet.png"
import { useMapEvent, useMap } from 'react-leaflet/hooks';
import API_URL from './config';
function Stairs({position, size, body})
{
@ -269,7 +270,7 @@ function Map({callbackRoomSelected, selectedRoom, floorID, callbackChangeFloor})
// We use the useEffect hook to fetch the data to build the Map
useEffect(() =>
{
fetch("https://encartes.aliens-lyon.fr/api/map/get_floor/"+floorID)
fetch(API_URL + "get_floor/"+floorID)
.then(response => response.json())
.then(data => {setLoading(false); setFloor(data)})
.catch((error) => {setError("API unreachable");});

2
src/config.js Normal file
View File

@ -0,0 +1,2 @@
const API_URL = 'https://encartes.aliens-lyon.fr/api/map/';
export default API_URL;