2024-08-12 23:08:57 -05:00
|
|
|
import { LinkIncludingShortenedCollectionAndTags } from "@/types/global";
|
|
|
|
import { useQuery } from "@tanstack/react-query";
|
2024-08-14 15:44:07 -05:00
|
|
|
import { useSession } from "next-auth/react";
|
2024-08-12 23:08:57 -05:00
|
|
|
|
|
|
|
const useDashboardData = () => {
|
2024-08-14 15:44:07 -05:00
|
|
|
const { status } = useSession();
|
|
|
|
|
2024-08-12 23:08:57 -05:00
|
|
|
return useQuery({
|
|
|
|
queryKey: ["dashboardData"],
|
|
|
|
queryFn: async (): Promise<LinkIncludingShortenedCollectionAndTags[]> => {
|
|
|
|
const response = await fetch("/api/v1/dashboard");
|
|
|
|
const data = await response.json();
|
|
|
|
|
|
|
|
return data.response;
|
|
|
|
},
|
2024-08-14 15:44:07 -05:00
|
|
|
enabled: status === "authenticated",
|
2024-08-12 23:08:57 -05:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export { useDashboardData };
|