import { useState, useEffect } from "react"; import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card" import { Tag } from "primereact/tag"; import ZapDisplay from "@/components/zaps/ZapDisplay"; import { BookOpen } from "lucide-react" import Image from "next/image" import { useZapsSubscription } from "@/hooks/nostrQueries/zaps/useZapsSubscription"; import { getTotalFromZaps } from "@/utils/lightning"; import { useImageProxy } from "@/hooks/useImageProxy"; import { useRouter } from "next/navigation"; import { formatTimestampToHowLongAgo } from "@/utils/time"; import GenericButton from "@/components/buttons/GenericButton"; export function CourseTemplate({ course }) { const { zaps, zapsLoading, zapsError } = useZapsSubscription({ event: course }); const [zapAmount, setZapAmount] = useState(0); const [lessonCount, setLessonCount] = useState(0); const router = useRouter(); const { returnImageProxy } = useImageProxy(); useEffect(() => { if (zaps.length > 0) { const total = getTotalFromZaps(zaps, course); setZapAmount(total); } }, [zaps, course]); useEffect(() => { if (course && course?.tags) { const lessons = course.tags.filter(tag => tag[0] === "a"); setLessonCount(lessons.length); } }, [course]); if (zapsError) return
{lessonCount} lessons
{course?.published_at && course.published_at !== "" ? ( formatTimestampToHowLongAgo(course.published_at) ) : ( formatTimestampToHowLongAgo(course.created_at) )}