Skip to content

Commit

Permalink
fix: useLocalisation
Browse files Browse the repository at this point in the history
  • Loading branch information
Clemog committed Sep 14, 2023
1 parent 963b40a commit 6f7965c
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions source/components/localisation/useLocalisation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,28 @@ export default () => {
(state: AppState) => state.currentLang
).toLowerCase()

const regionParams: Region | undefined = useSupportedRegion(
iframeLocalisationOption
)
const iframeRegionParams: Region | undefined =
iframeLocalisationOption && useSupportedRegion(iframeLocalisationOption)

console.log(iframeRegionParams)
useEffect(() => {
if (localisation?.country != null && localisation?.country?.code != null) {
return undefined
}

if (iframeLocalisationOption) {
dispatch(
setLocalisation({
country: {
code: iframeRegionParams?.[currentLang]?.code,
name: iframeRegionParams?.[currentLang]?.nom,
},
userChosen: false,
})
)
return undefined
}

const asyncFecthAPI = async () => {
await fetch(API)
.then((res) => {
Expand All @@ -56,20 +69,7 @@ export default () => {
})
}

if (iframeLocalisationOption) {
dispatch(
setLocalisation({
country: {
code: regionParams?.[currentLang]?.code,
name: regionParams?.[currentLang]?.nom,
},
userChosen: false,
})
)
} else {
asyncFecthAPI()
}

asyncFecthAPI()
return undefined
}, [localisation, iframeLocalisationOption])

Expand Down

0 comments on commit 6f7965c

Please sign in to comment.