From 89036f8aecde528da8348cb99f932a83ab001318 Mon Sep 17 00:00:00 2001
From: archer <545436317@qq.com>
Date: Mon, 7 Aug 2023 13:26:53 +0800
Subject: [PATCH] perf: git star
---
client/src/components/Layout/index.tsx | 8 +++++---
client/src/components/Layout/navbar.tsx | 25 ++++++++++++++---------
client/src/components/MyTooltip/index.tsx | 2 +-
client/src/pages/index.tsx | 15 ++------------
client/src/pages/tools/index.tsx | 2 +-
client/src/store/global.ts | 13 ++++++++++++
6 files changed, 37 insertions(+), 28 deletions(-)
diff --git a/client/src/components/Layout/index.tsx b/client/src/components/Layout/index.tsx
index 3f3c1e11d..b9c148b62 100644
--- a/client/src/components/Layout/index.tsx
+++ b/client/src/components/Layout/index.tsx
@@ -28,7 +28,7 @@ const Layout = ({ children }: { children: JSX.Element }) => {
const router = useRouter();
const { colorMode, setColorMode } = useColorMode();
const { Loading } = useLoading();
- const { loading, setScreenWidth, isPc } = useGlobalStore();
+ const { loading, setScreenWidth, isPc, loadGitStar } = useGlobalStore();
const { userInfo } = useUserStore();
const isChatPage = useMemo(
@@ -46,14 +46,16 @@ const Layout = ({ children }: { children: JSX.Element }) => {
const resize = throttle(() => {
setScreenWidth(document.documentElement.clientWidth);
}, 300);
- resize();
window.addEventListener('resize', resize);
+ resize();
+ loadGitStar();
+
return () => {
window.removeEventListener('resize', resize);
};
- }, []);
+ }, [loadGitStar, setScreenWidth]);
const { data: unread = 0 } = useQuery(['getUnreadCount'], getUnreadCount, {
enabled: !!userInfo,
diff --git a/client/src/components/Layout/navbar.tsx b/client/src/components/Layout/navbar.tsx
index 82675689e..4f561e9a9 100644
--- a/client/src/components/Layout/navbar.tsx
+++ b/client/src/components/Layout/navbar.tsx
@@ -11,6 +11,8 @@ import Avatar from '../Avatar';
import MyIcon from '../Icon';
import Language from '../Language';
import { useTranslation } from 'next-i18next';
+import { useGlobalStore } from '@/store/global';
+import MyTooltip from '../MyTooltip';
export enum NavbarTypeEnum {
normal = 'normal',
@@ -21,6 +23,7 @@ const Navbar = ({ unread }: { unread: number }) => {
const { t } = useTranslation();
const router = useRouter();
const { userInfo } = useUserStore();
+ const { gitStar } = useGlobalStore();
const { lastChatAppId, lastChatId } = useChatStore();
const navbarList = useMemo(
() => [
@@ -158,16 +161,18 @@ const Navbar = ({ unread }: { unread: number }) => {
)}
{feConfigs?.show_git && (
-
-
-
+
+
+
+
+
)}
);
diff --git a/client/src/components/MyTooltip/index.tsx b/client/src/components/MyTooltip/index.tsx
index 8dc85d07a..c05f79768 100644
--- a/client/src/components/MyTooltip/index.tsx
+++ b/client/src/components/MyTooltip/index.tsx
@@ -11,7 +11,7 @@ const MyTooltip = ({ children, forceShow = false, shouldWrapChildren = true, ...
return isPc || forceShow ? (
{
const router = useRouter();
const { t } = useTranslation();
const { inviterId } = router.query as { inviterId: string };
- const { isPc } = useGlobalStore();
- const [star, setStar] = useState(1500);
+ const { isPc, gitStar } = useGlobalStore();
useEffect(() => {
if (inviterId) {
@@ -136,15 +134,6 @@ const Home = () => {
}, 500);
}, [isPc]);
- useEffect(() => {
- (async () => {
- try {
- const { data: git } = await axios.get('https://api.github.com/repos/labring/FastGPT');
- setStar(git.stargazers_count);
- } catch (error) {}
- })();
- }, []);
-
return (
{
leftIcon={}
onClick={() => window.open('https://github.com/labring/FastGPT', '_blank')}
>
- Stars {(star / 1000).toFixed(1)}k
+ Stars {(gitStar / 1000).toFixed(1)}k
)}