forked from Transparency/kgroad-frontend2
made like
This commit is contained in:
parent
d77846bbbb
commit
9cd7b2a67d
@ -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,17 +18,9 @@ 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`
|
||||
);
|
||||
|
||||
return res.data;
|
||||
};
|
||||
|
||||
const likeReport = async () => {
|
||||
const Authorization = `Bearer ${session?.data?.access_token}`;
|
||||
const config = {
|
||||
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/`,
|
||||
{},
|
||||
config
|
||||
);
|
||||
} else {
|
||||
await apiInstance.post(
|
||||
`/report/${report_id}/unlike/`,
|
||||
{},
|
||||
config
|
||||
);
|
||||
}
|
||||
|
||||
router.refresh();
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user