import React from 'react' import { useRouter } from 'next/router' import { useTheme } from 'next-themes' 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 CardCompact = props => { const router = useRouter() const { theme, setTheme } = useTheme() let name = props.item[`n`] let time = new Date(props.item[`a`] * 1000) return (
{ let slug = name .toLowerCase() .trim() .replace(/[^\w\s-]/g, '') .replace(/[\s_-]+/g, '-') .replace(/^-+|-+$/g, '') router.push(`/post-detail/${props.item?.pk}/${slug}/`) }} key={props.index} style={{ marginBottom: '10px' }} className={`my-2 w-full overflow-visible ${ props?.page === 'dashboard' ? '' : 'cursor-pointer' } py-2 ${ theme === 'dark' ? 'bg-card' : 'bg-app-shady-white' } hover_effect flex flex-col justify-center rounded-md hover:border-primary/50 hover:dark:bg-app-dark-blue md:flex-row`}>
{name}
{props.item['c'] || props.categoryId} {time.getDate()}-{time.getMonth() + 1}-{time.getFullYear()} {formatBytes(props.item['s'])}
) } export default CardCompact