2023-12-13 14:32:57 +03:00
|
|
|
|
'use client';
|
|
|
|
|
|
2023-12-25 16:53:27 +03:00
|
|
|
|
import { AnimatePresence } from 'framer-motion';
|
2023-08-26 17:26:49 +03:00
|
|
|
|
import { useMemo, useState } from 'react';
|
|
|
|
|
|
2024-04-03 21:05:53 +03:00
|
|
|
|
import { IconFollow, IconFollowOff } from '@/components/Icons';
|
2024-01-04 19:38:12 +03:00
|
|
|
|
import MiniButton from '@/components/ui/MiniButton';
|
|
|
|
|
import Overlay from '@/components/ui/Overlay';
|
2024-03-20 15:27:32 +03:00
|
|
|
|
import AnimateFade from '@/components/wrap/AnimateFade';
|
|
|
|
|
import DataLoader from '@/components/wrap/DataLoader';
|
2023-12-13 14:32:57 +03:00
|
|
|
|
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
|
|
|
|
|
2023-12-28 14:04:44 +03:00
|
|
|
|
const subscriptions = useMemo(() => {
|
2023-08-26 17:26:49 +03:00
|
|
|
|
return items.filter(item => auth?.subscriptions.includes(item.id));
|
|
|
|
|
}, [auth, items]);
|
2023-07-31 23:47:18 +03:00
|
|
|
|
|
|
|
|
|
return (
|
2024-01-07 03:29:16 +03:00
|
|
|
|
<DataLoader
|
2024-03-08 19:37:36 +03:00
|
|
|
|
id='profile-page' // prettier: split lines
|
2024-01-07 03:29:16 +03:00
|
|
|
|
isLoading={loading}
|
|
|
|
|
error={error}
|
|
|
|
|
hasNoData={!user}
|
|
|
|
|
>
|
|
|
|
|
<AnimateFade className='flex gap-6 py-2'>
|
|
|
|
|
<div>
|
|
|
|
|
<Overlay position='top-0 right-0'>
|
|
|
|
|
<MiniButton
|
2024-03-09 16:40:10 +03:00
|
|
|
|
title='Отслеживаемые схемы'
|
2024-01-07 03:29:16 +03:00
|
|
|
|
icon={
|
|
|
|
|
showSubs ? (
|
2024-04-03 21:05:53 +03:00
|
|
|
|
<IconFollow size='1.25rem' className='icon-primary' />
|
2024-01-07 03:29:16 +03:00
|
|
|
|
) : (
|
2024-04-03 21:05:53 +03:00
|
|
|
|
<IconFollowOff size='1.25rem' className='icon-primary' />
|
2024-01-07 03:29:16 +03:00
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
onClick={() => setShowSubs(prev => !prev)}
|
|
|
|
|
/>
|
|
|
|
|
</Overlay>
|
|
|
|
|
<h1 className='mb-4'>Учетные данные пользователя</h1>
|
|
|
|
|
<div className='flex py-2'>
|
|
|
|
|
<EditorProfile />
|
|
|
|
|
<EditorPassword />
|
2023-12-28 14:04:44 +03:00
|
|
|
|
</div>
|
2024-01-07 03:29:16 +03:00
|
|
|
|
</div>
|
|
|
|
|
<AnimatePresence>
|
|
|
|
|
{subscriptions.length > 0 && showSubs ? <ViewSubscriptions items={subscriptions} /> : null}
|
|
|
|
|
</AnimatePresence>
|
|
|
|
|
</AnimateFade>
|
|
|
|
|
</DataLoader>
|
2023-12-28 14:04:44 +03:00
|
|
|
|
);
|
2023-07-31 23:47:18 +03:00
|
|
|
|
}
|
|
|
|
|
|
2023-12-28 14:04:44 +03:00
|
|
|
|
export default UserTabs;
|