no log: Refactor app structure

pull/2060/head
LASER-Yi 2 years ago
parent 0b7a1a90a1
commit 75a7dc8cdf

@ -1,13 +1,13 @@
import { render } from "@testing-library/react";
import { render } from "@/tests";
import { StrictMode } from "react";
import { describe, it } from "vitest";
import { Main } from "../src/main";
import App from ".";
describe("App", () => {
it("should render without crash", () => {
render(
<StrictMode>
<Main />
<App />
</StrictMode>
);
});

@ -1,10 +1,20 @@
import { StrictMode } from "react";
import ReactDOM from "react-dom";
import { Main } from "./main";
import { useRoutes } from "react-router-dom";
import { AllProviders } from "./providers";
import { useRouteItems } from "./Router";
const RouteApp = () => {
const items = useRouteItems();
return useRoutes(items);
};
ReactDOM.render(
<StrictMode>
<Main />
<AllProviders>
<RouteApp />
</AllProviders>
</StrictMode>,
document.getElementById("root")
);

@ -3,19 +3,13 @@ import ThemeProvider from "@/App/theme";
import { ModalsProvider } from "@/modules/modals";
import "@fontsource/roboto/300.css";
import { NotificationsProvider } from "@mantine/notifications";
import { FunctionComponent } from "react";
import { QueryClientProvider } from "react-query";
import { ReactQueryDevtools } from "react-query/devtools";
import { useRoutes } from "react-router-dom";
import { Router, useRouteItems } from "./Router";
import { Router } from "./Router";
import { Environment } from "./utilities";
const RouteApp = () => {
const items = useRouteItems();
return useRoutes(items);
};
export const Main = () => {
export const AllProviders: FunctionComponent = ({ children }) => {
return (
<QueryClientProvider client={queryClient}>
<ThemeProvider>
@ -25,7 +19,7 @@ export const Main = () => {
{Environment.queryDev && (
<ReactQueryDevtools initialIsOpen={false} />
)}
<RouteApp></RouteApp>
{children}
</Router>
</NotificationsProvider>
</ModalsProvider>

@ -0,0 +1,13 @@
import { AllProviders } from "@/providers";
import { render, RenderOptions } from "@testing-library/react";
import { ReactElement } from "react";
const customRender = (
ui: ReactElement,
options?: Omit<RenderOptions, "wrapper">
) => render(ui, { wrapper: AllProviders, ...options });
// re-export everything
export * from "@testing-library/react";
// override render method
export { customRender as render };
Loading…
Cancel
Save