UserBar.tsx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 hover:bg-[#F1F5F9] dark:hover:bg-theme-dark hover:rounded-xl',
  26. {
  27. 'bg-white rounded-xl dark:bg-black': pathname.startsWith('/chat'),
  28. },
  29. )}
  30. key='/chat'
  31. >
  32. <div className='mr-3'>
  33. <Image
  34. key='image_chat'
  35. src={pathname === '/chat' ? '/pictures/chat_active.png' : '/pictures/chat.png'}
  36. alt='chat_image'
  37. width={40}
  38. height={40}
  39. />
  40. </div>
  41. <span className='text-sm'>{'在线对话'}</span>
  42. </Link>
  43. </div>
  44. );
  45. }
  46. export default UserBar;