feat: favorite & watch lists
This commit is contained in:
1 parent
960a7a6242
commit
8858e47d38
51 files changed
+561
-290
No files matched your search
@@ -0,0 +1,36 @@
|
||||
import { usersShows } from '@/api';
|
||||
import useInfiniteList from './useInfiniteList';
|
||||
import { useSession } from './useSession';
|
||||
import { useFavorites, useWatchList } from './useLocalUsersLists';
|
||||
|
||||
export const KEY = ({ list, showType }: { showType: Show['type']; list: 'favorite' | 'watchlist' }) => [
|
||||
`users-${list}`,
|
||||
showType
|
||||
];
|
||||
|
||||
const useUsersShows = ({ showType, list = 'favorite' }: { showType: Show['type']; list: 'favorite' | 'watchlist' }) => {
|
||||
const session = useSession();
|
||||
|
||||
const { shows: favorite } = useFavorites();
|
||||
const { shows: watchlist } = useWatchList();
|
||||
|
||||
const query = useInfiniteList({
|
||||
queryKey: KEY({ list, showType }),
|
||||
queryFn: () => usersShows({ showType, list }),
|
||||
enabled: Boolean(session)
|
||||
});
|
||||
|
||||
return session
|
||||
? query
|
||||
: {
|
||||
fetchNextPage: undefined,
|
||||
isLoading: false,
|
||||
isFetched: true,
|
||||
shows: {
|
||||
favorite: favorite.filter((show) => show.type === showType),
|
||||
watchlist: watchlist.filter((show) => show.type === showType)
|
||||
}[list]
|
||||
};
|
||||
};
|
||||
|
||||
export default useUsersShows;
|
||||
Reference in new issue
Block a user