diff --git a/src/ErrorBoundary.tsx b/src/ErrorBoundary.tsx index 70253739..89cad721 100644 --- a/src/ErrorBoundary.tsx +++ b/src/ErrorBoundary.tsx @@ -1,10 +1,9 @@ import { TFunction } from "i18next"; -import { Component, ErrorInfo, ReactNode } from "react"; +import { Component, ErrorInfo, PropsWithChildren } from "react"; import { withTranslation } from "react-i18next"; interface Props { t: TFunction<[string, string], undefined>; - children: ReactNode; } interface State { @@ -13,7 +12,7 @@ interface State { errorInfo?: ErrorInfo; } -class ErrorBoundary extends Component { +class ErrorBoundary extends Component, State> { public state: State = { hasError: false, }; diff --git a/src/components/ButtonWithSpinner/ButtonWithSpinner.tsx b/src/components/ButtonWithSpinner/ButtonWithSpinner.tsx index 613f3bbb..37226d92 100644 --- a/src/components/ButtonWithSpinner/ButtonWithSpinner.tsx +++ b/src/components/ButtonWithSpinner/ButtonWithSpinner.tsx @@ -1,10 +1,10 @@ -import type { ButtonHTMLAttributes, FC } from "react"; +import type { ButtonHTMLAttributes, FC, ReactElement } from "react"; import ButtonSpinner from "./ButtonSpinner/ButtonSpinner"; type Props = { className?: string; loading?: boolean; - icon?: React.ReactElement; + icon?: ReactElement; } & ButtonHTMLAttributes; const ButtonWithSpinner: FC = ({ diff --git a/src/components/RequireAuth.tsx b/src/components/RequireAuth.tsx index 53fc2520..4d0ce894 100644 --- a/src/components/RequireAuth.tsx +++ b/src/components/RequireAuth.tsx @@ -1,13 +1,9 @@ -import { FC, useContext } from "react"; -import { Navigate, useLocation } from "react-router-dom"; import { AppContext } from "@/context/app-context"; - -type Props = { - children: JSX.Element; -}; +import { FC, PropsWithChildren, useContext } from "react"; +import { Navigate, useLocation } from "react-router-dom"; //see https://reactrouter.com/docs/en/v6/examples/auth -const RequireAuth: FC = ({ children }) => { +const RequireAuth: FC = ({ children }) => { let { isLoggedIn } = useContext(AppContext); let location = useLocation(); diff --git a/src/components/RequireSetup.tsx b/src/components/RequireSetup.tsx index ad6dc5d1..26863b78 100644 --- a/src/components/RequireSetup.tsx +++ b/src/components/RequireSetup.tsx @@ -1,13 +1,15 @@ -import { FC } from "react"; +import { FC, PropsWithChildren } from "react"; import { Navigate } from "react-router-dom"; type Props = { needsSetup: boolean; - children: JSX.Element; }; //see https://reactrouter.com/docs/en/v6/examples/auth -const RequireSetup: FC = ({ needsSetup, children }) => { +const RequireSetup: FC> = ({ + needsSetup, + children, +}) => { if (!needsSetup) { return ; } diff --git a/src/context/app-context.tsx b/src/context/app-context.tsx index 5262a2ea..c7b45fb2 100644 --- a/src/context/app-context.tsx +++ b/src/context/app-context.tsx @@ -1,8 +1,16 @@ -import type { FC } from "react"; import { - createContext, + ACCESS_TOKEN, + disableGutter, + parseJwt, + retrieveSettings, + saveSettings, + setWindowAlias, +} from "@/utils"; +import type { FC, PropsWithChildren } from "react"; +import { Dispatch, SetStateAction, + createContext, useCallback, useContext, useEffect, @@ -10,16 +18,8 @@ import { } from "react"; import { useTranslation } from "react-i18next"; import { useNavigate } from "react-router-dom"; -import { - ACCESS_TOKEN, - disableGutter, - parseJwt, - retrieveSettings, - saveSettings, - setWindowAlias, -} from "@/utils"; -import { SSEContext } from "./sse-context"; import { toast } from "react-toastify"; +import { SSEContext } from "./sse-context"; export interface AppContextType { isLoggedIn: boolean; @@ -56,11 +56,7 @@ export const appContextDefault: AppContextType = { export const AppContext = createContext(appContextDefault); -type Props = { - children?: React.ReactNode; -}; - -const AppContextProvider: FC = ({ children }) => { +const AppContextProvider: FC = ({ children }) => { const { i18n } = useTranslation(); const { evtSource, setEvtSource } = useContext(SSEContext); diff --git a/src/context/sse-context.tsx b/src/context/sse-context.tsx index fe329037..75a06762 100644 --- a/src/context/sse-context.tsx +++ b/src/context/sse-context.tsx @@ -1,5 +1,3 @@ -import type { FC } from "react"; -import { createContext, Dispatch, SetStateAction, useState } from "react"; import { AppStatus } from "@/models/app-status"; import { App } from "@/models/app.model"; import { BtcInfo } from "@/models/btc-info"; @@ -9,6 +7,8 @@ import { SystemInfo } from "@/models/system-info"; import { SystemStartupInfo } from "@/models/system-startup-info"; import { Transaction } from "@/models/transaction.model"; import { WalletBalance } from "@/models/wallet-balance"; +import type { FC, PropsWithChildren } from "react"; +import { Dispatch, SetStateAction, createContext, useState } from "react"; export interface SSEContextType { evtSource: EventSource | null; @@ -65,11 +65,7 @@ export const SSEContext = createContext(sseContextDefault); export const SSE_URL = "/api/sse/subscribe"; -type Props = { - children?: React.ReactNode; -}; - -const SSEContextProvider: FC = (props) => { +const SSEContextProvider: FC = (props) => { const [evtSource, setEvtSource] = useState(null); const [systemInfo, setSystemInfo] = useState({ alias: "", diff --git a/src/index.tsx b/src/index.tsx index e6574b42..7080eebe 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,16 +1,16 @@ -import React from "react"; +import { StrictMode } from "react"; import { createRoot } from "react-dom/client"; import { BrowserRouter } from "react-router-dom"; import { ToastContainer } from "react-toastify"; +import "react-tooltip/dist/react-tooltip.css"; import App from "./App"; -import "./i18n/config"; -import "./index.css"; import AppContextProvider from "./context/app-context"; import SSEContextProvider from "./context/sse-context"; -import "react-tooltip/dist/react-tooltip.css"; +import "./i18n/config"; +import "./index.css"; -import "i18next"; import ErrorBoundary from "@/ErrorBoundary"; +import "i18next"; declare module "i18next" { interface CustomTypeOptions { @@ -21,7 +21,7 @@ declare module "i18next" { const container = document.getElementById("root") as HTMLElement; const root = createRoot(container); root.render( - + @@ -33,5 +33,5 @@ root.render( - , + , ); diff --git a/src/layouts/Layout.tsx b/src/layouts/Layout.tsx index 8e5e5933..97eefbc6 100644 --- a/src/layouts/Layout.tsx +++ b/src/layouts/Layout.tsx @@ -1,14 +1,10 @@ import useSSE from "@/hooks/use-sse"; -import type { FC } from "react"; +import type { FC, PropsWithChildren } from "react"; import BottomNav from "./BottomNav"; import Header from "./Header"; import SideDrawer from "./SideDrawer"; -type Props = { - children?: React.ReactNode; -}; - -const Layout: FC = ({ children }) => { +const Layout: FC = ({ children }) => { // use SSE for all components after login useSSE(); return ( diff --git a/src/layouts/ModalBackground.tsx b/src/layouts/ModalBackground.tsx index 941b7be3..692ec7ee 100644 --- a/src/layouts/ModalBackground.tsx +++ b/src/layouts/ModalBackground.tsx @@ -1,10 +1,6 @@ -import type { FC } from "react"; +import type { FC, PropsWithChildren } from "react"; -type Props = { - children?: React.ReactNode; -}; - -const ModalBackground: FC = ({ children }) => ( +const ModalBackground: FC = ({ children }) => (
{children}
diff --git a/src/layouts/ModalDialog.tsx b/src/layouts/ModalDialog.tsx index 487e400a..8aa463e7 100644 --- a/src/layouts/ModalDialog.tsx +++ b/src/layouts/ModalDialog.tsx @@ -1,5 +1,5 @@ import { XMarkIcon } from "@heroicons/react/24/outline"; -import { FC, useCallback, useEffect } from "react"; +import { FC, PropsWithChildren, useCallback, useEffect } from "react"; import ModalBackground from "./ModalBackground"; export const disableScroll = { @@ -8,12 +8,15 @@ export const disableScroll = { }; type Props = { - children?: React.ReactNode; closeable?: boolean; close: () => void; }; -const ModalDialog: FC = ({ closeable = true, close, children }) => { +const ModalDialog: FC> = ({ + closeable = true, + close, + children, +}) => { const closeModal = useCallback(() => { close(); disableScroll.off(); diff --git a/src/layouts/SetupContainer.tsx b/src/layouts/SetupContainer.tsx index d3cc2915..a25534e2 100644 --- a/src/layouts/SetupContainer.tsx +++ b/src/layouts/SetupContainer.tsx @@ -1,13 +1,9 @@ -import { FC, useContext } from "react"; -import { MoonIcon } from "@heroicons/react/24/outline"; import I18nDropdown from "@/components/I18nDropdown"; import { AppContext } from "@/context/app-context"; +import { MoonIcon } from "@heroicons/react/24/outline"; +import { FC, PropsWithChildren, useContext } from "react"; -type Props = { - children?: React.ReactNode; -}; - -const SetupContainer: FC = ({ children }) => { +const SetupContainer: FC = ({ children }) => { const { toggleDarkMode } = useContext(AppContext); return (
diff --git a/src/pages/Settings/ActionBox.tsx b/src/pages/Settings/ActionBox.tsx index 6344c41c..10f4130f 100644 --- a/src/pages/Settings/ActionBox.tsx +++ b/src/pages/Settings/ActionBox.tsx @@ -1,18 +1,17 @@ -import type { FC, ReactElement, ReactNode } from "react"; +import type { FC, PropsWithChildren, ReactElement } from "react"; export type Props = { name: string | ReactElement; actionName: string; action: () => void; showChild: boolean; - children: ReactNode; }; /** * displays a box with a title and a button which triggers an action (e.g. reboot) * has a child component which is displayed if showChild is true */ -const ActionBox: FC = ({ +const ActionBox: FC> = ({ name, action, actionName, diff --git a/src/pages/Setup/SelectOption.tsx b/src/pages/Setup/SelectOption.tsx index d3f7570c..1adc935f 100644 --- a/src/pages/Setup/SelectOption.tsx +++ b/src/pages/Setup/SelectOption.tsx @@ -1,17 +1,16 @@ -import { FC } from "react"; +import { FC, PropsWithChildren } from "react"; type Props = { id: string; radioGroup: string; value: string; selected: string | null; - children?: React.ReactNode; // Can be LightningDialog or SetupPhase // TODO: Move both to something better than enums onSelectOption: (value: any) => void; }; -const SelectOption: FC = ({ +const SelectOption: FC> = ({ children, id, radioGroup, diff --git a/src/utils/test-utils.tsx b/src/utils/test-utils.tsx index 8bd4e0bb..9b75fe7c 100644 --- a/src/utils/test-utils.tsx +++ b/src/utils/test-utils.tsx @@ -1,4 +1,3 @@ -import { render, RenderOptions } from "@testing-library/react"; import { AppContext, appContextDefault, @@ -9,16 +8,22 @@ import { sseContextDefault, SSEContextType, } from "@/context/sse-context"; -import React, { FC, ReactElement } from "react"; +import i18n from "@/i18n/test_config"; +import { render, RenderOptions } from "@testing-library/react"; +import { FC, PropsWithChildren, ReactElement } from "react"; import { I18nextProvider } from "react-i18next"; import { BrowserRouter } from "react-router-dom"; -import i18n from "@/i18n/test_config"; -const AllTheProviders: FC<{ - children: React.ReactNode; +type Props = { sseProps: SSEContextType; appProps: AppContextType; -}> = ({ children, appProps, sseProps }) => { +}; + +const AllTheProviders: FC> = ({ + children, + appProps, + sseProps, +}) => { return (