Skip to content

Commit

Permalink
fix: don't render application until we are sure the locale is initial…
Browse files Browse the repository at this point in the history
…ized (#525)
  • Loading branch information
amcgee authored Mar 2, 2021
1 parent 1aba628 commit 4329e8e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
6 changes: 4 additions & 2 deletions adapter/src/components/AuthBoundary.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ const settingsQuery = {

export const AuthBoundary = ({ url, children }) => {
const { loading, error, data } = useDataQuery(settingsQuery)
useLocale(data && data.userSettings.keyUiLocale)
const locale = useLocale(
data && (data.userSettings.keyUiLocale || window.navigator.language)
)

if (loading) {
if (loading || !locale) {
return <LoadingMask />
}

Expand Down
10 changes: 8 additions & 2 deletions adapter/src/utils/useLocale.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import i18n from '@dhis2/d2-i18n'
import moment from 'moment'
import { useEffect } from 'react'
import { useState, useEffect } from 'react'

i18n.setDefaultNamespace('default')

Expand All @@ -27,7 +27,13 @@ const setGlobalLocale = locale => {
}

export const useLocale = locale => {
const [result, setResult] = useState(undefined)
useEffect(() => {
setGlobalLocale(locale || window.navigator.language)
if (!locale) {
return
}
setGlobalLocale(locale)
setResult(locale)
}, [locale])
return result
}

0 comments on commit 4329e8e

Please sign in to comment.