Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image placeholder added #658

Merged
merged 2 commits into from
Nov 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions next_frontend/components/cases/CaseCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ import {
// import { AssuranceCase } from '@/types'
import Link from 'next/link'
import moment from 'moment'
import { Eye, MessageCircleMore, PencilRuler, ScanEye, Trash2 } from 'lucide-react'
import { Eye, Loader2, MessageCircleMore, PencilRuler, ScanEye, Trash2 } from 'lucide-react'
import { AlertModal } from '@/components/modals/alertModal'
import { useParams, useRouter } from 'next/navigation'
import { useLoginToken } from '@/hooks/useAuth'
import Image from 'next/image'
import { Skeleton } from '../ui/skeleton'

interface CaseCardProps {
assuranceCase: any
Expand All @@ -31,6 +32,7 @@ const CaseCard = ({ assuranceCase } : CaseCardProps) => {
const [open, setOpen] = useState(false)
const [loading, setLoading] = useState(false)
const [imgSrc, setImgSrc] = useState('');
const [imageLoading, setImageLoading] = useState<boolean>(true);
// const [imgSrc, setImgSrc] = useState(`https://teamedia.blob.core.windows.net/sample-container/chart-screenshot-case-${assuranceCase.id}.png`);
// const [imageExists, setImageExists] = useState(true)
// const [imageUrl, setImageUrl] = useState<string>('')
Expand Down Expand Up @@ -81,6 +83,8 @@ const CaseCard = ({ assuranceCase } : CaseCardProps) => {
setImgSrc(result.image)
} catch (error) {
console.log('Failed to fetch image')
} finally {
setImageLoading(false)
}
}

Expand All @@ -93,15 +97,20 @@ const CaseCard = ({ assuranceCase } : CaseCardProps) => {
<Link href={`/case/${assuranceCase.id}`}>
<Card className='flex flex-col justify-start items-start group-hover:bg-indigo-500/5 transition-all h-full'>
<CardHeader className='flex-1 w-full'>
<div className='relative flex aspect-video rounded-md mb-4 overflow-hidden'>
{imgSrc && (
<Image
src={imgSrc}
alt={`Assurance Case ${assuranceCase.name} screenshot`}
fill
/>
{imageLoading ?
(
<Skeleton className="relative flex aspect-video rounded-md mb-4 overflow-hidden" />
) : (
<div className='relative flex aspect-video rounded-md mb-4 overflow-hidden'>
{imgSrc && (
<Image
src={imgSrc}
alt={`Assurance Case ${assuranceCase.name} screenshot`}
fill
/>
)}
</div>
)}
</div>
<CardTitle>{name}</CardTitle>
<CardDescription className='text-slate-900 dark:text-white'>{description}</CardDescription>
</CardHeader>
Expand Down
Loading