-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from columbiaspace/setup-status
created a status indicator for the setup page
- Loading branch information
Showing
8 changed files
with
230 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import React, { useEffect, useState } from "react"; | ||
import mapboxgl from "mapbox-gl/dist/mapbox-gl.js"; | ||
import "mapbox-gl/dist/mapbox-gl.css"; | ||
|
||
const MapboxComponent = ({ handleMapBoxAPIStatus }) => { | ||
const [mapBoxAPIKey, setMapBoxAPIKey] = useState(null); | ||
|
||
useEffect(() => { | ||
const fetchMapBoxAPIKey = async () => { | ||
try { | ||
const response = await fetch("http://localhost:8000/get_mapbox_key"); | ||
const data = await response.json(); | ||
setMapBoxAPIKey(data.MAPBOX_KEY); | ||
checkMapboxAPIKey(data.MAPBOX_KEY); | ||
} catch (error) { | ||
console.error("Error fetching MapBox API key:", error); | ||
handleMapBoxAPIStatus("red"); | ||
} | ||
}; | ||
|
||
fetchMapBoxAPIKey(); | ||
}, [handleMapBoxAPIStatus]); | ||
|
||
const checkMapboxAPIKey = (key) => { | ||
handleMapBoxAPIStatus('yellow'); // Set to yellow while checking | ||
const tempDiv = document.createElement('div'); | ||
tempDiv.style.display = 'none'; | ||
document.body.appendChild(tempDiv); | ||
|
||
const map = new mapboxgl.Map({ | ||
container: tempDiv, | ||
accessToken: key, | ||
}); | ||
|
||
map.on('load', () => { | ||
handleMapBoxAPIStatus('green'); | ||
map.remove(); | ||
document.body.removeChild(tempDiv); | ||
}); | ||
|
||
map.on('error', () => { | ||
handleMapBoxAPIStatus('red'); | ||
map.remove(); | ||
document.body.removeChild(tempDiv); | ||
}); | ||
}; | ||
|
||
return null; | ||
}; | ||
|
||
export default MapboxComponent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.