[build] upgrade eslint to 9.37.0 (#88)
Co-authored-by: tobi <tobi.smethurst@protonmail.com> Reviewed-on: https://codeberg.org/superseriousbusiness/masto-fe-standalone/pulls/88 Co-authored-by: Zoë Bijl <moiety@noreply.codeberg.org> Co-committed-by: Zoë Bijl <moiety@noreply.codeberg.org>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
export interface LocaleData {
|
||||
locale: string;
|
||||
messages: Record<string, string>;
|
||||
locale: string,
|
||||
messages: Record<string, string>,
|
||||
}
|
||||
|
||||
let loadedLocale: LocaleData | undefined;
|
||||
@@ -11,10 +11,10 @@ export function setLocale(locale: LocaleData) {
|
||||
|
||||
export function getLocale(): LocaleData {
|
||||
if (!loadedLocale) {
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
throw new Error('getLocale() called before any locale has been set');
|
||||
if (process.env.NODE_ENV === "development") {
|
||||
throw new Error("getLocale() called before any locale has been set");
|
||||
} else {
|
||||
return { locale: 'unknown', messages: {} };
|
||||
return { locale: "unknown", messages: {} };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
export type { LocaleData } from './global_locale';
|
||||
export { setLocale, getLocale, isLocaleLoaded } from './global_locale';
|
||||
export { loadLocale } from './load_locale';
|
||||
export type { LocaleData } from "./global_locale";
|
||||
export { setLocale, getLocale, isLocaleLoaded } from "./global_locale";
|
||||
export { loadLocale } from "./load_locale";
|
||||
|
||||
export { IntlProvider } from './intl_provider';
|
||||
export { IntlProvider } from "./intl_provider";
|
||||
|
||||
@@ -1,21 +1,23 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
import { IntlProvider as BaseIntlProvider } from 'react-intl';
|
||||
import { IntlProvider as BaseIntlProvider } from "react-intl";
|
||||
|
||||
import { getLocale, isLocaleLoaded } from './global_locale';
|
||||
import { loadLocale } from './load_locale';
|
||||
import { getLocale, isLocaleLoaded } from "./global_locale";
|
||||
import { loadLocale } from "./load_locale";
|
||||
|
||||
function onProviderError(error: unknown) {
|
||||
// Silent the error, like upstream does
|
||||
if (process.env.NODE_ENV === 'production') return;
|
||||
if (process.env.NODE_ENV === "production") {
|
||||
return;
|
||||
}
|
||||
|
||||
// This browser does not advertise Intl support for this locale, we only print a warning
|
||||
// As-per the spec, the browser should select the best matching locale
|
||||
if (
|
||||
error &&
|
||||
typeof error === 'object' &&
|
||||
typeof error === "object" &&
|
||||
error instanceof Error &&
|
||||
error.message.match('MISSING_DATA')
|
||||
error.message.match("MISSING_DATA")
|
||||
) {
|
||||
console.warn(error.message);
|
||||
}
|
||||
@@ -24,7 +26,7 @@ function onProviderError(error: unknown) {
|
||||
}
|
||||
|
||||
export const IntlProvider: React.FC<
|
||||
Omit<React.ComponentProps<typeof BaseIntlProvider>, 'locale' | 'messages'>
|
||||
Omit<React.ComponentProps<typeof BaseIntlProvider>, "locale" | "messages">
|
||||
> = ({ children, ...props }) => {
|
||||
const [localeLoaded, setLocaleLoaded] = useState(false);
|
||||
|
||||
@@ -39,7 +41,9 @@ export const IntlProvider: React.FC<
|
||||
void loadLocaleData();
|
||||
}, []);
|
||||
|
||||
if (!localeLoaded) return null;
|
||||
if (!localeLoaded) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const { locale, messages } = getLocale();
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { Semaphore } from 'async-mutex';
|
||||
import { Semaphore } from "async-mutex";
|
||||
|
||||
import type { LocaleData } from './global_locale';
|
||||
import { isLocaleLoaded, setLocale } from './global_locale';
|
||||
import { type LocaleData } from "./global_locale";
|
||||
import { isLocaleLoaded, setLocale } from "./global_locale";
|
||||
|
||||
const localeLoadingSemaphore = new Semaphore(1);
|
||||
|
||||
export async function loadLocale() {
|
||||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- we want to match empty strings
|
||||
const locale = document.querySelector<HTMLElement>('html')?.lang || 'en';
|
||||
|
||||
const locale = document.querySelector<HTMLElement>("html")?.lang || "en";
|
||||
|
||||
// We use a Semaphore here so only one thing can try to load the locales at
|
||||
// the same time. If one tries to do it while its in progress, it will wait
|
||||
@@ -15,15 +15,17 @@ export async function loadLocale() {
|
||||
// data is already loaded)
|
||||
await localeLoadingSemaphore.runExclusive(async () => {
|
||||
// if the locale is already set, then do nothing
|
||||
if (isLocaleLoaded()) return;
|
||||
if (isLocaleLoaded()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const localeData = (await import(
|
||||
/* webpackMode: "lazy" */
|
||||
/* webpackChunkName: "locales/vanilla/[request]" */
|
||||
/* webpackInclude: /\.json$/ */
|
||||
/* webpackPreload: true */
|
||||
`mastodon/locales/${locale}.json`
|
||||
)) as LocaleData['messages'];
|
||||
`mastodon/locales/${locale}.json`,
|
||||
)) as LocaleData["messages"];
|
||||
|
||||
setLocale({ messages: localeData, locale });
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user