mirror of
https://github.com/mue/mue.git
synced 2026-06-08 22:18:40 +02:00
feat(Language): remove unused quote language functionality and clean up code
This commit is contained in:
@@ -1,8 +1,7 @@
|
|||||||
import { useState, useEffect, useRef, useMemo } from 'react';
|
import { useState, useMemo } from 'react';
|
||||||
import { useT, useTranslation } from 'contexts/TranslationContext';
|
import { useT, useTranslation } from 'contexts/TranslationContext';
|
||||||
import variables from 'config/variables';
|
|
||||||
|
|
||||||
import { MdOutlineOpenInNew, MdSearch } from 'react-icons/md';
|
import { MdOutlineOpenInNew, MdSearch, MdComputer } from 'react-icons/md';
|
||||||
import { TextField, InputAdornment } from '@mui/material';
|
import { TextField, InputAdornment } from '@mui/material';
|
||||||
|
|
||||||
import { Radio } from 'components/Form/Settings';
|
import { Radio } from 'components/Form/Settings';
|
||||||
@@ -12,10 +11,7 @@ import languages from '@/i18n/languages.json';
|
|||||||
const LanguageOptions = () => {
|
const LanguageOptions = () => {
|
||||||
const t = useT();
|
const t = useT();
|
||||||
const { language: currentLanguage, changeLanguage } = useTranslation();
|
const { language: currentLanguage, changeLanguage } = useTranslation();
|
||||||
const loadingText = t('modals.main.loading');
|
|
||||||
const offlineText = t('modals.main.marketplace.offline.description');
|
|
||||||
const languageTitle = t('modals.main.settings.sections.language.title');
|
const languageTitle = t('modals.main.settings.sections.language.title');
|
||||||
const quoteTitle = t('modals.main.settings.sections.language.quote');
|
|
||||||
|
|
||||||
const [searchQuery, setSearchQuery] = useState('');
|
const [searchQuery, setSearchQuery] = useState('');
|
||||||
|
|
||||||
@@ -86,64 +82,6 @@ const LanguageOptions = () => {
|
|||||||
// Find current language option for display
|
// Find current language option for display
|
||||||
const currentLangOption = languageOptions.find(l => l.value === currentLanguage);
|
const currentLangOption = languageOptions.find(l => l.value === currentLanguage);
|
||||||
|
|
||||||
const [quoteLanguages, setQuoteLanguages] = useState([
|
|
||||||
{
|
|
||||||
name: loadingText,
|
|
||||||
value: 'loading',
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
|
|
||||||
const controllerRef = useRef(new AbortController());
|
|
||||||
|
|
||||||
const getquoteLanguages = async () => {
|
|
||||||
try {
|
|
||||||
const data = await (
|
|
||||||
await fetch(variables.constants.API_URL + '/quotes/languages', {
|
|
||||||
signal: controllerRef.current.signal,
|
|
||||||
})
|
|
||||||
).json();
|
|
||||||
|
|
||||||
if (controllerRef.current.signal.aborted === true) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const fetchedQuoteLanguages = data.map((language) => {
|
|
||||||
return {
|
|
||||||
name: languages.find((l) => l.value === language.name)
|
|
||||||
? languages.find((l) => l.value === language.name).name
|
|
||||||
: 'English',
|
|
||||||
value: language,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
setQuoteLanguages(fetchedQuoteLanguages);
|
|
||||||
} catch (error) {
|
|
||||||
if (error.name !== 'AbortError') {
|
|
||||||
console.error('Failed to fetch quote languages:', error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (navigator.onLine === false || localStorage.getItem('offlineMode') === 'true') {
|
|
||||||
setQuoteLanguages([
|
|
||||||
{
|
|
||||||
name: offlineText,
|
|
||||||
value: 'loading',
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
getquoteLanguages();
|
|
||||||
|
|
||||||
const controller = controllerRef.current;
|
|
||||||
return () => {
|
|
||||||
// stop making requests
|
|
||||||
controller.abort();
|
|
||||||
};
|
|
||||||
}, [offlineText]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="modalHeader">
|
<div className="modalHeader">
|
||||||
@@ -201,29 +139,38 @@ const LanguageOptions = () => {
|
|||||||
</div>
|
</div>
|
||||||
{systemLanguage && systemLanguage.value !== currentLanguage && (
|
{systemLanguage && systemLanguage.value !== currentLanguage && (
|
||||||
<button
|
<button
|
||||||
className="uploadbg"
|
|
||||||
onClick={() => changeLanguage(systemLanguage.value)}
|
onClick={() => changeLanguage(systemLanguage.value)}
|
||||||
style={{ marginBottom: 12 }}
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
gap: '8px',
|
||||||
|
padding: '10px 16px',
|
||||||
|
marginBottom: 16,
|
||||||
|
background: 'rgba(255, 255, 255, 0.08)',
|
||||||
|
border: '1px solid rgba(255, 255, 255, 0.1)',
|
||||||
|
borderRadius: '8px',
|
||||||
|
color: 'var(--fg)',
|
||||||
|
cursor: 'pointer',
|
||||||
|
fontSize: '14px',
|
||||||
|
transition: 'all 0.2s ease',
|
||||||
|
}}
|
||||||
|
onMouseEnter={(e) => {
|
||||||
|
e.currentTarget.style.background = 'rgba(255, 255, 255, 0.12)';
|
||||||
|
e.currentTarget.style.borderColor = 'rgba(255, 255, 255, 0.2)';
|
||||||
|
}}
|
||||||
|
onMouseLeave={(e) => {
|
||||||
|
e.currentTarget.style.background = 'rgba(255, 255, 255, 0.08)';
|
||||||
|
e.currentTarget.style.borderColor = 'rgba(255, 255, 255, 0.1)';
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{t('modals.main.settings.sections.language.use_system')} ({systemLanguage.name})
|
<MdComputer style={{ fontSize: '18px', opacity: 0.8 }} />
|
||||||
|
{t('modals.main.settings.sections.language.use_system')}
|
||||||
|
<span style={{ opacity: 0.6 }}>({systemLanguage.name})</span>
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
<div className="languageSettings">
|
<div className="languageSettings">
|
||||||
<Radio name="language" options={filteredLanguages} element=".other" />
|
<Radio name="language" options={filteredLanguages} element=".other" />
|
||||||
</div>
|
</div>
|
||||||
<span className="mainTitle">
|
|
||||||
{quoteTitle}
|
|
||||||
</span>
|
|
||||||
<div className="languageSettings">
|
|
||||||
<Radio
|
|
||||||
name="quoteLanguage"
|
|
||||||
options={quoteLanguages.map((language) => {
|
|
||||||
return { name: language.name, value: language.value.name };
|
|
||||||
})}
|
|
||||||
defaultValue={quoteLanguages[0].name}
|
|
||||||
category="quote"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -156,9 +156,8 @@ export function useQuoteLoader(updateQuote) {
|
|||||||
if (offline) return doOffline();
|
if (offline) return doOffline();
|
||||||
|
|
||||||
const fetchAPIQuote = async () => {
|
const fetchAPIQuote = async () => {
|
||||||
const quoteLanguage = localStorage.getItem('quoteLanguage');
|
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
`${variables.constants.API_URL}/quotes/random?language=${quoteLanguage}`
|
`${variables.constants.API_URL}/quotes/random`
|
||||||
).then(res => res.json());
|
).then(res => res.json());
|
||||||
|
|
||||||
if (response.statusCode === 429) return null;
|
if (response.statusCode === 429) return null;
|
||||||
@@ -169,7 +168,6 @@ export function useQuoteLoader(updateQuote) {
|
|||||||
author: response.author,
|
author: response.author,
|
||||||
authorlink: getAuthorLink(response.author),
|
authorlink: getAuthorLink(response.author),
|
||||||
...authorimgdata,
|
...authorimgdata,
|
||||||
quoteLanguage,
|
|
||||||
authorOccupation: response.author_occupation,
|
authorOccupation: response.author_occupation,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ export function useQuoteState() {
|
|||||||
authorlink: null,
|
authorlink: null,
|
||||||
authorimg: null,
|
authorimg: null,
|
||||||
authorimglicense: null,
|
authorimglicense: null,
|
||||||
quoteLanguage: '',
|
|
||||||
noQuote: false,
|
noQuote: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -87,10 +87,6 @@
|
|||||||
"name": "showWelcome",
|
"name": "showWelcome",
|
||||||
"value": true
|
"value": true
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"name": "quoteLanguage",
|
|
||||||
"value": "en"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"name": "date",
|
"name": "date",
|
||||||
"value": "false"
|
"value": "false"
|
||||||
|
|||||||
Reference in New Issue
Block a user