import React from 'react'; import {useRouter } from 'next/router'; function formatBytes(bytes, decimals = 1) { if (!+bytes) return '0 Bytes' const k = 1024 const dm = decimals < 0 ? 0 : decimals const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'] const i = Math.floor(Math.log(bytes) / Math.log(k)) return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}` } const Card = (props) => { const router = useRouter(); let name = props.item[`name`]; let time = new Date(props.item[`timestamp`]); return (
{ if(props?.page ==="dashboard" || props?.blur){ return; } let slug = name.toLowerCase().trim().replace(/[^\w\s-]/g, '').replace(/[\s_-]+/g, '-').replace(/^-+|-+$/g, ''); router.push(`/post-detail/${props.item?.eid}/${slug}/`) }} key={props.index} style={{marginBottom:"10px"}} className={`my-2 overflow-hidden w-full ${props?.page ==="dashboard"?"":"cursor-pointer"} py-2 bg-card rounded-md flex justify-center hover:bg-primary/10 border border-off-white/10 hover:border-primary/50 flex-col md:flex-row `}>
{props?.item?.name}
{props.item['c'] || props.categoryId} {time.getDate()||""}-{time.getMonth()+1||""}-{time.getFullYear()||""} {formatBytes(props.item['size'])} {props?.page ==="dashboard"? {router.push(`/upload?data=${JSON.stringify(props?.item)}`)}} className='font-medium cursor-pointer text-primary' >Edit:null}
); }; export default Card;