fix:medol update

This commit is contained in:
Rama Priyanto 2025-09-25 17:02:21 +07:00
parent bf249ccbfb
commit d79cbc026a
3 changed files with 30 additions and 46 deletions

View File

@ -43,7 +43,7 @@ export default function MedolUpdate() {
} }
if (selectedTab === "inp" && inpUpdate?.length < 1) { if (selectedTab === "inp" && inpUpdate?.length < 1) {
// getInpUpdate(); // getInpUpdate();
getTbnUpdate(); getInpUpdate();
} }
}, [selectedTab]); }, [selectedTab]);
@ -53,39 +53,21 @@ export default function MedolUpdate() {
} }
async function getTbnUpdate() { async function getTbnUpdate() {
const res = await topNewsTbn(); const res = await topNewsTbn("tribrata-news");
console.log("tbn data", res?.data?.data); console.log("res tbn", res?.data?.data?.latest);
const tempTbn: any = []; setTbnUpdate(res?.data?.data?.latest);
const tempINP: any = []; // setInpUpdate(tempINP);
for (const element of res?.data?.data) {
if (
element.website.name.includes("Tribratanews") ||
element.website.name.includes("Tribrata News")
) {
if (tempTbn.length <= 10) {
tempTbn.push(element);
}
}
if (element.website.name.includes("INP")) {
if (tempINP.length <= 10) {
tempINP.push(element);
}
}
}
setTbnUpdate(tempTbn);
setInpUpdate(tempINP);
} }
async function getInpUpdate() { async function getInpUpdate() {
const headers = { // const headers = {
"content-type": "application/json", // "content-type": "application/json",
}; // };
const resLog = await inpLogin(headers); // const resLog = await inpLogin(headers);
const res = await topNewsInp(resLog?.data?.access_token); // const res = await topNewsInp(resLog?.data?.access_token);
// setInpUpdate(res?.data); // setInpUpdate(res?.data);
const res = await topNewsTbn("indonesian-national-police");
setInpUpdate(res?.data?.data?.latest);
setInpUpdate(res?.data?.data);
// getDataImage(res?.data); // getDataImage(res?.data);
} }
@ -215,7 +197,7 @@ export default function MedolUpdate() {
wrapper: "!w-full !max-w-full", wrapper: "!w-full !max-w-full",
img: "!w-full", img: "!w-full",
}} // src={newsItem.thumbnailLink} }} // src={newsItem.thumbnailLink}
src={`https://mediahub.polri.go.id/api/media/view?id=${newsItem?.id}&operation=thumbnail&isSmall=true`} src={`https://mediahub.polri.go.id/api/v2/media/view?id=${newsItem?.id}&operation=thumbnail&isSmall=true`}
/> />
</CardBody> </CardBody>
<CardFooter className="flex flex-col items-start text-left"> <CardFooter className="flex flex-col items-start text-left">
@ -290,10 +272,13 @@ export default function MedolUpdate() {
> >
{tbnUpdate?.map((newsItem: any) => ( {tbnUpdate?.map((newsItem: any) => (
<SwiperSlide <SwiperSlide
key={newsItem.title} key={newsItem.id}
className="hover:shadow-xl hover:opacity-90" className="hover:shadow-xl hover:opacity-90"
> >
<Link href={newsItem?.source_url} target="_blank"> <Link
href={"https://tribratanews.polri.go.id"}
target="_blank"
>
<Card <Card
isPressable isPressable
shadow="sm" shadow="sm"
@ -307,13 +292,13 @@ export default function MedolUpdate() {
img: "!w-full", img: "!w-full",
}} }}
className="object-cover !h-[20vh] w-full" className="object-cover !h-[20vh] w-full"
src={newsItem?.image} src={newsItem?.thumbnail}
/> />
</CardBody> </CardBody>
<CardFooter className="flex flex-col items-start text-left"> <CardFooter className="flex flex-col items-start text-left">
{/* {convertDateFormatNoTime(newsItem?.date)} */} {/* {convertDateFormatNoTime(newsItem?.date)} */}
<p className="text-xs"> <p className="text-xs">
{formatDate(newsItem?.date)} {formatDate(newsItem?.publicationDate)}
</p> </p>
<b className="text-sm"> <b className="text-sm">
{textEllipsis(newsItem?.title, 120)} {textEllipsis(newsItem?.title, 120)}
@ -386,8 +371,10 @@ export default function MedolUpdate() {
className="hover:shadow-xl hover:opacity-90" className="hover:shadow-xl hover:opacity-90"
> >
<Link <Link
// href={`https://inp.polri.go.id/artikel/${newsItem?.slug}`} href={`https://inp.polri.go.id/artikel/${newsItem?.slug
href={newsItem.source_url} .split("-")
.slice(0, -1)
.join("-")}`}
target="_blank" target="_blank"
> >
<Card <Card
@ -399,7 +386,7 @@ export default function MedolUpdate() {
<Image <Image
alt="thumnail" alt="thumnail"
className="object-cover !h-[20vh]" className="object-cover !h-[20vh]"
src={newsItem?.image} src={newsItem?.thumbnail}
// src={newsItem?.thumbnail} // src={newsItem?.thumbnail}
/> />
</CardBody> </CardBody>
@ -407,7 +394,7 @@ export default function MedolUpdate() {
{/* {newsItem?.created_at} */} {/* {newsItem?.created_at} */}
<p className="text-xs"> <p className="text-xs">
{" "} {" "}
{formatDate(newsItem?.date)} {formatDate(newsItem?.publicationDate)}
</p> </p>
<b className="text-sm"> <b className="text-sm">
{textEllipsis(newsItem?.title, 120)} {textEllipsis(newsItem?.title, 120)}

View File

@ -3,7 +3,7 @@
"version": "0.0.1", "version": "0.0.1",
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "next dev -p 4000", "dev": "next dev -p 3000",
"build": "next build", "build": "next build",
"start": "next start -p 4000", "start": "next start -p 4000",
"lint": "next lint" "lint": "next lint"

View File

@ -1,7 +1,7 @@
import axios from "axios"; import axios from "axios";
const tbnInstance = axios.create({ const tbnInstance = axios.create({
baseURL: "https://portal.humas.polri.go.id/v1/api", baseURL: "https://api-portal.humas.polri.go.id/api/v1",
headers: { headers: {
"content-type": "application/json", "content-type": "application/json",
}, },
@ -87,14 +87,11 @@ export async function inpLogin(headers: any) {
} }
} }
export async function topNewsTbn() { export async function topNewsTbn(type: string) {
const headers = { const headers = {
"content-type": "application/json", "content-type": "application/json",
}; };
return await tbnGetNews( return await tbnGetNews(`homepage/article/${type}?limit=5`, headers);
`/public/articles?page=1&limit=50&order_by=terkini&source=tbnews`,
headers
);
} }
export async function loginInp() { export async function loginInp() {
const headers = { const headers = {