12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- import { UserInfoResponse } from '@/types/userinfo';
- import { STORAGE_USERINFO_KEY } from '@/utils/constants/index';
- import { Avatar } from 'antd';
- import cls from 'classnames';
- import Link from 'next/link';
- import Image from 'next/image';
- import { useRouter } from 'next/router';
- import { useEffect, useState } from 'react';
- function UserBar({ onlyAvatar = false }) {
- const [userInfo, setUserInfo] = useState<UserInfoResponse>();
- useEffect(() => {
- try {
- const user = JSON.parse(localStorage.getItem(STORAGE_USERINFO_KEY) ?? '');
- setUserInfo(user);
- } catch {
- return undefined;
- }
- }, []);
- const { pathname } = useRouter()
- return (
- <div className='flex flex-1 items-center justify-center '>
- <Link
- href='/chat'
- className={cls(
- 'flex items-center w-full h-12 px-4 cursor-pointer hover:bg-[#F1F5F9] dark:hover:bg-theme-dark hover:rounded-xl',
- {
- 'bg-white rounded-xl dark:bg-black': pathname.startsWith('/chat'),
- },
- )}
- key='/chat'
- >
- <div className='mr-3'>
- <Image
- key='image_chat'
- src={pathname === '/chat' ? '/pictures/chat_active.png' : '/pictures/chat.png'}
- alt='chat_image'
- width={40}
- height={40}
- />
- </div>
- <span className='text-sm'>{'在线对话'}</span>
- </Link>
- </div>
- );
- }
- export default UserBar;
|