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,17 +18,9 @@ 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 res = await apiInstance.get(
`/report/${report_id}/get_fans`
);
return res.data;
};
const likeReport = async () => {
const Authorization = `Bearer ${session?.data?.access_token}`; const Authorization = `Bearer ${session?.data?.access_token}`;
const config = { const config = {
headers: { headers: {
@ -35,13 +28,30 @@ const ReportLike: React.FC<IReportLikeProps> = ({
}, },
}; };
// console.log(getFans()); const checkLike = async () => {
const res = await apiInstance.get<{ detail: string }>(
`/report/${report_id}/like/check/`,
config
);
const res = await apiInstance.post( return res.data;
};
const likeReport = async () => {
const isLiked = await checkLike();
if (isLiked.detail === "Like does not exist!") {
await apiInstance.post(
`/report/${report_id}/like/`, `/report/${report_id}/like/`,
{}, {},
config config
); );
} else {
await apiInstance.post(
`/report/${report_id}/unlike/`,
{},
config
);
}
router.refresh(); router.refresh();
}; };