UserBar.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { UserInfoResponse } from '@/types/userinfo';
  2. import { STORAGE_USERINFO_KEY } from '@/utils/constants/index';
  3. import { Avatar } from 'antd';
  4. import cls from 'classnames';
  5. import Link from 'next/link';
  6. import Image from 'next/image';
  7. import { useRouter } from 'next/router';
  8. import { useEffect, useState } from 'react';
  9. function UserBar({ onlyAvatar = false }) {
  10. const [userInfo, setUserInfo] = useState<UserInfoResponse>();
  11. useEffect(() => {
  12. try {
  13. const user = JSON.parse(localStorage.getItem(STORAGE_USERINFO_KEY) ?? '');
  14. setUserInfo(user);
  15. } catch {
  16. return undefined;
  17. }
  18. }, []);
  19. const { pathname } = useRouter()
  20. return (
  21. <div className='flex flex-1 items-center justify-center '>
  22. <Link
  23. href='/chat'
  24. className={cls(
  25. 'flex items-center w-full h-12 px-4 cursor-pointer dark:hover:bg-theme-dark hover:rounded-xl',
  26. {
  27. 'bg-[#7288FA] rounded-xl dark:bg-black text-[#fff]': pathname.startsWith('/chat'),
  28. 'hover:bg-[#d8d8d8]': !pathname.startsWith('/chat'),
  29. 'hover:text-[#3d8dfc]': !pathname.startsWith('/chat'),
  30. },
  31. )}
  32. key='/chat'
  33. >
  34. <div className='mr-3'>
  35. <Image
  36. key='image_chat'
  37. src={pathname === '/chat' ? '/pictures/chat_active.png' : '/pictures/chat.png'}
  38. alt='chat_image'
  39. width={40}
  40. height={40}
  41. />
  42. </div>
  43. <span className='text-sm'>{'在线对话'}</span>
  44. </Link>
  45. </div>
  46. );
  47. }
  48. export default UserBar;