2023-08-26 17:26:49 +03:00
|
|
|
|
import { useMemo, useState } from 'react';
|
|
|
|
|
|
2023-07-31 23:47:18 +03:00
|
|
|
|
import BackendError from '../../components/BackendError';
|
2023-11-26 02:24:16 +03:00
|
|
|
|
import { ConceptLoader } from '../../components/common/ConceptLoader';
|
|
|
|
|
import MiniButton from '../../components/common/MiniButton';
|
2023-10-23 18:22:55 +03:00
|
|
|
|
import { NotSubscribedIcon,SubscribedIcon } from '../../components/Icons';
|
2023-08-26 17:26:49 +03:00
|
|
|
|
import { useAuth } from '../../context/AuthContext';
|
|
|
|
|
import { useLibrary } from '../../context/LibraryContext';
|
2023-07-31 23:47:18 +03:00
|
|
|
|
import { useUserProfile } from '../../context/UserProfileContext';
|
2023-08-26 17:26:49 +03:00
|
|
|
|
import EditorPassword from './EditorPassword';
|
|
|
|
|
import EditorProfile from './EditorProfile';
|
|
|
|
|
import ViewSubscriptions from './ViewSubscriptions';
|
2023-07-31 23:47:18 +03:00
|
|
|
|
|
|
|
|
|
function UserTabs() {
|
|
|
|
|
const { user, error, loading } = useUserProfile();
|
2023-08-26 17:26:49 +03:00
|
|
|
|
const { user: auth } = useAuth();
|
|
|
|
|
const { items } = useLibrary();
|
|
|
|
|
|
2023-08-27 00:19:19 +03:00
|
|
|
|
const [showSubs, setShowSubs] = useState(false);
|
2023-08-26 17:26:49 +03:00
|
|
|
|
|
|
|
|
|
const subscriptions = useMemo(
|
|
|
|
|
() => {
|
|
|
|
|
return items.filter(item => auth?.subscriptions.includes(item.id));
|
|
|
|
|
}, [auth, items]);
|
2023-07-31 23:47:18 +03:00
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className='w-full'>
|
2023-09-03 18:26:50 +03:00
|
|
|
|
{ loading && <ConceptLoader /> }
|
2023-07-31 23:47:18 +03:00
|
|
|
|
{ error && <BackendError error={error} />}
|
2023-08-26 17:26:49 +03:00
|
|
|
|
{ user &&
|
|
|
|
|
<div className='flex justify-center gap-2 py-2'>
|
|
|
|
|
<div className='flex flex-col gap-2 min-w-max'>
|
|
|
|
|
<div className='relative w-full'>
|
|
|
|
|
<div className='absolute top-0 right-0 mt-2'>
|
|
|
|
|
<MiniButton
|
|
|
|
|
tooltip='Показать/Скрыть список отслеживаний'
|
|
|
|
|
icon={showSubs
|
2023-10-23 18:22:55 +03:00
|
|
|
|
? <SubscribedIcon color='text-primary' size={5}/>
|
|
|
|
|
: <NotSubscribedIcon color='text-primary' size={5}/>
|
2023-08-26 17:26:49 +03:00
|
|
|
|
}
|
|
|
|
|
onClick={() => setShowSubs(prev => !prev)}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<h1>Учетные данные пользователя</h1>
|
|
|
|
|
<div className='flex justify-center py-2 max-w-fit'>
|
|
|
|
|
<EditorProfile />
|
|
|
|
|
<EditorPassword />
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
{subscriptions.length > 0 && showSubs &&
|
2023-09-11 21:06:51 +03:00
|
|
|
|
<div className='flex flex-col w-full gap-6 pl-4'>
|
2023-08-26 17:26:49 +03:00
|
|
|
|
<h1>Отслеживаемые схемы</h1>
|
|
|
|
|
<ViewSubscriptions items={subscriptions} />
|
|
|
|
|
</div>}
|
|
|
|
|
</div>
|
|
|
|
|
}
|
2023-07-31 23:47:18 +03:00
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default UserTabs;
|