2024-05-26 12:18:09 -07:00
|
|
|
"use client"
|
2024-05-16 10:47:34 -07:00
|
|
|
|
2024-05-26 12:18:09 -07:00
|
|
|
import { AnimatePresence, motion } from "framer-motion"
|
|
|
|
import Image from "next/image"
|
|
|
|
import { useEffect, useState } from "react"
|
|
|
|
import ProjectCardDropdown from "./dropdown"
|
|
|
|
import { Clock, Globe, Lock } from "lucide-react"
|
|
|
|
import { Sandbox } from "@/lib/types"
|
|
|
|
import { Card } from "@/components/ui/card"
|
|
|
|
import { useRouter } from "next/navigation"
|
2024-04-16 16:57:15 -04:00
|
|
|
|
|
|
|
export default function ProjectCard({
|
|
|
|
children,
|
2024-05-16 10:47:34 -07:00
|
|
|
sandbox,
|
|
|
|
onVisibilityChange,
|
|
|
|
onDelete,
|
2024-05-16 21:45:19 -07:00
|
|
|
deletingId,
|
2024-04-16 16:57:15 -04:00
|
|
|
}: {
|
2024-05-26 12:18:09 -07:00
|
|
|
children?: React.ReactNode
|
|
|
|
sandbox: Sandbox
|
|
|
|
onVisibilityChange: (sandbox: Sandbox) => void
|
|
|
|
onDelete: (sandbox: Sandbox) => void
|
|
|
|
deletingId: string
|
2024-04-16 16:57:15 -04:00
|
|
|
}) {
|
2024-05-26 12:18:09 -07:00
|
|
|
const [hovered, setHovered] = useState(false)
|
|
|
|
const [date, setDate] = useState<string>()
|
|
|
|
const router = useRouter()
|
2024-05-16 10:47:34 -07:00
|
|
|
|
2024-05-25 01:24:13 -07:00
|
|
|
useEffect(() => {
|
2024-05-26 12:18:09 -07:00
|
|
|
const createdAt = new Date(sandbox.createdAt)
|
|
|
|
const now = new Date()
|
2024-05-25 01:24:13 -07:00
|
|
|
const diffInMinutes = Math.floor(
|
|
|
|
(now.getTime() - createdAt.getTime()) / 60000
|
2024-05-26 12:18:09 -07:00
|
|
|
)
|
2024-05-25 01:24:13 -07:00
|
|
|
|
|
|
|
if (diffInMinutes < 1) {
|
2024-05-26 12:18:09 -07:00
|
|
|
setDate("Now")
|
2024-05-25 01:24:13 -07:00
|
|
|
} else if (diffInMinutes < 60) {
|
2024-05-26 12:18:09 -07:00
|
|
|
setDate(`${diffInMinutes}m ago`)
|
2024-05-25 01:24:13 -07:00
|
|
|
} else if (diffInMinutes < 1440) {
|
2024-05-26 12:18:09 -07:00
|
|
|
setDate(`${Math.floor(diffInMinutes / 60)}h ago`)
|
2024-05-25 01:24:13 -07:00
|
|
|
} else {
|
2024-05-26 12:18:09 -07:00
|
|
|
setDate(`${Math.floor(diffInMinutes / 1440)}d ago`)
|
2024-05-25 01:24:13 -07:00
|
|
|
}
|
2024-05-26 12:18:09 -07:00
|
|
|
}, [sandbox])
|
2024-05-25 01:24:13 -07:00
|
|
|
|
2024-04-16 16:57:15 -04:00
|
|
|
return (
|
2024-05-16 10:47:34 -07:00
|
|
|
<Card
|
2024-05-16 21:45:19 -07:00
|
|
|
tabIndex={0}
|
|
|
|
onClick={() => router.push(`/code/${sandbox.id}`)}
|
2024-05-16 10:47:34 -07:00
|
|
|
onMouseEnter={() => setHovered(true)}
|
|
|
|
onMouseLeave={() => setHovered(false)}
|
2024-05-17 23:54:34 -07:00
|
|
|
className={`group/canvas-card p-4 h-48 flex flex-col justify-between items-start hover:border-muted-foreground/50 relative overflow-hidden transition-all`}
|
2024-04-16 16:57:15 -04:00
|
|
|
>
|
2024-05-26 12:18:09 -07:00
|
|
|
<AnimatePresence>
|
2024-05-16 10:47:34 -07:00
|
|
|
{hovered && (
|
|
|
|
<motion.div
|
|
|
|
initial={{ opacity: 0 }}
|
|
|
|
animate={{ opacity: 1 }}
|
|
|
|
className="h-full w-full absolute inset-0"
|
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</motion.div>
|
|
|
|
)}
|
2024-05-26 12:18:09 -07:00
|
|
|
</AnimatePresence>
|
2024-05-16 10:47:34 -07:00
|
|
|
|
|
|
|
<div className="space-x-2 flex items-center justify-start w-full z-10">
|
|
|
|
<Image
|
|
|
|
alt=""
|
|
|
|
src={
|
|
|
|
sandbox.type === "react"
|
|
|
|
? "/project-icons/react.svg"
|
|
|
|
: "/project-icons/node.svg"
|
|
|
|
}
|
|
|
|
width={20}
|
|
|
|
height={20}
|
|
|
|
/>
|
|
|
|
<div className="font-medium static whitespace-nowrap w-full text-ellipsis overflow-hidden">
|
|
|
|
{sandbox.name}
|
|
|
|
</div>
|
|
|
|
<ProjectCardDropdown
|
|
|
|
sandbox={sandbox}
|
|
|
|
onVisibilityChange={onVisibilityChange}
|
|
|
|
onDelete={onDelete}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div className="flex flex-col text-muted-foreground space-y-0.5 text-sm z-10">
|
|
|
|
<div className="flex items-center">
|
|
|
|
{sandbox.visibility === "private" ? (
|
|
|
|
<>
|
|
|
|
<Lock className="w-3 h-3 mr-2" /> Private
|
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
<Globe className="w-3 h-3 mr-2" /> Public
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
<div className="flex items-center">
|
2024-05-25 01:24:13 -07:00
|
|
|
<Clock className="w-3 h-3 mr-2" /> {date}
|
2024-05-16 10:47:34 -07:00
|
|
|
</div>
|
2024-04-16 16:57:15 -04:00
|
|
|
</div>
|
2024-05-16 10:47:34 -07:00
|
|
|
</Card>
|
2024-05-26 12:18:09 -07:00
|
|
|
)
|
2024-04-16 16:57:15 -04:00
|
|
|
}
|