mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-27 00:17:31 +00:00
perf: git star
This commit is contained in:
@@ -28,7 +28,7 @@ const Layout = ({ children }: { children: JSX.Element }) => {
|
|||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { colorMode, setColorMode } = useColorMode();
|
const { colorMode, setColorMode } = useColorMode();
|
||||||
const { Loading } = useLoading();
|
const { Loading } = useLoading();
|
||||||
const { loading, setScreenWidth, isPc } = useGlobalStore();
|
const { loading, setScreenWidth, isPc, loadGitStar } = useGlobalStore();
|
||||||
const { userInfo } = useUserStore();
|
const { userInfo } = useUserStore();
|
||||||
|
|
||||||
const isChatPage = useMemo(
|
const isChatPage = useMemo(
|
||||||
@@ -46,14 +46,16 @@ const Layout = ({ children }: { children: JSX.Element }) => {
|
|||||||
const resize = throttle(() => {
|
const resize = throttle(() => {
|
||||||
setScreenWidth(document.documentElement.clientWidth);
|
setScreenWidth(document.documentElement.clientWidth);
|
||||||
}, 300);
|
}, 300);
|
||||||
resize();
|
|
||||||
|
|
||||||
window.addEventListener('resize', resize);
|
window.addEventListener('resize', resize);
|
||||||
|
|
||||||
|
resize();
|
||||||
|
loadGitStar();
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
window.removeEventListener('resize', resize);
|
window.removeEventListener('resize', resize);
|
||||||
};
|
};
|
||||||
}, []);
|
}, [loadGitStar, setScreenWidth]);
|
||||||
|
|
||||||
const { data: unread = 0 } = useQuery(['getUnreadCount'], getUnreadCount, {
|
const { data: unread = 0 } = useQuery(['getUnreadCount'], getUnreadCount, {
|
||||||
enabled: !!userInfo,
|
enabled: !!userInfo,
|
||||||
|
@@ -11,6 +11,8 @@ import Avatar from '../Avatar';
|
|||||||
import MyIcon from '../Icon';
|
import MyIcon from '../Icon';
|
||||||
import Language from '../Language';
|
import Language from '../Language';
|
||||||
import { useTranslation } from 'next-i18next';
|
import { useTranslation } from 'next-i18next';
|
||||||
|
import { useGlobalStore } from '@/store/global';
|
||||||
|
import MyTooltip from '../MyTooltip';
|
||||||
|
|
||||||
export enum NavbarTypeEnum {
|
export enum NavbarTypeEnum {
|
||||||
normal = 'normal',
|
normal = 'normal',
|
||||||
@@ -21,6 +23,7 @@ const Navbar = ({ unread }: { unread: number }) => {
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { userInfo } = useUserStore();
|
const { userInfo } = useUserStore();
|
||||||
|
const { gitStar } = useGlobalStore();
|
||||||
const { lastChatAppId, lastChatId } = useChatStore();
|
const { lastChatAppId, lastChatId } = useChatStore();
|
||||||
const navbarList = useMemo(
|
const navbarList = useMemo(
|
||||||
() => [
|
() => [
|
||||||
@@ -158,6 +161,7 @@ const Navbar = ({ unread }: { unread: number }) => {
|
|||||||
)}
|
)}
|
||||||
<Language {...itemStyles} />
|
<Language {...itemStyles} />
|
||||||
{feConfigs?.show_git && (
|
{feConfigs?.show_git && (
|
||||||
|
<MyTooltip label={`Git Star: ${gitStar}`} placement={'right-end'}>
|
||||||
<Link
|
<Link
|
||||||
as={NextLink}
|
as={NextLink}
|
||||||
href="https://github.com/labring/FastGPT"
|
href="https://github.com/labring/FastGPT"
|
||||||
@@ -168,6 +172,7 @@ const Navbar = ({ unread }: { unread: number }) => {
|
|||||||
>
|
>
|
||||||
<MyIcon name={'git'} width={'22px'} height={'22px'} />
|
<MyIcon name={'git'} width={'22px'} height={'22px'} />
|
||||||
</Link>
|
</Link>
|
||||||
|
</MyTooltip>
|
||||||
)}
|
)}
|
||||||
</Flex>
|
</Flex>
|
||||||
);
|
);
|
||||||
|
@@ -11,7 +11,7 @@ const MyTooltip = ({ children, forceShow = false, shouldWrapChildren = true, ...
|
|||||||
return isPc || forceShow ? (
|
return isPc || forceShow ? (
|
||||||
<Tooltip
|
<Tooltip
|
||||||
bg={'white'}
|
bg={'white'}
|
||||||
arrowShadowColor={' rgba(0,0,0,0.1)'}
|
arrowShadowColor={' rgba(0,0,0,0.05)'}
|
||||||
hasArrow
|
hasArrow
|
||||||
arrowSize={12}
|
arrowSize={12}
|
||||||
offset={[-15, 15]}
|
offset={[-15, 15]}
|
||||||
|
@@ -7,15 +7,13 @@ import { serviceSideProps } from '@/utils/i18n';
|
|||||||
import { useTranslation } from 'next-i18next';
|
import { useTranslation } from 'next-i18next';
|
||||||
|
|
||||||
import styles from './index.module.scss';
|
import styles from './index.module.scss';
|
||||||
import axios from 'axios';
|
|
||||||
import MyIcon from '@/components/Icon';
|
import MyIcon from '@/components/Icon';
|
||||||
|
|
||||||
const Home = () => {
|
const Home = () => {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { inviterId } = router.query as { inviterId: string };
|
const { inviterId } = router.query as { inviterId: string };
|
||||||
const { isPc } = useGlobalStore();
|
const { isPc, gitStar } = useGlobalStore();
|
||||||
const [star, setStar] = useState(1500);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (inviterId) {
|
if (inviterId) {
|
||||||
@@ -136,15 +134,6 @@ const Home = () => {
|
|||||||
}, 500);
|
}, 500);
|
||||||
}, [isPc]);
|
}, [isPc]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
(async () => {
|
|
||||||
try {
|
|
||||||
const { data: git } = await axios.get('https://api.github.com/repos/labring/FastGPT');
|
|
||||||
setStar(git.stargazers_count);
|
|
||||||
} catch (error) {}
|
|
||||||
})();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Flex
|
<Flex
|
||||||
className={styles.home}
|
className={styles.home}
|
||||||
@@ -200,7 +189,7 @@ const Home = () => {
|
|||||||
leftIcon={<MyIcon name={'git'} w={'20px'} />}
|
leftIcon={<MyIcon name={'git'} w={'20px'} />}
|
||||||
onClick={() => window.open('https://github.com/labring/FastGPT', '_blank')}
|
onClick={() => window.open('https://github.com/labring/FastGPT', '_blank')}
|
||||||
>
|
>
|
||||||
Stars {(star / 1000).toFixed(1)}k
|
Stars {(gitStar / 1000).toFixed(1)}k
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
<Button
|
<Button
|
||||||
|
@@ -25,7 +25,7 @@ const list = [
|
|||||||
? [
|
? [
|
||||||
{
|
{
|
||||||
icon: 'git',
|
icon: 'git',
|
||||||
label: 'Git项目地址',
|
label: 'GitHub 地址',
|
||||||
link: 'https://github.com/labring/FastGPT'
|
link: 'https://github.com/labring/FastGPT'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
import { create } from 'zustand';
|
import { create } from 'zustand';
|
||||||
import { devtools } from 'zustand/middleware';
|
import { devtools } from 'zustand/middleware';
|
||||||
import { immer } from 'zustand/middleware/immer';
|
import { immer } from 'zustand/middleware/immer';
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
type State = {
|
type State = {
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
@@ -9,6 +10,8 @@ type State = {
|
|||||||
setScreenWidth: (val: number) => void;
|
setScreenWidth: (val: number) => void;
|
||||||
isPc?: boolean;
|
isPc?: boolean;
|
||||||
initIsPc(val: boolean): void;
|
initIsPc(val: boolean): void;
|
||||||
|
gitStar: number;
|
||||||
|
loadGitStar: () => Promise<void>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useGlobalStore = create<State>()(
|
export const useGlobalStore = create<State>()(
|
||||||
@@ -35,6 +38,16 @@ export const useGlobalStore = create<State>()(
|
|||||||
set((state) => {
|
set((state) => {
|
||||||
state.isPc = val;
|
state.isPc = val;
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
gitStar: 2700,
|
||||||
|
async loadGitStar() {
|
||||||
|
try {
|
||||||
|
const { data: git } = await axios.get('https://api.github.com/repos/labring/FastGPT');
|
||||||
|
|
||||||
|
set((state) => {
|
||||||
|
state.gitStar = git.stargazers_count;
|
||||||
|
});
|
||||||
|
} catch (error) {}
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user