1
0
mirror of https://github.com/funamitech/mastodon synced 2024-12-12 05:39:02 +09:00

[Glitch] Upgrade react-intl

Port 44cd88adc4 to glitch-soc

Signed-off-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
Renaud Chaput 2023-05-31 23:43:39 +02:00 committed by Claire
parent 85722a918d
commit 9e133e2527
111 changed files with 168 additions and 1349 deletions

View File

@ -1,4 +1,4 @@
import IntlMessageFormat from 'intl-messageformat';
import { IntlMessageFormat } from 'intl-messageformat';
import { defineMessages } from 'react-intl';
import { List as ImmutableList } from 'immutable';

View File

@ -1,8 +1,7 @@
import { useCallback } from 'react';
import * as React from 'react';
import type { InjectedIntl } from 'react-intl';
import { defineMessages, injectIntl } from 'react-intl';
import { defineMessages, useIntl } from 'react-intl';
import { IconButton } from './icon_button';
@ -16,9 +15,11 @@ const messages = defineMessages({
interface Props {
domain: string;
onUnblockDomain: (domain: string) => void;
intl: InjectedIntl;
}
const _Domain: React.FC<Props> = ({ domain, onUnblockDomain, intl }) => {
export const Domain: React.FC<Props> = ({ domain, onUnblockDomain }) => {
const intl = useIntl();
const handleDomainUnblock = useCallback(() => {
onUnblockDomain(domain);
}, [domain, onUnblockDomain]);
@ -42,5 +43,3 @@ const _Domain: React.FC<Props> = ({ domain, onUnblockDomain, intl }) => {
</div>
);
};
export const Domain = injectIntl(_Domain);

View File

@ -1,7 +1,6 @@
import { useCallback } from 'react';
import type { InjectedIntl } from 'react-intl';
import { injectIntl, defineMessages } from 'react-intl';
import { useIntl, defineMessages } from 'react-intl';
import { Icon } from 'flavours/glitch/components/icon';
@ -13,10 +12,11 @@ interface Props {
disabled: boolean;
maxId: string;
onClick: (maxId: string) => void;
intl: InjectedIntl;
}
const _LoadGap: React.FC<Props> = ({ disabled, maxId, onClick, intl }) => {
export const LoadGap: React.FC<Props> = ({ disabled, maxId, onClick }) => {
const intl = useIntl();
const handleClick = useCallback(() => {
onClick(maxId);
}, [maxId, onClick]);
@ -32,5 +32,3 @@ const _LoadGap: React.FC<Props> = ({ disabled, maxId, onClick, intl }) => {
</button>
);
};
export const LoadGap = injectIntl(_LoadGap);

View File

@ -1,6 +1,6 @@
import { Component } from 'react';
import type { InjectedIntl } from 'react-intl';
import type { IntlShape } from 'react-intl';
import { injectIntl, defineMessages } from 'react-intl';
const messages = defineMessages({
@ -103,7 +103,7 @@ const getUnitDelay = (units: string) => {
};
export const timeAgoString = (
intl: InjectedIntl,
intl: IntlShape,
date: Date,
now: number,
year: number,
@ -155,7 +155,7 @@ export const timeAgoString = (
};
const timeRemainingString = (
intl: InjectedIntl,
intl: IntlShape,
date: Date,
now: number,
timeGiven = true
@ -190,7 +190,7 @@ const timeRemainingString = (
};
interface Props {
intl: InjectedIntl;
intl: IntlShape;
timestamp: string;
year: number;
futureDate?: boolean;
@ -201,7 +201,7 @@ interface States {
}
class RelativeTimestamp extends Component<Props, States> {
state = {
now: this.props.intl.now(),
now: Date.now(),
};
static defaultProps = {
@ -223,7 +223,7 @@ class RelativeTimestamp extends Component<Props, States> {
UNSAFE_componentWillReceiveProps(nextProps: Props) {
if (this.props.timestamp !== nextProps.timestamp) {
this.setState({ now: this.props.intl.now() });
this.setState({ now: Date.now() });
}
}
@ -253,7 +253,7 @@ class RelativeTimestamp extends Component<Props, States> {
: Math.max(updateInterval, unitRemainder);
this._timer = window.setTimeout(() => {
this.setState({ now: this.props.intl.now() });
this.setState({ now: Date.now() });
}, delay);
}

View File

@ -1,12 +1,11 @@
import PropTypes from 'prop-types';
import { PureComponent } from 'react';
import { IntlProvider, addLocaleData } from 'react-intl';
import { IntlProvider } from 'react-intl';
import { getLocale } from 'mastodon/locales';
import { getLocale, onProviderError } from 'mastodon/locales';
const { localeData, messages } = getLocale();
addLocaleData(localeData);
const { messages } = getLocale();
export default class AdminComponent extends PureComponent {
@ -19,7 +18,7 @@ export default class AdminComponent extends PureComponent {
const { locale, children } = this.props;
return (
<IntlProvider locale={locale} messages={messages}>
<IntlProvider locale={locale} messages={messages} onError={onProviderError}>
{children}
</IntlProvider>
);

View File

@ -1,7 +1,7 @@
import PropTypes from 'prop-types';
import { PureComponent } from 'react';
import { IntlProvider, addLocaleData } from 'react-intl';
import { IntlProvider } from 'react-intl';
import { Provider } from 'react-redux';
@ -11,10 +11,9 @@ import Compose from 'flavours/glitch/features/standalone/compose';
import initialState from 'flavours/glitch/initial_state';
import { store } from 'flavours/glitch/store';
import { getLocale } from 'mastodon/locales';
import { getLocale, onProviderError } from 'mastodon/locales';
const { localeData, messages } = getLocale();
addLocaleData(localeData);
const { messages } = getLocale();
if (initialState) {
store.dispatch(hydrateStore(initialState));
@ -32,7 +31,7 @@ export default class TimelineContainer extends PureComponent {
const { locale } = this.props;
return (
<IntlProvider locale={locale} messages={messages}>
<IntlProvider locale={locale} messages={messages} onError={onProviderError}>
<Provider store={store}>
<Compose />
</Provider>

View File

@ -1,7 +1,7 @@
import PropTypes from 'prop-types';
import { PureComponent } from 'react';
import { IntlProvider, addLocaleData } from 'react-intl';
import { IntlProvider } from 'react-intl';
import { Helmet } from 'react-helmet';
import { BrowserRouter, Route } from 'react-router-dom';
@ -18,10 +18,9 @@ import ErrorBoundary from 'flavours/glitch/components/error_boundary';
import UI from 'flavours/glitch/features/ui';
import initialState, { title as siteTitle } from 'flavours/glitch/initial_state';
import { store } from 'flavours/glitch/store';
import { getLocale } from 'locales';
import { getLocale, onProviderError } from 'locales';
const { localeData, messages } = getLocale();
addLocaleData(localeData);
const { messages } = getLocale();
const title = process.env.NODE_ENV === 'production' ? siteTitle : `${siteTitle} (Dev)`;
@ -87,7 +86,7 @@ export default class Mastodon extends PureComponent {
const { locale } = this.props;
return (
<IntlProvider locale={locale} messages={messages}>
<IntlProvider locale={locale} messages={messages} onError={onProviderError}>
<ReduxProvider store={store}>
<ErrorBoundary>
<BrowserRouter>

View File

@ -2,7 +2,7 @@ import PropTypes from 'prop-types';
import { PureComponent } from 'react';
import { createPortal } from 'react-dom';
import { IntlProvider, addLocaleData } from 'react-intl';
import { IntlProvider } from 'react-intl';
import { fromJS } from 'immutable';
@ -16,10 +16,9 @@ import MediaModal from 'flavours/glitch/features/ui/components/media_modal';
import Video from 'flavours/glitch/features/video';
import { getScrollbarWidth } from 'flavours/glitch/utils/scrollbar';
import { getLocale } from 'mastodon/locales';
import { getLocale, onProviderError } from 'mastodon/locales';
const { localeData, messages } = getLocale();
addLocaleData(localeData);
const { messages } = getLocale();
const MEDIA_COMPONENTS = { MediaGallery, Video, Card, Poll, Hashtag, Audio };
@ -85,7 +84,7 @@ export default class MediaContainer extends PureComponent {
}
return (
<IntlProvider locale={locale} messages={messages}>
<IntlProvider locale={locale} messages={messages} onError={onProviderError}>
<>
{[].map.call(components, (component, i) => {
const componentName = component.getAttribute('data-component');

View File

@ -0,0 +1,21 @@
import { setLocale } from 'locales';
export async function loadLocale() {
const locale = document.querySelector('html').lang || 'en';
const upstreamLocaleData = await import(
/* webpackMode: "lazy" */
/* webpackChunkName: "locales/vanilla/[request]" */
/* webpackInclude: /\.json$/ */
/* webpackPreload: true */
`mastodon/locales/${locale}.json`);
const localeData = await import(
/* webpackMode: "lazy" */
/* webpackChunkName: "locales/glitch/[request]" */
/* webpackInclude: /\.json$/ */
/* webpackPreload: true */
`flavours/glitch/locales/${locale}.json`);
setLocale({ messages: {...upstreamLocaleData, ...localeData} });
}

File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More