From e8a0b401f97c3cd4d068eb4c6efc8df10dd0b276 Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Tue, 27 Dec 2022 22:02:55 +0800 Subject: [PATCH] Add safe fallback --- src/components/compose.jsx | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/components/compose.jsx b/src/components/compose.jsx index 6cb26937..67b679d4 100644 --- a/src/components/compose.jsx +++ b/src/components/compose.jsx @@ -51,6 +51,8 @@ const menu = document.createElement('ul'); menu.role = 'listbox'; menu.className = 'text-expander-menu'; +const DEFAULT_LANG = 'en'; + function Compose({ onClose, replyToStatus, @@ -104,7 +106,7 @@ function Compose({ const [visibility, setVisibility] = useState('public'); const [sensitive, setSensitive] = useState(false); const [language, setLanguage] = useState( - store.session.get('currentLanguage') || 'en', + store.session.get('currentLanguage') || DEFAULT_LANG, ); const [mediaAttachments, setMediaAttachments] = useState([]); const [poll, setPoll] = useState(null); @@ -154,7 +156,7 @@ function Compose({ } focusTextarea(); setVisibility(visibility); - setLanguage(language); + setLanguage(language || DEFAULT_LANG); setSensitive(sensitive); } if (draftStatus) { @@ -177,7 +179,7 @@ function Compose({ focusTextarea(); spoilerTextRef.current.value = spoilerText; setVisibility(visibility); - setLanguage(language); + setLanguage(language || DEFAULT_LANG); setSensitive(sensitive); setPoll(composablePoll); setMediaAttachments(mediaAttachments); @@ -203,7 +205,7 @@ function Compose({ focusTextarea(); spoilerTextRef.current.value = spoilerText; setVisibility(visibility); - setLanguage(language); + setLanguage(language || DEFAULT_LANG); setSensitive(sensitive); setPoll(composablePoll); setMediaAttachments(mediaAttachments); @@ -955,14 +957,14 @@ function Compose({ )}