feat: favorite & watch lists
This commit is contained in:
1 parent
960a7a6242
commit
8858e47d38
51 files changed
+561
-290
No files matched your search
@@ -2,5 +2,6 @@ export const paths = [
|
||||
{ path: '/', title: 'Random' },
|
||||
{ path: '/popular', title: 'Popular' },
|
||||
{ path: '/top', title: 'Top rated' },
|
||||
{ path: '/favorites', title: 'Favorites' }
|
||||
{ path: '/favorites', title: 'Favorites' },
|
||||
{ path: '/watch-list', title: 'Watch list' }
|
||||
];
|
||||
@@ -1,6 +1,6 @@
|
||||
'use client';
|
||||
|
||||
import { LogIn,LogOut, User as UserIcon, UserRound } from 'lucide-react';
|
||||
import { LogIn, LogOut, User as UserIcon, UserRound } from 'lucide-react';
|
||||
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
@@ -11,8 +11,8 @@ import {
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger
|
||||
} from '@/components/ui/dropdown-menu';
|
||||
import useAccount from '@/hooks/useAccount';
|
||||
|
||||
import useAccount from './useAccount';
|
||||
import useAuth from './useAuth';
|
||||
import useLogOut from './useLogOut';
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import { useQuery, useQueryClient } from '@tanstack/react-query';
|
||||
|
||||
import { account } from '@/api';
|
||||
import { useSession } from '@/hooks/useSession';
|
||||
|
||||
const KEY = ['account'];
|
||||
|
||||
const useAccount = () => {
|
||||
const queryClient = useQueryClient();
|
||||
const session = useSession();
|
||||
|
||||
const query = useQuery({
|
||||
enabled: Boolean(session),
|
||||
staleTime: Infinity,
|
||||
notifyOnChangeProps: ['data'],
|
||||
queryKey: KEY,
|
||||
queryFn: () => account()
|
||||
});
|
||||
|
||||
if (session === null) {
|
||||
queryClient.removeQueries({ queryKey: KEY });
|
||||
queryClient.resetQueries({ queryKey: KEY });
|
||||
}
|
||||
|
||||
return session ? query.data : undefined;
|
||||
};
|
||||
|
||||
export default useAccount;
|
||||
Reference in new issue
Block a user