made like

This commit is contained in:
Alibek 2024-02-20 00:33:33 +06:00
parent d77846bbbb
commit 9cd7b2a67d

View File

@ -6,6 +6,7 @@ import like from "./icons/like.svg";
import { apiInstance } from "@/shared/config/apiConfig";
import { useRouter } from "next/navigation";
import { useSession } from "next-auth/react";
import { useEffect } from "react";
interface IReportLikeProps {
count: number;
@ -17,31 +18,40 @@ const ReportLike: React.FC<IReportLikeProps> = ({
report_id,
}: IReportLikeProps) => {
const session = useSession();
const router = useRouter();
const getFans = async () => {
const res = await apiInstance.get(
`/report/${report_id}/get_fans`
const Authorization = `Bearer ${session?.data?.access_token}`;
const config = {
headers: {
Authorization,
},
};
const checkLike = async () => {
const res = await apiInstance.get<{ detail: string }>(
`/report/${report_id}/like/check/`,
config
);
return res.data;
};
const likeReport = async () => {
const Authorization = `Bearer ${session?.data?.access_token}`;
const config = {
headers: {
Authorization,
},
};
// console.log(getFans());
const res = await apiInstance.post(
`/report/${report_id}/like/`,
{},
config
);
const isLiked = await checkLike();
if (isLiked.detail === "Like does not exist!") {
await apiInstance.post(
`/report/${report_id}/like/`,
{},
config
);
} else {
await apiInstance.post(
`/report/${report_id}/unlike/`,
{},
config
);
}
router.refresh();
};