Skip to content

Commit

Permalink
feat(webapp): show a message when select a language with an incomplet…
Browse files Browse the repository at this point in the history
…e translation
  • Loading branch information
Torresmorah committed Nov 24, 2023
1 parent 2e874e1 commit 5273496
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 3 deletions.
5 changes: 4 additions & 1 deletion webapp/src/components/Header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { useTranslation } from 'react-i18next'
import LocaleLink from 'components/LocaleLink'
import ToggleColorMode from 'components/ToggleColorMode'
import { generalConfig } from '../../config'
import useAlertTranslationState from '../../hooks/customHooks/useAlertTranslationState'

import AntelopeLogoSvg from './AntelopeLogo'
import styles from './styles'
Expand Down Expand Up @@ -49,6 +50,7 @@ const LanguageMenu = () => {
const [anchorMenu, setAnchorMenu] = useState(null)
const { i18n } = useTranslation('translations')
const location = useLocation()
const [,{ showAlertMessage }] = useAlertTranslationState()

const toggleMenu = (event) => {
setAnchorMenu(event.currentTarget)
Expand All @@ -57,8 +59,9 @@ const LanguageMenu = () => {
const closeMenu = (language) => {
setAnchorMenu(null)

if (typeof language === 'string') {
if (typeof language === 'string' && language !== i18n.language) {
i18n.changeLanguage(language)
showAlertMessage(language, true)
}
}

Expand Down
1 change: 1 addition & 0 deletions webapp/src/config/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const healthLights = Object.freeze({
export const defaultLanguage = 'en'
export const languageResources = resources
export const languages = Object.keys(resources)
export const languagesInProgress = ['ko','zh']

Check warning on line 36 in webapp/src/config/general.js

View check run for this annotation

codefactor.io / CodeFactor

webapp/src/config/general.js#L36

A space is required after ','. (comma-spacing)
export const languagesLabels = {
'es': 'Español',
'en': 'English',
Expand Down
24 changes: 24 additions & 0 deletions webapp/src/context/state.context.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,19 @@ const sharedStateReducer = (state, action) => {
}
}

case 'updateTranslationAlertsState': {
return {
...state,
translationinProgress: {
...state.translationinProgress,
isAlertShown: {
...state.translationinProgress.isAlertShown,
[action.payload]: true
}
},
}
}

default: {
throw new Error(`Unsupported action type: ${action.type}`)
}
Expand All @@ -122,6 +135,9 @@ const initialValue = {
tps: new Array(30).fill({ blocks: [], transactions: 0 }),
tpb: new Array(60).fill({ blocks: [], transactions: 0 }),
tpsWaitingBlock: null,
translationinProgress: {
isAlertShown: {}
}
}

export const SharedStateProvider = ({ ...props }) => {
Expand Down Expand Up @@ -315,6 +331,13 @@ export const useSharedState = () => {
scheduleInterval = null
}

const updateTranslationAlertsState = language => {
dispatch({
type: 'updateTranslationAlertsState',
payload: language,
})
}

return [
state,
{
Expand All @@ -327,6 +350,7 @@ export const useSharedState = () => {
stopTrackingInfo,
startTrackingInfo,
startTrackingProducerSchedule,
updateTranslationAlertsState
},
]
}
31 changes: 31 additions & 0 deletions webapp/src/hooks/customHooks/useAlertTranslationState.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { useTranslation } from 'react-i18next'

import { useSharedState } from '../../context/state.context'
import { useSnackbarMessageState } from '../../context/snackbar-message.context'
import { generalConfig } from '../../config'

const useAlertTranslationState = () => {
const [{ translationinProgress }, { updateTranslationAlertsState }] =
useSharedState()
const [, { showMessage }] = useSnackbarMessageState()
const { t } = useTranslation('')

const showAlertMessage = (language, ignoreStatus = false) => {
if (!generalConfig.languagesInProgress.includes(language)) return
if (!ignoreStatus && translationinProgress?.isAlertShown[language]) return

showMessage({
type: 'info',
content: t('translationInProgress'),
anchorOrigin: {
vertical: 'top',
horizontal: 'center',
}
})
updateTranslationAlertsState(language)
}

return [{}, { showAlertMessage }]
}

export default useAlertTranslationState
3 changes: 2 additions & 1 deletion webapp/src/language/ko/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
"secondsAgo": "Seconds Ago",
"metaTitle": "Antelope Tools network monitors real-time infrastructure data for multiple Antelope and EOSIO chains.",
"metaDescription": "Antelope Tools Dashboard is a network monitor featuring real-time data on block producer nodes and blockchain infrastructure for multiple Antelope and EOSIO chains.",
"goBack": "Go Back"
"goBack": "Go Back",
"translationInProgress": "This translation is in progress, if you find an error please let us know."
},
"routes": {
"/>sidebar": "Dashboard",
Expand Down
3 changes: 2 additions & 1 deletion webapp/src/language/zh/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
"secondsAgo": "Seconds Ago",
"metaTitle": "Antelope Tools network monitors real-time infrastructure data for multiple Antelope and EOSIO chains.",
"metaDescription": "Antelope Tools Dashboard is a network monitor featuring real-time data on block producer nodes and blockchain infrastructure for multiple Antelope and EOSIO chains.",
"goBack": "Go Back"
"goBack": "Go Back",
"translationInProgress": "This translation is in progress, if you find an error please let us know."
},
"routes": {
"/>sidebar": "Dashboard",
Expand Down
6 changes: 6 additions & 0 deletions webapp/src/layouts/Dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
getLanguageFromPath,
removeLanguageFromPath,
} from 'utils/url-localization'
import useAlertTranslationState from '../hooks/customHooks/useAlertTranslationState'

import styles from './styles'

Expand Down Expand Up @@ -55,6 +56,7 @@ const Dashboard = ({ children }) => {
const location = useLocation()
const [lacchain] = useSharedState()
const [routeName, setRouteName] = useState(INIT_VALUES)
const [,{ showAlertMessage }] = useAlertTranslationState()

const navigate = useNavigate()

Expand Down Expand Up @@ -91,6 +93,10 @@ const Dashboard = ({ children }) => {
}
}

if(generalConfig.languagesInProgress.includes(selectedLanguage)) {
showAlertMessage(selectedLanguage)
}

const route = routes.find(route =>
route.useParams
? removeParam(route.path) === removeParam(path)
Expand Down

0 comments on commit 5273496

Please sign in to comment.