Skip to content

Commit

Permalink
Merge pull request #287 from City-of-Helsinki/UHF-10876
Browse files Browse the repository at this point in the history
Uhf 10876
  • Loading branch information
rpnykanen authored Nov 27, 2024
2 parents 233f272 + 475e52d commit e18fd14
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/hooks/useAddAskem.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { loadAskemScript } from '@/lib/askem'
// Only set the script tag once and reset after locale or title changes.
const useAddAskem = async (locale, title) => {
let apiKey = useRef('');
let askemReset = useRef('');

useEffect(() => {
doAskemReset();
Expand All @@ -22,19 +21,22 @@ const useAddAskem = async (locale, title) => {
}

setSettings();
if (!askemReset.current) {
reset = await loadAskemScript();
askemReset.current = reset;
}
askemReset.current();

reset = await loadAskemScript().catch((error)=> {
console.log(`Error while initializing askem script: ${error}`);
return () => {};
});

reset();

return () => {};
}

function setSettings() {
const settings = {
apikey: apiKey.current,
title: title,
canonicalUrl: window.location.href,
disableFonts: true
canonicalUrl: window.location.href
}
if (window.askem) {
window.askem.settings = settings
Expand Down

0 comments on commit e18fd14

Please sign in to comment.