2023-12-13 14:32:57 +03:00
|
|
|
|
'use client';
|
|
|
|
|
|
2023-08-26 17:26:49 +03:00
|
|
|
|
import { useMemo, useState } from 'react';
|
2023-12-17 20:19:28 +03:00
|
|
|
|
import { FiBell, FiBellOff } from 'react-icons/fi';
|
2023-08-26 17:26:49 +03:00
|
|
|
|
|
2023-12-13 14:32:57 +03:00
|
|
|
|
import { ConceptLoader } from '@/components/Common/ConceptLoader';
|
|
|
|
|
import MiniButton from '@/components/Common/MiniButton';
|
|
|
|
|
import Overlay from '@/components/Common/Overlay';
|
|
|
|
|
import InfoError from '@/components/InfoError';
|
|
|
|
|
import { useAuth } from '@/context/AuthContext';
|
|
|
|
|
import { useLibrary } from '@/context/LibraryContext';
|
|
|
|
|
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}
|
2023-12-13 14:32:57 +03:00
|
|
|
|
{error ? <InfoError error={error} /> : null}
|
2023-11-27 11:33:34 +03:00
|
|
|
|
{user ?
|
2023-12-17 20:19:28 +03:00
|
|
|
|
<div className='flex gap-6 py-2'>
|
|
|
|
|
<div>
|
|
|
|
|
<Overlay position='top-0 right-0'>
|
2023-12-05 01:22:44 +03:00
|
|
|
|
<MiniButton
|
|
|
|
|
tooltip='Показать/Скрыть список отслеживаний'
|
|
|
|
|
icon={showSubs
|
2023-12-17 20:19:28 +03:00
|
|
|
|
? <FiBell size='1.25rem' className='clr-text-primary' />
|
|
|
|
|
: <FiBellOff size='1.25rem' className='clr-text-primary' />
|
2023-12-05 01:22:44 +03:00
|
|
|
|
}
|
|
|
|
|
onClick={() => setShowSubs(prev => !prev)}
|
|
|
|
|
/>
|
|
|
|
|
</Overlay>
|
2023-12-17 20:19:28 +03:00
|
|
|
|
<h1 className='mb-4'>Учетные данные пользователя</h1>
|
|
|
|
|
<div className='flex py-2 max-w-fit'>
|
2023-11-27 11:33:34 +03:00
|
|
|
|
<EditorProfile />
|
|
|
|
|
<EditorPassword />
|
|
|
|
|
</div>
|
2023-08-26 17:26:49 +03:00
|
|
|
|
</div>
|
2023-11-27 11:33:34 +03:00
|
|
|
|
{(subscriptions.length > 0 && showSubs) ?
|
2023-12-17 20:19:28 +03:00
|
|
|
|
<div>
|
|
|
|
|
<h1 className='mb-6'>Отслеживаемые схемы</h1>
|
2023-11-27 11:33:34 +03:00
|
|
|
|
<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;
|