Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't render application until we are sure the locale is initialized #525

Merged
merged 1 commit into from
Mar 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}