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