refactor: adjust base components export

This commit is contained in:
GyDi 2022-11-20 22:03:55 +08:00
parent 892b919cf3
commit 8bb4803ff9
No known key found for this signature in database
GPG Key ID: 9C3AD40F1F99880A
34 changed files with 44 additions and 66 deletions

View File

@ -6,7 +6,7 @@ interface Props {
extra?: React.ReactNode; extra?: React.ReactNode;
} }
const BaseEmpty = (props: Props) => { export const BaseEmpty = (props: Props) => {
const { text = "Empty", extra } = props; const { text = "Empty", extra } = props;
return ( return (
@ -27,5 +27,3 @@ const BaseEmpty = (props: Props) => {
</Box> </Box>
); );
}; };
export default BaseEmpty;

View File

@ -9,12 +9,10 @@ function ErrorFallback({ error }: FallbackProps) {
); );
} }
const BaseErrorBoundary: React.FC = (props) => { export const BaseErrorBoundary: React.FC = (props) => {
return ( return (
<ErrorBoundary FallbackComponent={ErrorFallback}> <ErrorBoundary FallbackComponent={ErrorFallback}>
{props.children} {props.children}
</ErrorBoundary> </ErrorBoundary>
); );
}; };
export default BaseErrorBoundary;

View File

@ -37,7 +37,7 @@ const LoadingItem = styled("div")(({ theme }) => ({
background: theme.palette.text.secondary, background: theme.palette.text.secondary,
})); }));
const BaseLoading = () => { export const BaseLoading = () => {
return ( return (
<Loading> <Loading>
<LoadingItem /> <LoadingItem />
@ -46,5 +46,3 @@ const BaseLoading = () => {
</Loading> </Loading>
); );
}; };
export default BaseLoading;

View File

@ -69,7 +69,7 @@ interface NoticeInstance {
let parent: HTMLDivElement = null!; let parent: HTMLDivElement = null!;
// @ts-ignore // @ts-ignore
const Notice: NoticeInstance = (props) => { export const Notice: NoticeInstance = (props) => {
if (!parent) { if (!parent) {
parent = document.createElement("div"); parent = document.createElement("div");
document.body.appendChild(parent); document.body.appendChild(parent);
@ -91,5 +91,3 @@ const Notice: NoticeInstance = (props) => {
setTimeout(() => Notice({ type, message, duration }), 0); setTimeout(() => Notice({ type, message, duration }), 0);
}; };
}); });
export default Notice;

View File

@ -1,6 +1,6 @@
import React from "react"; import React from "react";
import { Typography } from "@mui/material"; import { Typography } from "@mui/material";
import BaseErrorBoundary from "./base-error-boundary"; import { BaseErrorBoundary } from "./base-error-boundary";
interface Props { interface Props {
title?: React.ReactNode; // the page title title?: React.ReactNode; // the page title
@ -8,7 +8,7 @@ interface Props {
contentStyle?: React.CSSProperties; contentStyle?: React.CSSProperties;
} }
const BasePage: React.FC<Props> = (props) => { export const BasePage: React.FC<Props> = (props) => {
const { title, header, contentStyle, children } = props; const { title, header, contentStyle, children } = props;
return ( return (
@ -31,5 +31,3 @@ const BasePage: React.FC<Props> = (props) => {
</BaseErrorBoundary> </BaseErrorBoundary>
); );
}; };
export default BasePage;

View File

@ -1,2 +1,6 @@
export { BaseDialog, type DialogRef } from "./base-dialog"; export { BaseDialog, type DialogRef } from "./base-dialog";
export { BasePage } from "./base-page";
export { BaseEmpty } from "./base-empty";
export { BaseLoading } from "./base-loading";
export { BaseErrorBoundary } from "./base-error-boundary";
export { Notice } from "./base-notice"; export { Notice } from "./base-notice";

View File

@ -15,7 +15,7 @@ import {
import { relaunch } from "@tauri-apps/api/process"; import { relaunch } from "@tauri-apps/api/process";
import { checkUpdate, installUpdate } from "@tauri-apps/api/updater"; import { checkUpdate, installUpdate } from "@tauri-apps/api/updater";
import { atomUpdateState } from "@/services/states"; import { atomUpdateState } from "@/services/states";
import Notice from "../base/base-notice"; import { Notice } from "@/components/base";
interface Props { interface Props {
open: boolean; open: boolean;

View File

@ -10,8 +10,8 @@ import {
patchProfilesConfig, patchProfilesConfig,
getRuntimeLogs, getRuntimeLogs,
} from "@/services/cmds"; } from "@/services/cmds";
import { Notice } from "@/components/base";
import ProfileMore from "./profile-more"; import ProfileMore from "./profile-more";
import Notice from "../base/base-notice";
interface Props { interface Props {
items: IProfileItem[]; items: IProfileItem[];

View File

@ -11,7 +11,7 @@ import {
} from "@mui/material"; } from "@mui/material";
import { atomThemeMode } from "@/services/states"; import { atomThemeMode } from "@/services/states";
import { readProfileFile, saveProfileFile } from "@/services/cmds"; import { readProfileFile, saveProfileFile } from "@/services/cmds";
import Notice from "../base/base-notice"; import { Notice } from "@/components/base";
import "monaco-editor/esm/vs/basic-languages/javascript/javascript.contribution.js"; import "monaco-editor/esm/vs/basic-languages/javascript/javascript.contribution.js";
import "monaco-editor/esm/vs/basic-languages/yaml/yaml.contribution.js"; import "monaco-editor/esm/vs/basic-languages/yaml/yaml.contribution.js";
@ -26,7 +26,7 @@ interface Props {
onChange?: () => void; onChange?: () => void;
} }
const FileEditor = (props: Props) => { export const FileEditor = (props: Props) => {
const { uid, open, mode, onClose, onChange } = props; const { uid, open, mode, onClose, onChange } = props;
const { t } = useTranslation(); const { t } = useTranslation();
@ -92,5 +92,3 @@ const FileEditor = (props: Props) => {
</Dialog> </Dialog>
); );
}; };
export default FileEditor;

View File

@ -17,7 +17,7 @@ import {
import { Settings } from "@mui/icons-material"; import { Settings } from "@mui/icons-material";
import { patchProfile } from "@/services/cmds"; import { patchProfile } from "@/services/cmds";
import { version } from "@root/package.json"; import { version } from "@root/package.json";
import Notice from "../base/base-notice"; import { Notice } from "@/components/base";
interface Props { interface Props {
open: boolean; open: boolean;

View File

@ -1,3 +1,4 @@
import { Fragment } from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { import {
Button, Button,
@ -9,8 +10,7 @@ import {
Divider, Divider,
Typography, Typography,
} from "@mui/material"; } from "@mui/material";
import BaseEmpty from "../base/base-empty"; import { BaseEmpty } from "@/components/base";
import { Fragment } from "react";
interface Props { interface Props {
open: boolean; open: boolean;

View File

@ -16,11 +16,11 @@ import {
import { RefreshRounded } from "@mui/icons-material"; import { RefreshRounded } from "@mui/icons-material";
import { atomLoadingCache } from "@/services/states"; import { atomLoadingCache } from "@/services/states";
import { updateProfile, deleteProfile, viewProfile } from "@/services/cmds"; import { updateProfile, deleteProfile, viewProfile } from "@/services/cmds";
import { Notice } from "@/components/base";
import parseTraffic from "@/utils/parse-traffic"; import parseTraffic from "@/utils/parse-traffic";
import ProfileBox from "./profile-box"; import ProfileBox from "./profile-box";
import InfoEditor from "./info-editor"; import InfoEditor from "./info-editor";
import FileEditor from "./file-editor"; import { FileEditor } from "./file-editor";
import Notice from "../base/base-notice";
const round = keyframes` const round = keyframes`
from { transform: rotate(0deg); } from { transform: rotate(0deg); }

View File

@ -13,11 +13,11 @@ import {
} from "@mui/material"; } from "@mui/material";
import { FeaturedPlayListRounded } from "@mui/icons-material"; import { FeaturedPlayListRounded } from "@mui/icons-material";
import { viewProfile } from "@/services/cmds"; import { viewProfile } from "@/services/cmds";
import { Notice } from "@/components/base";
import InfoEditor from "./info-editor"; import InfoEditor from "./info-editor";
import FileEditor from "./file-editor"; import { FileEditor } from "./file-editor";
import ProfileBox from "./profile-box"; import ProfileBox from "./profile-box";
import LogViewer from "./log-viewer"; import LogViewer from "./log-viewer";
import Notice from "../base/base-notice";
interface Props { interface Props {
selected: boolean; selected: boolean;

View File

@ -20,7 +20,7 @@ import {
} from "@mui/material"; } from "@mui/material";
import { Settings } from "@mui/icons-material"; import { Settings } from "@mui/icons-material";
import { createProfile } from "@/services/cmds"; import { createProfile } from "@/services/cmds";
import Notice from "../base/base-notice"; import { Notice } from "@/components/base";
import FileInput from "./file-input"; import FileInput from "./file-input";
interface Props { interface Props {

View File

@ -12,8 +12,8 @@ import {
SxProps, SxProps,
Theme, Theme,
} from "@mui/material"; } from "@mui/material";
import { BaseLoading } from "@/components/base";
import delayManager from "@/services/delay"; import delayManager from "@/services/delay";
import BaseLoading from "../base/base-loading";
interface Props { interface Props {
groupName: string; groupName: string;

View File

@ -16,7 +16,7 @@ export const useRenderList = (mode: string) => {
const { data: proxiesData, mutate: mutateProxies } = useSWR( const { data: proxiesData, mutate: mutateProxies } = useSWR(
"getProxies", "getProxies",
getProxies, getProxies,
{ refreshInterval: 45000, suspense: true } { refreshInterval: 45000 }
); );
const [headStates, setHeadState] = useHeadStateNew(); const [headStates, setHeadState] = useHeadStateNew();
@ -35,6 +35,7 @@ export const useRenderList = (mode: string) => {
}, [proxiesData, mode]); }, [proxiesData, mode]);
const renderList: IRenderItem[] = useMemo(() => { const renderList: IRenderItem[] = useMemo(() => {
if (!proxiesData) return [];
const useRule = mode === "rule" || mode === "script"; const useRule = mode === "rule" || mode === "script";
const renderGroups = const renderGroups =
(useRule ? proxiesData?.groups : [proxiesData?.global!]) || []; (useRule ? proxiesData?.groups : [proxiesData?.global!]) || [];

View File

@ -11,7 +11,7 @@ import {
} from "@/utils/clash-fields"; } from "@/utils/clash-fields";
import { BaseDialog, DialogRef } from "@/components/base"; import { BaseDialog, DialogRef } from "@/components/base";
import { useProfiles } from "@/hooks/use-profiles"; import { useProfiles } from "@/hooks/use-profiles";
import Notice from "@/components/base/base-notice"; import { Notice } from "@/components/base";
const fieldSorter = (a: string, b: string) => { const fieldSorter = (a: string, b: string) => {
if (a.includes("-") === a.includes("-")) { if (a.includes("-") === a.includes("-")) {

View File

@ -7,8 +7,7 @@ import { List, ListItem, ListItemText, TextField } from "@mui/material";
import { atomClashPort } from "@/services/states"; import { atomClashPort } from "@/services/states";
import { getClashConfig } from "@/services/api"; import { getClashConfig } from "@/services/api";
import { patchClashConfig } from "@/services/cmds"; import { patchClashConfig } from "@/services/cmds";
import { BaseDialog, DialogRef } from "@/components/base"; import { BaseDialog, DialogRef, Notice } from "@/components/base";
import Notice from "@/components/base/base-notice";
export const ClashPortViewer = forwardRef<DialogRef>((props, ref) => { export const ClashPortViewer = forwardRef<DialogRef>((props, ref) => {
const { t } = useTranslation(); const { t } = useTranslation();

View File

@ -5,8 +5,7 @@ import { useTranslation } from "react-i18next";
import { List, ListItem, ListItemText, TextField } from "@mui/material"; import { List, ListItem, ListItemText, TextField } from "@mui/material";
import { getClashInfo, patchClashConfig } from "@/services/cmds"; import { getClashInfo, patchClashConfig } from "@/services/cmds";
import { getAxios } from "@/services/api"; import { getAxios } from "@/services/api";
import { BaseDialog, DialogRef } from "@/components/base"; import { BaseDialog, DialogRef, Notice } from "@/components/base";
import Notice from "@/components/base/base-notice";
export const ControllerViewer = forwardRef<DialogRef>((props, ref) => { export const ControllerViewer = forwardRef<DialogRef>((props, ref) => {
const { t } = useTranslation(); const { t } = useTranslation();

View File

@ -5,7 +5,7 @@ import { Menu, MenuItem } from "@mui/material";
import { Settings } from "@mui/icons-material"; import { Settings } from "@mui/icons-material";
import { changeClashCore } from "@/services/cmds"; import { changeClashCore } from "@/services/cmds";
import { useVerge } from "@/hooks/use-verge"; import { useVerge } from "@/hooks/use-verge";
import Notice from "@/components/base/base-notice"; import { Notice } from "@/components/base";
const VALID_CORE = [ const VALID_CORE = [
{ name: "Clash", core: "clash" }, { name: "Clash", core: "clash" },

View File

@ -3,9 +3,8 @@ import { useTranslation } from "react-i18next";
import { useLockFn } from "ahooks"; import { useLockFn } from "ahooks";
import { styled, Typography } from "@mui/material"; import { styled, Typography } from "@mui/material";
import { useVerge } from "@/hooks/use-verge"; import { useVerge } from "@/hooks/use-verge";
import { BaseDialog, DialogRef } from "@/components/base"; import { BaseDialog, DialogRef, Notice } from "@/components/base";
import { HotkeyInput } from "./hotkey-input"; import { HotkeyInput } from "./hotkey-input";
import Notice from "@/components/base/base-notice";
const ItemWrapper = styled("div")` const ItemWrapper = styled("div")`
display: flex; display: flex;

View File

@ -3,8 +3,7 @@ import { useLockFn } from "ahooks";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { List, ListItem, ListItemText, Switch, TextField } from "@mui/material"; import { List, ListItem, ListItemText, Switch, TextField } from "@mui/material";
import { useVerge } from "@/hooks/use-verge"; import { useVerge } from "@/hooks/use-verge";
import { BaseDialog, DialogRef } from "@/components/base"; import { BaseDialog, DialogRef, Notice } from "@/components/base";
import Notice from "@/components/base/base-notice";
export const MiscViewer = forwardRef<DialogRef>((props, ref) => { export const MiscViewer = forwardRef<DialogRef>((props, ref) => {
const { t } = useTranslation(); const { t } = useTranslation();

View File

@ -9,8 +9,7 @@ import {
patchVergeConfig, patchVergeConfig,
} from "@/services/cmds"; } from "@/services/cmds";
import { forwardRef, useState } from "react"; import { forwardRef, useState } from "react";
import { BaseDialog, DialogRef } from "@/components/base"; import { BaseDialog, DialogRef, Notice } from "@/components/base";
import Notice from "@/components/base/base-notice";
interface Props { interface Props {
enable: boolean; enable: boolean;

View File

@ -14,8 +14,7 @@ import {
} from "@mui/material"; } from "@mui/material";
import { useVerge } from "@/hooks/use-verge"; import { useVerge } from "@/hooks/use-verge";
import { getSystemProxy } from "@/services/cmds"; import { getSystemProxy } from "@/services/cmds";
import { BaseDialog, DialogRef } from "@/components/base"; import { BaseDialog, DialogRef, Notice } from "@/components/base";
import Notice from "@/components/base/base-notice";
export const SysproxyViewer = forwardRef<DialogRef>((props, ref) => { export const SysproxyViewer = forwardRef<DialogRef>((props, ref) => {
const { t } = useTranslation(); const { t } = useTranslation();

View File

@ -11,8 +11,7 @@ import {
} from "@mui/material"; } from "@mui/material";
import { useVerge } from "@/hooks/use-verge"; import { useVerge } from "@/hooks/use-verge";
import { defaultTheme, defaultDarkTheme } from "@/pages/_theme"; import { defaultTheme, defaultDarkTheme } from "@/pages/_theme";
import { BaseDialog, DialogRef } from "@/components/base"; import { BaseDialog, DialogRef, Notice } from "@/components/base";
import Notice from "../../base/base-notice";
export const ThemeViewer = forwardRef<DialogRef>((props, ref) => { export const ThemeViewer = forwardRef<DialogRef>((props, ref) => {
const { t } = useTranslation(); const { t } = useTranslation();

View File

@ -5,10 +5,8 @@ import { useTranslation } from "react-i18next";
import { Button, Box, Typography } from "@mui/material"; import { Button, Box, Typography } from "@mui/material";
import { useVerge } from "@/hooks/use-verge"; import { useVerge } from "@/hooks/use-verge";
import { getClashInfo, openWebUrl } from "@/services/cmds"; import { getClashInfo, openWebUrl } from "@/services/cmds";
import { BaseDialog, BaseEmpty, DialogRef, Notice } from "@/components/base";
import { WebUIItem } from "./web-ui-item"; import { WebUIItem } from "./web-ui-item";
import { BaseDialog, DialogRef } from "@/components/base";
import BaseEmpty from "@/components/base/base-empty";
import Notice from "@/components/base/base-notice";
export const WebUIViewer = forwardRef<DialogRef>((props, ref) => { export const WebUIViewer = forwardRef<DialogRef>((props, ref) => {
const { t } = useTranslation(); const { t } = useTranslation();

View File

@ -15,13 +15,12 @@ import { atomCurrentProfile } from "@/services/states";
import { getProfiles } from "@/services/cmds"; import { getProfiles } from "@/services/cmds";
import { useVerge } from "@/hooks/use-verge"; import { useVerge } from "@/hooks/use-verge";
import { ReactComponent as LogoSvg } from "@/assets/image/logo.svg"; import { ReactComponent as LogoSvg } from "@/assets/image/logo.svg";
import Notice from "@/components/base/base-notice"; import { BaseErrorBoundary, Notice } from "@/components/base";
import LayoutItem from "@/components/layout/layout-item"; import LayoutItem from "@/components/layout/layout-item";
import LayoutControl from "@/components/layout/layout-control"; import LayoutControl from "@/components/layout/layout-control";
import LayoutTraffic from "@/components/layout/layout-traffic"; import LayoutTraffic from "@/components/layout/layout-traffic";
import UpdateButton from "@/components/layout/update-button"; import UpdateButton from "@/components/layout/update-button";
import useCustomTheme from "@/components/layout/use-custom-theme"; import useCustomTheme from "@/components/layout/use-custom-theme";
import BaseErrorBoundary from "@/components/base/base-error-boundary";
import getSystem from "@/utils/get-system"; import getSystem from "@/utils/get-system";
import "dayjs/locale/zh-cn"; import "dayjs/locale/zh-cn";

View File

@ -15,8 +15,7 @@ import { useTranslation } from "react-i18next";
import { TableChartRounded, TableRowsRounded } from "@mui/icons-material"; import { TableChartRounded, TableRowsRounded } from "@mui/icons-material";
import { closeAllConnections, getInformation } from "@/services/api"; import { closeAllConnections, getInformation } from "@/services/api";
import { atomConnectionSetting } from "@/services/states"; import { atomConnectionSetting } from "@/services/states";
import BasePage from "@/components/base/base-page"; import { BaseEmpty, BasePage } from "@/components/base";
import BaseEmpty from "@/components/base/base-empty";
import ConnectionItem from "@/components/connection/connection-item"; import ConnectionItem from "@/components/connection/connection-item";
import ConnectionTable from "@/components/connection/connection-table"; import ConnectionTable from "@/components/connection/connection-table";

View File

@ -16,8 +16,7 @@ import {
PauseCircleOutlineRounded, PauseCircleOutlineRounded,
} from "@mui/icons-material"; } from "@mui/icons-material";
import { atomEnableLog, atomLogData } from "@/services/states"; import { atomEnableLog, atomLogData } from "@/services/states";
import BasePage from "@/components/base/base-page"; import { BaseEmpty, BasePage } from "@/components/base";
import BaseEmpty from "@/components/base/base-empty";
import LogItem from "@/components/log/log-item"; import LogItem from "@/components/log/log-item";
const LogPage = () => { const LogPage = () => {

View File

@ -12,8 +12,7 @@ import {
} from "@/services/cmds"; } from "@/services/cmds";
import { getProxies, updateProxy } from "@/services/api"; import { getProxies, updateProxy } from "@/services/api";
import { atomCurrentProfile } from "@/services/states"; import { atomCurrentProfile } from "@/services/states";
import Notice from "@/components/base/base-notice"; import { BasePage, Notice } from "@/components/base";
import BasePage from "@/components/base/base-page";
import ProfileNew from "@/components/profile/profile-new"; import ProfileNew from "@/components/profile/profile-new";
import ProfileItem from "@/components/profile/profile-item"; import ProfileItem from "@/components/profile/profile-item";
import EnhancedMode from "@/components/profile/enhanced"; import EnhancedMode from "@/components/profile/enhanced";

View File

@ -5,7 +5,7 @@ import { Button, ButtonGroup, Paper } from "@mui/material";
import { getClashConfig, updateConfigs } from "@/services/api"; import { getClashConfig, updateConfigs } from "@/services/api";
import { patchClashConfig } from "@/services/cmds"; import { patchClashConfig } from "@/services/cmds";
import { ProxyGroups } from "@/components/proxy/proxy-groups"; import { ProxyGroups } from "@/components/proxy/proxy-groups";
import BasePage from "@/components/base/base-page"; import { BasePage } from "@/components/base";
const ProxyPage = () => { const ProxyPage = () => {
const { t } = useTranslation(); const { t } = useTranslation();

View File

@ -2,10 +2,9 @@ import useSWR from "swr";
import { useState, useMemo } from "react"; import { useState, useMemo } from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { Virtuoso } from "react-virtuoso"; import { Virtuoso } from "react-virtuoso";
import { Box, Button, MenuItem, Paper, Select, TextField } from "@mui/material"; import { Box, Paper, TextField } from "@mui/material";
import { getRules } from "@/services/api"; import { getRules } from "@/services/api";
import BasePage from "@/components/base/base-page"; import { BaseEmpty, BasePage } from "@/components/base";
import BaseEmpty from "@/components/base/base-empty";
import RuleItem from "@/components/rule/rule-item"; import RuleItem from "@/components/rule/rule-item";
const RulesPage = () => { const RulesPage = () => {

View File

@ -1,7 +1,6 @@
import { Paper } from "@mui/material"; import { Paper } from "@mui/material";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import Notice from "@/components/base/base-notice"; import { BasePage, Notice } from "@/components/base";
import BasePage from "@/components/base/base-page";
import SettingVerge from "@/components/setting/setting-verge"; import SettingVerge from "@/components/setting/setting-verge";
import SettingClash from "@/components/setting/setting-clash"; import SettingClash from "@/components/setting/setting-clash";
import SettingSystem from "@/components/setting/setting-system"; import SettingSystem from "@/components/setting/setting-system";

View File

@ -1,5 +1,5 @@
import { invoke } from "@tauri-apps/api/tauri"; import { invoke } from "@tauri-apps/api/tauri";
import Notice from "@/components/base/base-notice"; import { Notice } from "@/components/base";
export async function getClashLogs() { export async function getClashLogs() {
const regex = /time="(.+?)"\s+level=(.+?)\s+msg="(.+?)"/; const regex = /time="(.+?)"\s+level=(.+?)\s+msg="(.+?)"/;