"use client"; import { useState, useEffect } from "react"; import Image from "next/image"; import Link from "next/link"; import { Button } from "@/components/ui/button"; import { Card } from "@/components/ui/card"; import { Archive, Star, Trash2, Undo2, HeartOff } from "lucide-react"; import Swal from "sweetalert2"; import withReactContent from "sweetalert2-react-content"; import { getBookmarks, BookmarkItem } from "@/service/content"; import { Pagination, PaginationContent, PaginationItem, PaginationLink, PaginationNext, PaginationPrevious, } from "@/components/ui/pagination"; function formatTanggal(dateString: string) { if (!dateString) return ""; return ( new Date(dateString) .toLocaleString("id-ID", { day: "2-digit", month: "short", year: "numeric", hour: "2-digit", minute: "2-digit", hour12: false, timeZone: "Asia/Jakarta", }) .replace(/\./g, ":") + " WIB" ); } function getLink(item: BookmarkItem) { switch (item.article?.typeId) { case 1: return `/content/image/detail/${item.article?.id}`; case 2: return `/content/video/detail/${item.article?.id}`; case 3: return `/content/text/detail/${item.article?.id}`; case 4: return `/content/audio/detail/${item.article?.id}`; default: return "#"; } } type ForYouCardGridProps = { filterType: "My Collections" | "Archives" | "Favorites"; selectedCategory?: string; // ✅ tambahkan ini }; export default function ForYouCardGrid({ filterType }: ForYouCardGridProps) { const [bookmarks, setBookmarks] = useState([]); const [loading, setLoading] = useState(true); const [contentType, setContentType] = useState< "image" | "video" | "text" | "audio" >("image"); const [currentPage, setCurrentPage] = useState(1); const [totalPages, setTotalPages] = useState(1); const [totalData, setTotalData] = useState(0); const itemsPerPage = 6; const MySwal = withReactContent(Swal); useEffect(() => { fetchBookmarks(); }, [filterType, currentPage]); const fetchBookmarks = async () => { try { setLoading(true); const response = await getBookmarks( currentPage, itemsPerPage, filterType, ); if (!response?.error) { const data = response.data?.data || []; const meta = response.data?.meta; const totalCount = meta?.count ?? data.length ?? 0; const totalPageCount = Math.max( 1, Math.ceil(totalCount / itemsPerPage) ); setBookmarks(data); setTotalPages(totalPageCount); setTotalData(totalCount); if (currentPage > totalPageCount) setCurrentPage(1); } else { MySwal.fire("Error", "Gagal memuat bookmark.", "error"); } } catch (err) { console.error(err); MySwal.fire("Error", "Terjadi kesalahan saat memuat bookmark.", "error"); } finally { setLoading(false); } }; const handleAction = (action: string, title: string) => { MySwal.fire({ icon: "info", title: action, text: `${title} berhasil di${action.toLowerCase()}.`, timer: 1200, showConfirmButton: false, }); }; const renderButtons = (bookmark: BookmarkItem) => { const title = bookmark.article?.title || "Konten"; if (filterType === "Archives") { return (
); } if (filterType === "Favorites") { return (
); } return (
); }; const renderCard = (bookmark: BookmarkItem) => (
{/* Gambar / ikon */} {bookmark.article?.typeId === 3 ? ( // 📝 TEXT
) : bookmark.article?.typeId === 4 ? ( // 🎵 AUDIO
) : ( // 📸 / 🎬
{bookmark.article?.title
)} {/* Caption */}

Disimpan: {formatTanggal(bookmark.createdAt)}

{bookmark.article?.title}

{renderButtons(bookmark)}
); // Filter sesuai tab const filtered = bookmarks.filter((b) => { const t = b.article?.typeId; switch (contentType) { case "image": return t === 1; case "video": return t === 2; case "text": return t === 3; case "audio": return t === 4; default: return true; } }); return (
{/* Tabs */}
{["image", "video", "audio", "text"].map((type) => ( ))}
{/* Grid + Pagination */} {loading ? (
{[...Array(6)].map((_, i) => (
))}
) : filtered.length > 0 ? ( <>
{filtered.map((b) => renderCard(b))}
{totalPages > 1 && (
setCurrentPage((p) => Math.max(1, p - 1))} className={ currentPage === 1 ? "pointer-events-none opacity-50" : "cursor-pointer" } /> {Array.from({ length: totalPages }, (_, i) => i + 1).map( (n) => ( setCurrentPage(n)} isActive={currentPage === n} > {n} ) )} setCurrentPage((p) => Math.min(totalPages, p + 1)) } className={ currentPage === totalPages ? "pointer-events-none opacity-50" : "cursor-pointer" } />

Menampilkan halaman {currentPage} dari {totalPages} • Total{" "} {totalData} konten

)} ) : (

Tidak ada bookmark ditemukan.

)}
); } // "use client"; // import { useState, useEffect } from "react"; // import Image from "next/image"; // import Link from "next/link"; // import { Button } from "@/components/ui/button"; // import { Archive, Star, Trash2, Box, Undo2, HeartOff } from "lucide-react"; // import Swal from "sweetalert2"; // import withReactContent from "sweetalert2-react-content"; // import { getBookmarks } from "@/service/content"; // import { BookmarkItem } from "@/service/content"; // import { Swiper, SwiperSlide } from "swiper/react"; // import "swiper/css"; // import "swiper/css/navigation"; // import { Navigation } from "swiper/modules"; // function formatTanggal(dateString: string) { // if (!dateString) return ""; // return ( // new Date(dateString) // .toLocaleString("id-ID", { // day: "2-digit", // month: "short", // year: "numeric", // hour: "2-digit", // minute: "2-digit", // hour12: false, // timeZone: "Asia/Jakarta", // }) // .replace(/\./g, ":") + " WIB" // ); // } // function getLink(item: BookmarkItem) { // switch (item.article?.typeId) { // case 1: // return `/content/image/detail/${item.article?.id}`; // case 2: // return `/content/video/detail/${item.article?.id}`; // case 3: // return `/content/text/detail/${item.article?.id}`; // case 4: // return `/content/audio/detail/${item.article?.id}`; // default: // return "#"; // } // } // type ForYouCardGridProps = { // filterType: "My Collections" | "Archives" | "Favorites"; // selectedCategory?: string; // }; // export default function ForYouCardGrid({ filterType }: ForYouCardGridProps) { // const [bookmarks, setBookmarks] = useState([]); // const [loading, setLoading] = useState(true); // const [contentType, setContentType] = useState< // "image" | "video" | "text" | "audio" // >("image"); // const MySwal = withReactContent(Swal); // useEffect(() => { // fetchBookmarks(); // }, [filterType]); // const fetchBookmarks = async () => { // try { // setLoading(true); // const response = await getBookmarks(1, 50, filterType); // if (!response?.error) { // setBookmarks(response.data?.data || []); // } else { // MySwal.fire("Error", "Gagal memuat bookmark.", "error"); // } // } catch (err) { // console.error(err); // MySwal.fire("Error", "Terjadi kesalahan saat memuat bookmark.", "error"); // } finally { // setLoading(false); // } // }; // const filtered = bookmarks.filter((b) => { // const t = b.article?.typeId; // switch (contentType) { // case "image": // return t === 1; // case "video": // return t === 2; // case "text": // return t === 3; // case "audio": // return t === 4; // default: // return true; // } // }); // const handleAction = (action: string, title: string) => { // MySwal.fire({ // icon: "info", // title: action, // text: `${title} berhasil di${action.toLowerCase()}.`, // timer: 1200, // showConfirmButton: false, // }); // }; // const renderButtons = (bookmark: BookmarkItem) => { // const title = bookmark.article?.title || "Konten"; // if (filterType === "Archives") { // return ( //
// // //
// ); // } // if (filterType === "Favorites") { // return ( //
// // //
// ); // } // return ( //
// // //
// ); // }; // const renderCard = (bookmark: BookmarkItem) => ( //
// {/* Gambar / ikon */} // {bookmark.article?.typeId === 3 ? ( // // 📝 TEXT //
// // // //
// ) : bookmark.article?.typeId === 4 ? ( // // 🎵 AUDIO //
// // // //
// ) : ( // // 📸 / 🎬 //
// // {bookmark.article?.title // //
// )} // {/* Caption */} //
//

// Disimpan: {formatTanggal(bookmark.createdAt)} //

// //

// {bookmark.article?.title} //

// // {renderButtons(bookmark)} //
//
// ); // if (loading) // return ( //
Memuat konten...
// ); // // if (filtered.length === 0) // // return ( // //
// //
📂
// //

// // Tidak Ada Konten di {filterType} // //

// //
// // ); // return ( //
// {/* Tab Filter Konten */} //
//
//
// {["image", "video", "audio", "text"].map((type) => ( // // ))} //
//
//
// {/* 🔹 Jika tidak ada data */} // {filtered.length === 0 ? ( //
// Tidak ada konten di {filterType}. //
// ) : ( // /* 🔹 Swiper hanya muncul kalau ada data */ //
// // {filtered.map((bookmark) => ( // // {renderCard(bookmark)} // // ))} // //
// )} //
// ); // } // "use client"; // import { useEffect, useState } from "react"; // import PublicationKlFilter from "./publication-filter"; // import { Button } from "@/components/ui/button"; // import { mediaWishlist } from "@/service/landing/landing"; // const itemsPerPage = 9; // type PublicationCardGridProps = { // selectedCategory: string; // title?: string; // refresh?: boolean; // categoryFilter?: string[]; // formatFilter?: string[]; // isInstitute?: boolean; // instituteId?: string; // sortBy?: string; // }; // export default function ForYouCardGrid({ // selectedCategory, // title, // refresh, // isInstitute = false, // instituteId = "", // }: PublicationCardGridProps) { // const [currentPage, setCurrentPage] = useState(0); // const [contentImage, setContentImage] = useState([]); // const [totalPages, setTotalPages] = useState(1); // const [categoryFilter] = useState([]); // const [formatFilter] = useState([]); // const [sortBy] = useState(); // useEffect(() => { // getDataImage(); // }, [currentPage, selectedCategory, title, refresh]); // async function getDataImage() { // const filter = // categoryFilter?.length > 0 // ? categoryFilter?.sort().join(",") // : selectedCategory || ""; // const name = title ?? ""; // const format = formatFilter?.join(",") ?? ""; // const response = await mediaWishlist( // "1", // isInstitute ? instituteId : "", // name, // filter, // "12", // currentPage, // sortBy, // format // ); // setTotalPages(response?.data?.data?.totalPages || 1); // setContentImage(response?.data?.data?.content || []); // } // const goToPage = (page: number) => { // setCurrentPage(page); // }; // return ( //
// {/* Grid Card */} //
// {contentImage.length === 0 ? ( //
// Tidak ada konten ditemukan. //
// ) : ( // contentImage.map((item: any, idx: number) => ( // // )) // )} //
// {/* Pagination */} //
// {Array.from({ length: totalPages }, (_, i) => ( // // ))} //
//
// ); // }