From 6fbf316c5d1af65a9d741cc5a89798229f5df9c6 Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Tue, 2 Apr 2024 21:55:20 +0800 Subject: [PATCH] refactor: improve layout navbar --- src/client/components/ui/avatar.tsx | 50 +++++++---- src/client/pages/Layout/UserConfig.tsx | 30 ++++++- src/client/pages/LayoutV2.tsx | 112 +++++++++++++------------ 3 files changed, 121 insertions(+), 71 deletions(-) diff --git a/src/client/components/ui/avatar.tsx b/src/client/components/ui/avatar.tsx index f52fd44..623fa70 100644 --- a/src/client/components/ui/avatar.tsx +++ b/src/client/components/ui/avatar.tsx @@ -1,22 +1,36 @@ -import * as React from "react" -import * as AvatarPrimitive from "@radix-ui/react-avatar" +import * as React from 'react'; +import * as AvatarPrimitive from '@radix-ui/react-avatar'; -import { cn } from "@/utils/style" +import { cn } from '@/utils/style'; +import { VariantProps, cva } from 'class-variance-authority'; +const avatarVariants = cva( + 'relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full', + { + variants: { + size: { + default: 'h-10 w-10', + sm: 'h-8 w-8', + lg: 'h-12 w-12', + }, + }, + } +); + +interface AvatarProps + extends React.ComponentPropsWithoutRef, + VariantProps {} const Avatar = React.forwardRef< React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, ...props }, ref) => ( + AvatarProps +>(({ className, size, ...props }, ref) => ( -)) -Avatar.displayName = AvatarPrimitive.Root.displayName +)); +Avatar.displayName = AvatarPrimitive.Root.displayName; const AvatarImage = React.forwardRef< React.ElementRef, @@ -24,11 +38,11 @@ const AvatarImage = React.forwardRef< >(({ className, ...props }, ref) => ( -)) -AvatarImage.displayName = AvatarPrimitive.Image.displayName +)); +AvatarImage.displayName = AvatarPrimitive.Image.displayName; const AvatarFallback = React.forwardRef< React.ElementRef, @@ -37,12 +51,12 @@ const AvatarFallback = React.forwardRef< -)) -AvatarFallback.displayName = AvatarPrimitive.Fallback.displayName +)); +AvatarFallback.displayName = AvatarPrimitive.Fallback.displayName; -export { Avatar, AvatarImage, AvatarFallback } +export { Avatar, AvatarImage, AvatarFallback }; diff --git a/src/client/pages/Layout/UserConfig.tsx b/src/client/pages/Layout/UserConfig.tsx index 81c6b2b..f337460 100644 --- a/src/client/pages/Layout/UserConfig.tsx +++ b/src/client/pages/Layout/UserConfig.tsx @@ -12,6 +12,8 @@ import { DropdownMenuSubTrigger, DropdownMenuRadioGroup, DropdownMenuRadioItem, + DropdownMenuSeparator, + DropdownMenuLabel, } from '@/components/ui/dropdown-menu'; import { useEvent } from '@/hooks/useEvent'; import { useSettingsStore } from '@/store/settings'; @@ -19,6 +21,7 @@ import { useUserInfo } from '@/store/user'; import { languages } from '@/utils/constants'; import { useTranslation, setLanguage } from '@i18next-toolkit/react'; import { useNavigate } from '@tanstack/react-router'; +import { version } from '@tianji/shared'; import React from 'react'; import { LuMoreVertical } from 'react-icons/lu'; @@ -38,7 +41,7 @@ export const UserConfig: React.FC = React.memo((props) => { }); const avatar = ( - + {(userInfo?.username ?? '').substring(0, 2).toUpperCase()} @@ -134,6 +137,31 @@ export const UserConfig: React.FC = React.memo((props) => { + + + + + {t('Community')} + + + window.open('https://discord.gg/8Vv47wAEej')} + > + {t('Join Discord')} + + + window.open('https://twitter.com/moonrailgun')} + > + {t('Follow Twitter')} + + + + + + + v{version} + diff --git a/src/client/pages/LayoutV2.tsx b/src/client/pages/LayoutV2.tsx index 85ede91..ad1986b 100644 --- a/src/client/pages/LayoutV2.tsx +++ b/src/client/pages/LayoutV2.tsx @@ -20,7 +20,7 @@ import { WorkspaceSwitcher } from '@/components/WorkspaceSwitcher'; import { UserConfig } from './Layout/UserConfig'; import { Outlet } from '@tanstack/react-router'; import { trpc } from '@/api/trpc'; -import { useCurrentWorkspaceId, useUserStore } from '@/store/user'; +import { useUserStore } from '@/store/user'; const defaultLayout: [number, number, number] = [265, 440, 655]; @@ -48,6 +48,62 @@ export const LayoutV2: React.FC = React.memo((props) => { } ); + const navbar = ( + <> +
+ +
+ +