refactor: 优化eslint配置,提升代码质量 (#1341)
* feat: 统一并标准化eslint * lint: napcat.webui * lint: napcat.webui * lint: napcat.core * build: fix * lint: napcat.webui * refactor: 重构eslint * Update README.md
This commit is contained in:
1 parent
c9b1d3fafa
commit
2185a884b4
651 files changed
+37978
-37584
No files matched your search
@@ -1,88 +1,88 @@
|
||||
import { BreadcrumbItem, Breadcrumbs } from '@heroui/breadcrumbs'
|
||||
import { Button } from '@heroui/button'
|
||||
import { useLocalStorage } from '@uidotdev/usehooks'
|
||||
import clsx from 'clsx'
|
||||
import { AnimatePresence, motion } from 'motion/react'
|
||||
import { useEffect, useMemo, useRef } from 'react'
|
||||
import { ErrorBoundary } from 'react-error-boundary'
|
||||
import { MdMenu, MdMenuOpen } from 'react-icons/md'
|
||||
import { useLocation, useNavigate } from 'react-router-dom'
|
||||
import { BreadcrumbItem, Breadcrumbs } from '@heroui/breadcrumbs';
|
||||
import { Button } from '@heroui/button';
|
||||
import { useLocalStorage } from '@uidotdev/usehooks';
|
||||
import clsx from 'clsx';
|
||||
import { AnimatePresence, motion } from 'motion/react';
|
||||
import { useEffect, useMemo, useRef } from 'react';
|
||||
import { ErrorBoundary } from 'react-error-boundary';
|
||||
import { MdMenu, MdMenuOpen } from 'react-icons/md';
|
||||
import { useLocation, useNavigate } from 'react-router-dom';
|
||||
|
||||
import key from '@/const/key'
|
||||
import key from '@/const/key';
|
||||
|
||||
import errorFallbackRender from '@/components/error_fallback'
|
||||
import errorFallbackRender from '@/components/error_fallback';
|
||||
// import PageLoading from "@/components/Loading/PageLoading";
|
||||
import SideBar from '@/components/sidebar'
|
||||
import SideBar from '@/components/sidebar';
|
||||
|
||||
import useAuth from '@/hooks/auth'
|
||||
import useAuth from '@/hooks/auth';
|
||||
|
||||
import type { MenuItem } from '@/config/site'
|
||||
import { siteConfig } from '@/config/site'
|
||||
import QQManager from '@/controllers/qq_manager'
|
||||
import type { MenuItem } from '@/config/site';
|
||||
import { siteConfig } from '@/config/site';
|
||||
import QQManager from '@/controllers/qq_manager';
|
||||
|
||||
const menus: MenuItem[] = siteConfig.navItems
|
||||
const menus: MenuItem[] = siteConfig.navItems;
|
||||
|
||||
const findTitle = (menus: MenuItem[], pathname: string): string[] => {
|
||||
const paths: string[] = []
|
||||
const paths: string[] = [];
|
||||
|
||||
if (pathname) {
|
||||
for (const item of menus) {
|
||||
if (item.href === pathname) {
|
||||
paths.push(item.label)
|
||||
paths.push(item.label);
|
||||
} else if (item.items) {
|
||||
const title = findTitle(item.items, pathname)
|
||||
const title = findTitle(item.items, pathname);
|
||||
|
||||
if (title.length > 0) {
|
||||
paths.push(item.label)
|
||||
paths.push(...title)
|
||||
paths.push(item.label);
|
||||
paths.push(...title);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return paths
|
||||
}
|
||||
const Layout: React.FC<{ children: React.ReactNode }> = ({ children }) => {
|
||||
const location = useLocation()
|
||||
const contentRef = useRef<HTMLDivElement>(null)
|
||||
const [openSideBar, setOpenSideBar] = useLocalStorage(key.sideBarOpen, true)
|
||||
const [b64img] = useLocalStorage(key.backgroundImage, '')
|
||||
const navigate = useNavigate()
|
||||
const { isAuth } = useAuth()
|
||||
return paths;
|
||||
};
|
||||
const Layout: React.FC<{ children: React.ReactNode; }> = ({ children }) => {
|
||||
const location = useLocation();
|
||||
const contentRef = useRef<HTMLDivElement>(null);
|
||||
const [openSideBar, setOpenSideBar] = useLocalStorage(key.sideBarOpen, true);
|
||||
const [b64img] = useLocalStorage(key.backgroundImage, '');
|
||||
const navigate = useNavigate();
|
||||
const { isAuth } = useAuth();
|
||||
const checkIsQQLogin = async () => {
|
||||
try {
|
||||
const result = await QQManager.checkQQLoginStatus()
|
||||
const result = await QQManager.checkQQLoginStatus();
|
||||
if (!result.isLogin) {
|
||||
if (isAuth) {
|
||||
navigate('/qq_login', { replace: true })
|
||||
navigate('/qq_login', { replace: true });
|
||||
} else {
|
||||
navigate('/web_login', { replace: true })
|
||||
navigate('/web_login', { replace: true });
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
navigate('/web_login', { replace: true })
|
||||
} catch (_error) {
|
||||
navigate('/web_login', { replace: true });
|
||||
}
|
||||
}
|
||||
};
|
||||
useEffect(() => {
|
||||
contentRef?.current?.scrollTo?.({
|
||||
top: 0,
|
||||
behavior: 'smooth'
|
||||
})
|
||||
}, [location.pathname])
|
||||
behavior: 'smooth',
|
||||
});
|
||||
}, [location.pathname]);
|
||||
useEffect(() => {
|
||||
if (isAuth) {
|
||||
checkIsQQLogin()
|
||||
checkIsQQLogin();
|
||||
}
|
||||
}, [isAuth])
|
||||
}, [isAuth]);
|
||||
const title = useMemo(() => {
|
||||
return findTitle(menus, location.pathname)
|
||||
}, [location.pathname])
|
||||
return findTitle(menus, location.pathname);
|
||||
}, [location.pathname]);
|
||||
return (
|
||||
<div
|
||||
className="h-screen relative flex bg-primary-50 dark:bg-black items-stretch"
|
||||
className='h-screen relative flex bg-primary-50 dark:bg-black items-stretch'
|
||||
style={{
|
||||
backgroundImage: `url(${b64img})`,
|
||||
backgroundSize: 'cover'
|
||||
backgroundSize: 'cover',
|
||||
}}
|
||||
>
|
||||
<SideBar items={menus} open={openSideBar} />
|
||||
@@ -117,17 +117,17 @@ const Layout: React.FC<{ children: React.ReactNode }> = ({ children }) => {
|
||||
>
|
||||
<Button
|
||||
isIconOnly
|
||||
radius="full"
|
||||
variant="light"
|
||||
radius='full'
|
||||
variant='light'
|
||||
onPress={() => setOpenSideBar(!openSideBar)}
|
||||
>
|
||||
{openSideBar ? <MdMenuOpen size={24} /> : <MdMenu size={24} />}
|
||||
</Button>
|
||||
</motion.div>
|
||||
<Breadcrumbs isDisabled size="lg">
|
||||
<Breadcrumbs isDisabled size='lg'>
|
||||
{title?.map((item, index) => (
|
||||
<BreadcrumbItem key={index}>
|
||||
<AnimatePresence mode="wait">
|
||||
<AnimatePresence mode='wait'>
|
||||
<motion.div
|
||||
key={item}
|
||||
initial={{ opacity: 0, y: -10 }}
|
||||
@@ -147,7 +147,7 @@ const Layout: React.FC<{ children: React.ReactNode }> = ({ children }) => {
|
||||
</ErrorBoundary>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
export default Layout
|
||||
export default Layout;
|
||||
@@ -1,25 +1,25 @@
|
||||
import { Link } from '@heroui/link'
|
||||
import { Tooltip } from '@heroui/tooltip'
|
||||
import { Link } from '@heroui/link';
|
||||
import { Tooltip } from '@heroui/tooltip';
|
||||
|
||||
import { GithubIcon } from '@/components/icons'
|
||||
import { GithubIcon } from '@/components/icons';
|
||||
|
||||
export default function PureLayout({
|
||||
children
|
||||
export default function PureLayout ({
|
||||
children,
|
||||
}: {
|
||||
children: React.ReactNode
|
||||
}) {
|
||||
return (
|
||||
<div className="relative flex flex-col h-screen">
|
||||
<div className="absolute right-0 top-0 p-2">
|
||||
<Tooltip content="查看WebUI源码" placement="left" showArrow>
|
||||
<Link isExternal href="https://github.com/bietiaop/NextNapCatWebUI">
|
||||
<GithubIcon className="text-default-900 hover:text-default-600 w-10 h-10 hover:drop-shadow-lg transition-all" />
|
||||
<div className='relative flex flex-col h-screen'>
|
||||
<div className='absolute right-0 top-0 p-2'>
|
||||
<Tooltip content='查看WebUI源码' placement='left' showArrow>
|
||||
<Link isExternal href='https://github.com/bietiaop/NextNapCatWebUI'>
|
||||
<GithubIcon className='text-default-900 hover:text-default-600 w-10 h-10 hover:drop-shadow-lg transition-all' />
|
||||
</Link>
|
||||
</Tooltip>
|
||||
</div>
|
||||
<main className="flex-grow w-full flex flex-col justify-center items-center">
|
||||
<main className='flex-grow w-full flex flex-col justify-center items-center'>
|
||||
{children}
|
||||
</main>
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user