refactoring: server actions data fetching -> api routes

This commit is contained in:
ner committed 2024-10-26 21:33:39 +03:00
1 parent 1111712d2c
commit 5cbf93b3b8
38 files changed
+326 -308

No files matched your search

@@ -1,20 +1,9 @@
import { useQuery } from '@tanstack/react-query';
import { credits } from '@/api';
import creditsQuery, { CreditsQueryProps } from '@/api/queries/credits';
interface Props {
showId?: Show['id'];
showType?: Show['type'];
}
export const KEY = ({ showId, showType }: Props) => ['credits', showId, showType];
const useCredits = ({ showId, showType }: Props) => {
return useQuery({
queryKey: KEY({ showId, showType }),
queryFn: () => credits({ showId, showType }),
enabled: Boolean(showId)
});
const useCredits = ({ showId, showType }: CreditsQueryProps) => {
return useQuery(creditsQuery({ showId, showType }));
};
export default useCredits;
+2 -9
View File
@@ -1,19 +1,12 @@
import { useQuery } from '@tanstack/react-query';
import { details } from '@/api';
import detailsQuery from '@/api/queries/details';
interface Props {
showId?: Show['id'];
showType?: Show['type'];
}
export const KEY = ({ showId, showType = 'movie' }: Props) => ['details', showId, showType];
const useDetails = ({ showId, showType = 'movie' }: Props) =>
useQuery({
enabled: Boolean(showId && showType),
queryKey: KEY({ showId, showType }),
queryFn: () => details({ showId: showId!, showType })
});
const useDetails = ({ showId, showType = 'movie' }: Props) => useQuery(detailsQuery({ showId, showType }));
export default useDetails;