Skip to content

Commit

Permalink
⚡️ perf: improve code of user panel (#5752)
Browse files Browse the repository at this point in the history
* improve code

* update repos
  • Loading branch information
arvinxx authored Feb 5, 2025
1 parent f899c82 commit 8903aed
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 14 deletions.
6 changes: 6 additions & 0 deletions next.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ const nextConfig: NextConfig = {
permanent: true,
source: '/welcome',
},
// we need back /repos url in the further
{
destination: '/files',
permanent: false,
source: '/repos',
},
],
// when external packages in dev mode with turbopack, this config will lead to bundle error
serverExternalPackages: isProd ? ['@electric-sql/pglite'] : undefined,
Expand Down
11 changes: 7 additions & 4 deletions src/app/(main)/_layout/Desktop/SideBar/Avatar.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ActionIcon } from '@lobehub/ui';
import { Tooltip } from 'antd';
import { LucideX } from 'lucide-react';
import { memo } from 'react';
import { Suspense, memo } from 'react';
import { useTranslation } from 'react-i18next';
import { Flexbox } from 'react-layout-kit';

Expand All @@ -14,10 +14,13 @@ const Avatar = memo(() => {
const { t } = useTranslation('common');
const hideSettingsMoveGuide = useUserStore(preferenceSelectors.hideSettingsMoveGuide);
const updateGuideState = useUserStore((s) => s.updateGuideState);

const content = (
<UserPanel>
<UserAvatar clickable />
</UserPanel>
<Suspense fallback={<UserAvatar />}>
<UserPanel>
<UserAvatar clickable />
</UserPanel>
</Suspense>
);

return hideSettingsMoveGuide ? (
Expand Down
5 changes: 0 additions & 5 deletions src/app/(main)/repos/page.tsx

This file was deleted.

5 changes: 3 additions & 2 deletions src/features/User/UserInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ const useStyles = createStyles(({ css, token }) => ({

export interface UserInfoProps extends FlexboxProps {
avatarProps?: Partial<UserAvatarProps>;
onClick?: () => void;
}

const UserInfo = memo<UserInfoProps>(({ avatarProps, ...rest }) => {
const UserInfo = memo<UserInfoProps>(({ avatarProps, onClick, ...rest }) => {
const { styles, theme } = useStyles();
const isSignedIn = useUserStore(authSelectors.isLogin);
const [nickname, username] = useUserStore((s) => [
Expand All @@ -44,7 +45,7 @@ const UserInfo = memo<UserInfoProps>(({ avatarProps, ...rest }) => {
paddingInline={12}
{...rest}
>
<Flexbox align={'center'} gap={12} horizontal>
<Flexbox align={'center'} gap={12} horizontal onClick={onClick}>
<UserAvatar background={theme.colorFill} size={48} {...avatarProps} />
<Flexbox flex={1} gap={6}>
<div className={styles.nickname}>{nickname}</div>
Expand Down
4 changes: 1 addition & 3 deletions src/features/User/UserPanel/PanelContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ const PanelContent = memo<{ closePopover: () => void }>(({ closePopover }) => {
<Flexbox gap={2} style={{ minWidth: 300 }}>
{!enableAuth || (enableAuth && isLoginWithAuth) ? (
<>
<Link href={'/profile'} style={{ color: 'inherit' }}>
<UserInfo />
</Link>
<UserInfo avatarProps={{ clickable: false }} />
{!isDeprecatedEdition && (
<Link href={'/profile/stats'} style={{ color: 'inherit' }}>
<DataStatistics />
Expand Down

0 comments on commit 8903aed

Please sign in to comment.