eslint warning fixes
This commit is contained in:
@ -1,12 +1,9 @@
|
|||||||
import { ExternalStore } from "@snort/shared";
|
import { ReactNode, useEffect, useState } from "react";
|
||||||
import { type ReactNode, useEffect, useState, useSyncExternalStore } from "react";
|
|
||||||
import { IntlProvider as ReactIntlProvider } from "react-intl";
|
import { IntlProvider as ReactIntlProvider } from "react-intl";
|
||||||
|
|
||||||
import useLogin from "@/Hooks/useLogin";
|
import { DefaultLocale, useLocale } from "@/Components/IntlProvider/IntlProviderUtils";
|
||||||
import enMessages from "@/translations/en.json";
|
import enMessages from "@/translations/en.json";
|
||||||
|
|
||||||
const DefaultLocale = "en-US";
|
|
||||||
|
|
||||||
const getMessages = (locale: string) => {
|
const getMessages = (locale: string) => {
|
||||||
const truncatedLocale = locale.toLowerCase().split(/[_-]+/)[0];
|
const truncatedLocale = locale.toLowerCase().split(/[_-]+/)[0];
|
||||||
|
|
||||||
@ -80,34 +77,6 @@ const getMessages = (locale: string) => {
|
|||||||
|
|
||||||
return matchLang(locale) ?? matchLang(truncatedLocale) ?? Promise.resolve(enMessages);
|
return matchLang(locale) ?? matchLang(truncatedLocale) ?? Promise.resolve(enMessages);
|
||||||
};
|
};
|
||||||
|
|
||||||
class LangStore extends ExternalStore<string | null> {
|
|
||||||
setLang(s: string) {
|
|
||||||
localStorage.setItem("lang", s);
|
|
||||||
this.notifyChange();
|
|
||||||
}
|
|
||||||
|
|
||||||
takeSnapshot() {
|
|
||||||
return localStorage.getItem("lang");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const LangOverride = new LangStore();
|
|
||||||
|
|
||||||
export function useLocale() {
|
|
||||||
const { language } = useLogin(s => ({ language: s.appData.item.preferences.language }));
|
|
||||||
const loggedOutLang = useSyncExternalStore(
|
|
||||||
c => LangOverride.hook(c),
|
|
||||||
() => LangOverride.snapshot(),
|
|
||||||
);
|
|
||||||
const locale = language ?? loggedOutLang ?? getLocale();
|
|
||||||
return {
|
|
||||||
locale,
|
|
||||||
lang: locale.toLowerCase().split(/[_-]+/)[0],
|
|
||||||
setOverride: (s: string) => LangOverride.setLang(s),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export const IntlProvider = ({ children }: { children: ReactNode }) => {
|
export const IntlProvider = ({ children }: { children: ReactNode }) => {
|
||||||
const { locale } = useLocale();
|
const { locale } = useLocale();
|
||||||
const [messages, setMessages] = useState<Record<string, string>>(enMessages);
|
const [messages, setMessages] = useState<Record<string, string>>(enMessages);
|
||||||
@ -128,7 +97,3 @@ export const IntlProvider = ({ children }: { children: ReactNode }) => {
|
|||||||
</ReactIntlProvider>
|
</ReactIntlProvider>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getLocale = () => {
|
|
||||||
return (navigator.languages && navigator.languages[0]) ?? navigator.language ?? DefaultLocale;
|
|
||||||
};
|
|
@ -0,0 +1,37 @@
|
|||||||
|
import { ExternalStore } from "@snort/shared";
|
||||||
|
import { useSyncExternalStore } from "react";
|
||||||
|
|
||||||
|
import useLogin from "@/Hooks/useLogin";
|
||||||
|
|
||||||
|
export const DefaultLocale = "en-US";
|
||||||
|
|
||||||
|
class LangStore extends ExternalStore<string | null> {
|
||||||
|
setLang(s: string) {
|
||||||
|
localStorage.setItem("lang", s);
|
||||||
|
this.notifyChange();
|
||||||
|
}
|
||||||
|
|
||||||
|
takeSnapshot() {
|
||||||
|
return localStorage.getItem("lang");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const LangOverride = new LangStore();
|
||||||
|
|
||||||
|
export function useLocale() {
|
||||||
|
const { language } = useLogin(s => ({ language: s.appData.item.preferences.language }));
|
||||||
|
const loggedOutLang = useSyncExternalStore(
|
||||||
|
c => LangOverride.hook(c),
|
||||||
|
() => LangOverride.snapshot(),
|
||||||
|
);
|
||||||
|
const locale = language ?? loggedOutLang ?? getLocale();
|
||||||
|
return {
|
||||||
|
locale,
|
||||||
|
lang: locale.toLowerCase().split(/[_-]+/)[0],
|
||||||
|
setOverride: (s: string) => LangOverride.setLang(s),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getLocale = () => {
|
||||||
|
return (navigator.languages && navigator.languages[0]) ?? navigator.language ?? DefaultLocale;
|
||||||
|
};
|
@ -310,4 +310,6 @@ class IrisAccount extends Component<Props> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default injectIntl(IrisAccount);
|
const IntlIrisAccount = injectIntl(IrisAccount);
|
||||||
|
IntlIrisAccount.displayName = "IrisAccount";
|
||||||
|
export default IntlIrisAccount;
|
||||||
|
@ -2,10 +2,10 @@ import classNames from "classnames";
|
|||||||
import { ReactNode } from "react";
|
import { ReactNode } from "react";
|
||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
|
|
||||||
|
import { useLocale } from "@/Components/IntlProvider/IntlProviderUtils";
|
||||||
import PageSpinner from "@/Components/PageSpinner";
|
import PageSpinner from "@/Components/PageSpinner";
|
||||||
import NostrBandApi from "@/External/NostrBand";
|
import NostrBandApi from "@/External/NostrBand";
|
||||||
import useCachedFetch from "@/Hooks/useCachedFetch";
|
import useCachedFetch from "@/Hooks/useCachedFetch";
|
||||||
import { useLocale } from "@/IntlProvider";
|
|
||||||
import { HashTagHeader } from "@/Pages/HashTagsPage";
|
import { HashTagHeader } from "@/Pages/HashTagsPage";
|
||||||
|
|
||||||
import { ErrorOrOffline } from "../ErrorOrOffline";
|
import { ErrorOrOffline } from "../ErrorOrOffline";
|
||||||
|
@ -7,6 +7,7 @@ import { ErrorOrOffline } from "@/Components/ErrorOrOffline";
|
|||||||
import Note from "@/Components/Event/EventComponent";
|
import Note from "@/Components/Event/EventComponent";
|
||||||
import { DisplayAs, DisplayAsSelector } from "@/Components/Feed/DisplayAsSelector";
|
import { DisplayAs, DisplayAsSelector } from "@/Components/Feed/DisplayAsSelector";
|
||||||
import ImageGridItem from "@/Components/Feed/ImageGridItem";
|
import ImageGridItem from "@/Components/Feed/ImageGridItem";
|
||||||
|
import { useLocale } from "@/Components/IntlProvider/IntlProviderUtils";
|
||||||
import PageSpinner from "@/Components/PageSpinner";
|
import PageSpinner from "@/Components/PageSpinner";
|
||||||
import { SpotlightThreadModal } from "@/Components/Spotlight/SpotlightThreadModal";
|
import { SpotlightThreadModal } from "@/Components/Spotlight/SpotlightThreadModal";
|
||||||
import ShortNote from "@/Components/Trending/ShortNote";
|
import ShortNote from "@/Components/Trending/ShortNote";
|
||||||
@ -14,7 +15,6 @@ import NostrBandApi from "@/External/NostrBand";
|
|||||||
import useCachedFetch from "@/Hooks/useCachedFetch";
|
import useCachedFetch from "@/Hooks/useCachedFetch";
|
||||||
import useLogin from "@/Hooks/useLogin";
|
import useLogin from "@/Hooks/useLogin";
|
||||||
import useModeration from "@/Hooks/useModeration";
|
import useModeration from "@/Hooks/useModeration";
|
||||||
import { useLocale } from "@/IntlProvider";
|
|
||||||
import { System } from "@/system";
|
import { System } from "@/system";
|
||||||
|
|
||||||
export default function TrendingNotes({ count = Infinity, small = false }: { count: number; small: boolean }) {
|
export default function TrendingNotes({ count = Infinity, small = false }: { count: number; small: boolean }) {
|
||||||
|
@ -3,7 +3,7 @@ import "./index.css";
|
|||||||
import { Outlet, RouteObject } from "react-router-dom";
|
import { Outlet, RouteObject } from "react-router-dom";
|
||||||
|
|
||||||
import Icon from "@/Components/Icons/Icon";
|
import Icon from "@/Components/Icons/Icon";
|
||||||
import { useLocale } from "@/IntlProvider";
|
import { useLocale } from "@/Components/IntlProvider/IntlProviderUtils";
|
||||||
import { AllLanguageCodes } from "@/Pages/settings/Preferences";
|
import { AllLanguageCodes } from "@/Pages/settings/Preferences";
|
||||||
|
|
||||||
import { Discover } from "./discover";
|
import { Discover } from "./discover";
|
||||||
|
@ -2,8 +2,8 @@ import "./Preferences.css";
|
|||||||
|
|
||||||
import { FormattedMessage, useIntl } from "react-intl";
|
import { FormattedMessage, useIntl } from "react-intl";
|
||||||
|
|
||||||
|
import { useLocale } from "@/Components/IntlProvider/IntlProviderUtils";
|
||||||
import useLogin from "@/Hooks/useLogin";
|
import useLogin from "@/Hooks/useLogin";
|
||||||
import { useLocale } from "@/IntlProvider";
|
|
||||||
import { unwrap } from "@/Utils";
|
import { unwrap } from "@/Utils";
|
||||||
import { DefaultImgProxy } from "@/Utils/Const";
|
import { DefaultImgProxy } from "@/Utils/Const";
|
||||||
import { updatePreferences, UserPreferences } from "@/Utils/Login";
|
import { updatePreferences, UserPreferences } from "@/Utils/Login";
|
||||||
|
@ -11,9 +11,9 @@ import { createBrowserRouter, RouteObject, RouterProvider } from "react-router-d
|
|||||||
|
|
||||||
import { preload } from "@/Cache";
|
import { preload } from "@/Cache";
|
||||||
import { ThreadRoute } from "@/Components/Event/Thread";
|
import { ThreadRoute } from "@/Components/Event/Thread";
|
||||||
|
import { IntlProvider } from "@/Components/IntlProvider/IntlProvider";
|
||||||
import { db } from "@/Db";
|
import { db } from "@/Db";
|
||||||
import { updateRelayConnections } from "@/Hooks/useLoginRelays";
|
import { updateRelayConnections } from "@/Hooks/useLoginRelays";
|
||||||
import { IntlProvider } from "@/IntlProvider";
|
|
||||||
import { AboutPage } from "@/Pages/About";
|
import { AboutPage } from "@/Pages/About";
|
||||||
import { SnortDeckLayout } from "@/Pages/DeckLayout";
|
import { SnortDeckLayout } from "@/Pages/DeckLayout";
|
||||||
import DonatePage from "@/Pages/DonatePage";
|
import DonatePage from "@/Pages/DonatePage";
|
||||||
|
Reference in New Issue
Block a user