forked from Transparency/kgroad-frontend2
		
	made like
This commit is contained in:
		
							parent
							
								
									16bb5a4a1a
								
							
						
					
					
						commit
						7a9ba30e8f
					
				| @ -19,11 +19,12 @@ const ReportDetails = async ({ | |||||||
|   params: { id: string }; |   params: { id: string }; | ||||||
| }) => { | }) => { | ||||||
|   const getReportDetails = async () => { |   const getReportDetails = async () => { | ||||||
|     const res = await apiInstance.get<IReport>( |     const res = await fetch( | ||||||
|       `/report/${params.id}/` |       `${process.env.NEXT_PUBLIC_BASE_API}/report/${params.id}/`, | ||||||
|  |       { cache: "no-store" } | ||||||
|     ); |     ); | ||||||
| 
 | 
 | ||||||
|     return res.data; |     return res.json(); | ||||||
|   }; |   }; | ||||||
|   const report: IReport = await getReportDetails(); |   const report: IReport = await getReportDetails(); | ||||||
| 
 | 
 | ||||||
| @ -75,6 +76,7 @@ const ReportDetails = async ({ | |||||||
| 
 | 
 | ||||||
|     return images; |     return images; | ||||||
|   }; |   }; | ||||||
|  | 
 | ||||||
|   return ( |   return ( | ||||||
|     <div className="report-details page-padding"> |     <div className="report-details page-padding"> | ||||||
|       <div className="report-details__container"> |       <div className="report-details__container"> | ||||||
| @ -94,7 +96,10 @@ const ReportDetails = async ({ | |||||||
|                 , {report.created_at.slice(0, 4)} |                 , {report.created_at.slice(0, 4)} | ||||||
|               </p> |               </p> | ||||||
|             </div> |             </div> | ||||||
|             <ReportLike count={report.total_likes} /> |             <ReportLike | ||||||
|  |               count={report.total_likes} | ||||||
|  |               report_id={report.id} | ||||||
|  |             /> | ||||||
|           </div> |           </div> | ||||||
| 
 | 
 | ||||||
|           <p className="report-information__description"> |           <p className="report-information__description"> | ||||||
|  | |||||||
| @ -1,20 +1,53 @@ | |||||||
|  | "use client"; | ||||||
|  | 
 | ||||||
| import "./ReportLike.scss"; | import "./ReportLike.scss"; | ||||||
| import Image from "next/image"; | import Image from "next/image"; | ||||||
| import like from "./icons/like.svg"; | import like from "./icons/like.svg"; | ||||||
| import { apiInstance } from "@/shared/config/apiConfig"; | import { apiInstance } from "@/shared/config/apiConfig"; | ||||||
|  | import { useRouter } from "next/navigation"; | ||||||
|  | import { useSession } from "next-auth/react"; | ||||||
| 
 | 
 | ||||||
| interface IReportLikeProps { | interface IReportLikeProps { | ||||||
|   count: number; |   count: number; | ||||||
|  |   report_id: number; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| const ReportLike: React.FC<IReportLikeProps> = ({ | const ReportLike: React.FC<IReportLikeProps> = ({ | ||||||
|   count, |   count, | ||||||
|  |   report_id, | ||||||
| }: IReportLikeProps) => { | }: IReportLikeProps) => { | ||||||
|   const likeReport = async () => { |   const session = useSession(); | ||||||
|     const res = await apiInstance.post(""); |   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 ( |   return ( | ||||||
|     <button className="report-like"> |     <button onClick={likeReport} className="report-like"> | ||||||
|       <Image src={like} alt="Like Icon" /> |       <Image src={like} alt="Like Icon" /> | ||||||
|       <span>{count}</span> |       <span>{count}</span> | ||||||
|     </button> |     </button> | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user