made like

This commit is contained in:
Alibek 2024-02-19 16:32:34 +06:00
parent 16bb5a4a1a
commit 7a9ba30e8f
2 changed files with 45 additions and 7 deletions

View File

@ -19,11 +19,12 @@ const ReportDetails = async ({
params: { id: string };
}) => {
const getReportDetails = async () => {
const res = await apiInstance.get<IReport>(
`/report/${params.id}/`
const res = await fetch(
`${process.env.NEXT_PUBLIC_BASE_API}/report/${params.id}/`,
{ cache: "no-store" }
);
return res.data;
return res.json();
};
const report: IReport = await getReportDetails();
@ -75,6 +76,7 @@ const ReportDetails = async ({
return images;
};
return (
<div className="report-details page-padding">
<div className="report-details__container">
@ -94,7 +96,10 @@ const ReportDetails = async ({
, {report.created_at.slice(0, 4)}
</p>
</div>
<ReportLike count={report.total_likes} />
<ReportLike
count={report.total_likes}
report_id={report.id}
/>
</div>
<p className="report-information__description">

View File

@ -1,20 +1,53 @@
"use client";
import "./ReportLike.scss";
import Image from "next/image";
import like from "./icons/like.svg";
import { apiInstance } from "@/shared/config/apiConfig";
import { useRouter } from "next/navigation";
import { useSession } from "next-auth/react";
interface IReportLikeProps {
count: number;
report_id: number;
}
const ReportLike: React.FC<IReportLikeProps> = ({
count,
report_id,
}: IReportLikeProps) => {
const likeReport = async () => {
const res = await apiInstance.post("");
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: {
Authorization,
},
};
// console.log(getFans());
const res = await apiInstance.post(
`/report/${report_id}/like/`,
{},
config
);
router.refresh();
};
return (
<button className="report-like">
<button onClick={likeReport} className="report-like">
<Image src={like} alt="Like Icon" />
<span>{count}</span>
</button>