Always pass a valid iso language code to the API, refresh global feed when language changes
This commit is contained in:
parent
6b8698ea42
commit
7b1a180966
|
@ -214,7 +214,7 @@ const expandHomeTimeline = ({ url, maxId }: ExpandHomeTimelineOpts = {}, done =
|
||||||
};
|
};
|
||||||
|
|
||||||
const expandPublicTimeline = ({ url, maxId, onlyMedia, language }: Record<string, any> = {}, done = noOp) =>
|
const expandPublicTimeline = ({ url, maxId, onlyMedia, language }: Record<string, any> = {}, done = noOp) =>
|
||||||
expandTimeline(`public${onlyMedia ? ':media' : ''}`, url || '/api/v1/timelines/public', url ? {} : { max_id: maxId, only_media: !!onlyMedia, language }, done);
|
expandTimeline(`public${onlyMedia ? ':media' : ''}`, url || '/api/v1/timelines/public', url ? {} : { max_id: maxId, only_media: !!onlyMedia, language: language || undefined }, done);
|
||||||
|
|
||||||
const expandRemoteTimeline = (instance: string, { url, maxId, onlyMedia }: Record<string, any> = {}, done = noOp) =>
|
const expandRemoteTimeline = (instance: string, { url, maxId, onlyMedia }: Record<string, any> = {}, done = noOp) =>
|
||||||
expandTimeline(`remote${onlyMedia ? ':media' : ''}:${instance}`, url || '/api/v1/timelines/public', url ? {} : { local: false, instance: instance, max_id: maxId, only_media: !!onlyMedia }, done);
|
expandTimeline(`remote${onlyMedia ? ':media' : ''}:${instance}`, url || '/api/v1/timelines/public', url ? {} : { local: false, instance: instance, max_id: maxId, only_media: !!onlyMedia }, done);
|
||||||
|
|
|
@ -11,7 +11,7 @@ function usePublicStream({ onlyMedia, language }: UsePublicStreamOpts = {}) {
|
||||||
`public${onlyMedia ? ':media' : ''}`,
|
`public${onlyMedia ? ':media' : ''}`,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
{ enabled: !language },
|
{ enabled: !language }, // TODO: support language streaming
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,13 +6,13 @@ import SvgIcon from 'soapbox/components/ui/icon/svg-icon';
|
||||||
import { languages } from 'soapbox/features/preferences';
|
import { languages } from 'soapbox/features/preferences';
|
||||||
import { useAppDispatch } from 'soapbox/hooks';
|
import { useAppDispatch } from 'soapbox/hooks';
|
||||||
|
|
||||||
const formatterLanguage = (lang: {}) => {
|
function formatLanguages(languageMap: Record<string, string>) {
|
||||||
const sigLanguage = Object.keys(lang).sort().map((sig) => {
|
const langCodes = Object.keys(languageMap).sort().map((sig) => {
|
||||||
return sig.substring(0, 2);
|
return sig.substring(0, 2);
|
||||||
});
|
});
|
||||||
|
|
||||||
return [...new Set(sigLanguage)];
|
return [...new Set(langCodes)];
|
||||||
};
|
}
|
||||||
|
|
||||||
interface ILanguageDropdown {
|
interface ILanguageDropdown {
|
||||||
language: string;
|
language: string;
|
||||||
|
@ -24,20 +24,20 @@ interface ILanguageDropdown {
|
||||||
*/
|
*/
|
||||||
const LanguageDropdown: React.FC<ILanguageDropdown> = ({ language, setLanguage }) => {
|
const LanguageDropdown: React.FC<ILanguageDropdown> = ({ language, setLanguage }) => {
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
const formattedLanguage = formatterLanguage(languages);
|
const formattedLanguages = formatLanguages(languages);
|
||||||
|
|
||||||
const newMenu: MenuItem[] = [{ icon: require('@tabler/icons/outline/world.svg'), text: 'Default', action: () => {
|
const newMenu: MenuItem[] = [{ icon: require('@tabler/icons/outline/world.svg'), text: 'Default', action: () => {
|
||||||
setLanguage('');
|
setLanguage('');
|
||||||
} }];
|
} }];
|
||||||
|
|
||||||
formattedLanguage.map((lg: string) => {
|
formattedLanguages.map((lang: string) => {
|
||||||
const languageText = languages[lg as keyof typeof languages];
|
const languageName = languages[lang as keyof typeof languages];
|
||||||
|
|
||||||
if (languageText !== undefined) {
|
if (languageName) {
|
||||||
newMenu.push({
|
newMenu.push({
|
||||||
text: `${lg.toUpperCase()} - ${languageText}`,
|
text: `${lang.toUpperCase()} - ${languageName}`,
|
||||||
action: () => {
|
action: () => {
|
||||||
setLanguage(lg.toUpperCase());
|
setLanguage(lang);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ const LanguageDropdown: React.FC<ILanguageDropdown> = ({ language, setLanguage }
|
||||||
<DropdownMenu items={newMenu} modal>
|
<DropdownMenu items={newMenu} modal>
|
||||||
{language ? (
|
{language ? (
|
||||||
<button type='button' className='flex h-full rounded-lg border-2 border-gray-700 px-1 text-gray-700 hover:cursor-pointer hover:border-gray-500 hover:text-gray-500 sm:mr-4 dark:border-white dark:text-white dark:hover:border-gray-700' onClick={() => dispatch(openDropdownMenu())}>
|
<button type='button' className='flex h-full rounded-lg border-2 border-gray-700 px-1 text-gray-700 hover:cursor-pointer hover:border-gray-500 hover:text-gray-500 sm:mr-4 dark:border-white dark:text-white dark:hover:border-gray-700' onClick={() => dispatch(openDropdownMenu())}>
|
||||||
{language}
|
{language.toUpperCase()}
|
||||||
</button>
|
</button>
|
||||||
) : (
|
) : (
|
||||||
<SvgIcon src={require('@tabler/icons/outline/world.svg')} className='text-gray-700 hover:cursor-pointer hover:text-gray-500 black:absolute black:right-0 black:top-4 black:text-white black:hover:text-gray-600 sm:mr-4 dark:text-white' />
|
<SvgIcon src={require('@tabler/icons/outline/world.svg')} className='text-gray-700 hover:cursor-pointer hover:text-gray-500 black:absolute black:right-0 black:top-4 black:text-white black:hover:text-gray-600 sm:mr-4 dark:text-white' />
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { defineMessages, FormattedMessage, useIntl } from 'react-intl';
|
||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
|
|
||||||
import { changeSetting } from 'soapbox/actions/settings';
|
import { changeSetting } from 'soapbox/actions/settings';
|
||||||
import { expandPublicTimeline } from 'soapbox/actions/timelines';
|
import { clearTimeline, expandPublicTimeline } from 'soapbox/actions/timelines';
|
||||||
import { usePublicStream } from 'soapbox/api/hooks';
|
import { usePublicStream } from 'soapbox/api/hooks';
|
||||||
import PullToRefresh from 'soapbox/components/pull-to-refresh';
|
import PullToRefresh from 'soapbox/components/pull-to-refresh';
|
||||||
import { Accordion, Column } from 'soapbox/components/ui';
|
import { Accordion, Column } from 'soapbox/components/ui';
|
||||||
|
@ -56,9 +56,15 @@ const PublicTimeline = () => {
|
||||||
|
|
||||||
usePublicStream({ onlyMedia, language });
|
usePublicStream({ onlyMedia, language });
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (language) {
|
||||||
|
dispatch(clearTimeline('public'));
|
||||||
|
}
|
||||||
|
}, [language]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
dispatch(expandPublicTimeline({ onlyMedia, language }));
|
dispatch(expandPublicTimeline({ onlyMedia, language }));
|
||||||
}, [onlyMedia]);
|
}, [onlyMedia, language]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Column
|
<Column
|
||||||
|
|
Loading…
Reference in New Issue