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-27 12:11:39 +03:00
|
|
|
|
import { ConceptLoader } from '../../components/Common/ConceptLoader';
|
|
|
|
|
import MiniButton from '../../components/Common/MiniButton';
|
2023-12-05 01:22:44 +03:00
|
|
|
|
import Overlay from '../../components/Common/Overlay';
|
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 (
|
2023-12-05 01:22:44 +03:00
|
|
|
|
<>
|
2023-11-27 11:33:34 +03:00
|
|
|
|
{loading ? <ConceptLoader /> : null}
|
|
|
|
|
{error ? <BackendError error={error} /> : null}
|
|
|
|
|
{user ?
|
|
|
|
|
<div className='flex justify-center gap-2 py-2'>
|
|
|
|
|
<div className='flex flex-col gap-2 min-w-max'>
|
2023-12-05 01:22:44 +03:00
|
|
|
|
<Overlay position='mt-2 top-0 right-0'>
|
|
|
|
|
<MiniButton
|
|
|
|
|
tooltip='Показать/Скрыть список отслеживаний'
|
|
|
|
|
icon={showSubs
|
|
|
|
|
? <SubscribedIcon color='text-primary' size={5}/>
|
|
|
|
|
: <NotSubscribedIcon color='text-primary' size={5}/>
|
|
|
|
|
}
|
|
|
|
|
onClick={() => setShowSubs(prev => !prev)}
|
|
|
|
|
/>
|
|
|
|
|
</Overlay>
|
2023-11-27 11:33:34 +03:00
|
|
|
|
<h1>Учетные данные пользователя</h1>
|
|
|
|
|
<div className='flex justify-center py-2 max-w-fit'>
|
|
|
|
|
<EditorProfile />
|
|
|
|
|
<EditorPassword />
|
|
|
|
|
</div>
|
2023-08-26 17:26:49 +03:00
|
|
|
|
</div>
|
2023-11-27 11:33:34 +03:00
|
|
|
|
{(subscriptions.length > 0 && showSubs) ?
|
|
|
|
|
<div className='flex flex-col w-full gap-6 pl-4'>
|
|
|
|
|
<h1>Отслеживаемые схемы</h1>
|
|
|
|
|
<ViewSubscriptions items={subscriptions} />
|
|
|
|
|
</div> : null}
|
|
|
|
|
</div> : null}
|
2023-12-05 01:22:44 +03:00
|
|
|
|
</>);
|
2023-07-31 23:47:18 +03:00
|
|
|
|
}
|
|
|
|
|
|
2023-12-05 01:22:44 +03:00
|
|
|
|
export default UserTabs;
|