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

View File

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