-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wait for Maps API Key to be retrieved before first render
- Loading branch information
1 parent
739b81f
commit bae3ae1
Showing
4 changed files
with
46 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
FROM node:20-alpine | ||
COPY musiccatalogue.ui-1.21.0.0 /opt/musiccatalogue.ui-1.21.0.0 | ||
WORKDIR /opt/musiccatalogue.ui-1.21.0.0 | ||
COPY musiccatalogue.ui-1.22.0.0 /opt/musiccatalogue.ui-1.22.0.0 | ||
WORKDIR /opt/musiccatalogue.ui-1.22.0.0 | ||
RUN npm install | ||
RUN npm run build | ||
ENTRYPOINT [ "npm", "start" ] |
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,5 @@ | ||
const secrets = { | ||
mapsApiKey: "Maps API Key", | ||
}; | ||
|
||
export default secrets; |
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,34 @@ | ||
import { apiFetchSecret, apiGetSecret } from "@/helpers/apiSecrets"; | ||
import { useState, useEffect } from "react"; | ||
import secrets from "@/helpers/secrets"; | ||
|
||
/** | ||
* Hook that uses the API helpers to retrieve the maps API key from the | ||
* Music Catalogue REST API | ||
* @param {*} logout | ||
* @returns | ||
*/ | ||
const useMapsApiKey = (logout) => { | ||
// Current list of artists and the method to change it | ||
const [apiKey, setApiKey] = useState(null); | ||
|
||
useEffect(() => { | ||
const fetchApiKey = async () => { | ||
try { | ||
// Get a list of artists via the service and store it in state | ||
var fetchedApiKey = await apiFetchSecret(secrets.mapsApiKey); | ||
setApiKey(fetchedApiKey); | ||
apiSetSecret(fetchedApiKey); | ||
} catch {} | ||
}; | ||
|
||
const currentApiKey = apiGetSecret(secrets.mapsApiKey); | ||
if (currentApiKey == null) { | ||
fetchApiKey(); | ||
} | ||
}, [logout]); | ||
|
||
return { apiKey, setApiKey }; | ||
}; | ||
|
||
export default useMapsApiKey; |