Skip to content

Commit

Permalink
feat(web): add index page setting config (#1858)
Browse files Browse the repository at this point in the history
* feat(web): add index page setting config

* delete test data
  • Loading branch information
newfish-cmyk committed Feb 21, 2024
1 parent cc97241 commit f192ec8
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 14 deletions.
12 changes: 2 additions & 10 deletions web/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import { BrowserRouter, useRoutes } from "react-router-dom";
import { BrowserRouter } from "react-router-dom";
import { ChakraProvider } from "@chakra-ui/react";
import { css, Global } from "@emotion/react";
import { loader } from "@monaco-editor/react";
import { wrapUseRoutes } from "@sentry/react";
import * as Sentry from "@sentry/react";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { ClickToComponent } from "click-to-react-component";
Expand All @@ -17,7 +16,7 @@ import useSiteSettingStore from "./pages/siteSetting";
import theme from "./chakraTheme";
import darkTheme from "./chakraThemeDark";
import { CHAKRA_UI_COLOR_MODE_KEY } from "./constants";
import routes from "./routes";
import RouteElement from "./routes";

import "simplebar-react/dist/simplebar.min.css";
import "./App.css";
Expand All @@ -28,13 +27,6 @@ const GlobalStyles = css`
}
`;

const useSentryRoutes = wrapUseRoutes(useRoutes);

function RouteElement() {
const element = useSentryRoutes(routes as any);
return element;
}

// Create a client
const queryClient = new QueryClient({
defaultOptions: {
Expand Down
3 changes: 2 additions & 1 deletion web/src/pages/siteSetting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ type SITE_KEY =
| "laf_wechat_url"
| "laf_status_url"
| "laf_doc_url"
| "laf_about_us_url";
| "laf_about_us_url"
| "enable_web_promo_page";

type State = {
siteSettings: {
Expand Down
35 changes: 32 additions & 3 deletions web/src/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import AuthLayout from "@/layouts/Auth";
import BasicLayout from "@/layouts/Basic";
import FunctionLayout from "@/layouts/Function";
import TemplateLayout from "@/layouts/Template";
import useSiteSettingStore from "@/pages/siteSetting";
import { useRoutes } from "react-router-dom";
import { wrapUseRoutes } from "@sentry/react";

const route404 = {
path: "*",
Expand Down Expand Up @@ -46,7 +49,6 @@ const routes = [
},
{
path: "/bind",
// element: <AuthLayout />,
auth: false,
children: [
{
Expand Down Expand Up @@ -147,7 +149,27 @@ function LazyElement(props: any) {
}

function dealRoutes(routesArr: any) {
const { siteSettings } = useSiteSettingStore();
if (routesArr && Array.isArray(routesArr) && routesArr.length > 0) {
if (siteSettings.enable_web_promo_page?.value === "false") {
for (let i = 0; i < routesArr.length; i++) {
const route = routesArr[i];
if (route.index) {
routesArr[i] = {
path: "/",
element: <BasicLayout />,
auth: true,
children: [
{
path: "/",
element: () => import("@/pages/home/index"),
},
],
};
}
}
}

routesArr.forEach((route) => {
if (route.element && typeof route.element == "function") {
const importFunc = route.element;
Expand All @@ -159,6 +181,13 @@ function dealRoutes(routesArr: any) {
});
}
}
dealRoutes(routes);

export default routes;
function RouteElement() {
const useSentryRoutes = wrapUseRoutes(useRoutes);

dealRoutes(routes);
const element = useSentryRoutes(routes as any);
return element;
}

export default RouteElement;

0 comments on commit f192ec8

Please sign in to comment.