From 7a7d07203efd6b269e083e330ee99703d8707fc3 Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Mon, 20 Jul 2020 00:04:57 +0300 Subject: [PATCH] Close language switcher popup not earlier than locale will be loaded and applied --- .../app/components/languageSwitcher/LanguageSwitcher.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/app/components/languageSwitcher/LanguageSwitcher.tsx b/packages/app/components/languageSwitcher/LanguageSwitcher.tsx index 8c90d1e..0898f8e 100644 --- a/packages/app/components/languageSwitcher/LanguageSwitcher.tsx +++ b/packages/app/components/languageSwitcher/LanguageSwitcher.tsx @@ -17,9 +17,11 @@ const LanguageSwitcher: ComponentType = ({ onClose = () => {} }) => { const onChangeLang = useCallback( (lang: string) => { - dispatch(changeLang(lang)); - // TODO: await language change and close popup, but not earlier than after 300ms - setTimeout(onClose, 300); + Promise.all([ + // 300ms is necessary for the visual animation of the language change to be completed + new Promise((resolve) => setTimeout(resolve, 300)), + dispatch(changeLang(lang)), + ]).then(onClose); }, [dispatch, onClose], );