Add safe fallback

This commit is contained in:
Lim Chee Aun 2022-12-27 22:02:55 +08:00
parent a08a3e58fb
commit e8a0b401f9

View file

@ -51,6 +51,8 @@ const menu = document.createElement('ul');
menu.role = 'listbox'; menu.role = 'listbox';
menu.className = 'text-expander-menu'; menu.className = 'text-expander-menu';
const DEFAULT_LANG = 'en';
function Compose({ function Compose({
onClose, onClose,
replyToStatus, replyToStatus,
@ -104,7 +106,7 @@ function Compose({
const [visibility, setVisibility] = useState('public'); const [visibility, setVisibility] = useState('public');
const [sensitive, setSensitive] = useState(false); const [sensitive, setSensitive] = useState(false);
const [language, setLanguage] = useState( const [language, setLanguage] = useState(
store.session.get('currentLanguage') || 'en', store.session.get('currentLanguage') || DEFAULT_LANG,
); );
const [mediaAttachments, setMediaAttachments] = useState([]); const [mediaAttachments, setMediaAttachments] = useState([]);
const [poll, setPoll] = useState(null); const [poll, setPoll] = useState(null);
@ -154,7 +156,7 @@ function Compose({
} }
focusTextarea(); focusTextarea();
setVisibility(visibility); setVisibility(visibility);
setLanguage(language); setLanguage(language || DEFAULT_LANG);
setSensitive(sensitive); setSensitive(sensitive);
} }
if (draftStatus) { if (draftStatus) {
@ -177,7 +179,7 @@ function Compose({
focusTextarea(); focusTextarea();
spoilerTextRef.current.value = spoilerText; spoilerTextRef.current.value = spoilerText;
setVisibility(visibility); setVisibility(visibility);
setLanguage(language); setLanguage(language || DEFAULT_LANG);
setSensitive(sensitive); setSensitive(sensitive);
setPoll(composablePoll); setPoll(composablePoll);
setMediaAttachments(mediaAttachments); setMediaAttachments(mediaAttachments);
@ -203,7 +205,7 @@ function Compose({
focusTextarea(); focusTextarea();
spoilerTextRef.current.value = spoilerText; spoilerTextRef.current.value = spoilerText;
setVisibility(visibility); setVisibility(visibility);
setLanguage(language); setLanguage(language || DEFAULT_LANG);
setSensitive(sensitive); setSensitive(sensitive);
setPoll(composablePoll); setPoll(composablePoll);
setMediaAttachments(mediaAttachments); setMediaAttachments(mediaAttachments);
@ -955,14 +957,14 @@ function Compose({
)} )}
<label class="toolbar-button"> <label class="toolbar-button">
<span class="icon-text"> <span class="icon-text">
{supportedLanguagesMap[language].native} {supportedLanguagesMap[language]?.native}
</span> </span>
<select <select
name="language" name="language"
value={language} value={language}
onChange={(e) => { onChange={(e) => {
const { value } = e.target; const { value } = e.target;
setLanguage(value); setLanguage(value || DEFAULT_LANG);
store.session.set('language', value); store.session.set('language', value);
}} }}
disabled={uiState === 'loading'} disabled={uiState === 'loading'}