-
This commit is contained in:
@@ -0,0 +1,117 @@
|
||||
import { useEffect } from 'react'
|
||||
import { Link, useSearchParams } from 'react-router-dom'
|
||||
import { motion } from 'framer-motion'
|
||||
import { ImageOff, MapPin, Zap } from 'lucide-react'
|
||||
import { Spinner, Tag } from '../components/ui'
|
||||
import { useApi } from '../hooks/useApi'
|
||||
|
||||
const FILTERS = [
|
||||
{ value: '', label: 'All projects' },
|
||||
{ value: 'residential', label: 'Residential' },
|
||||
{ value: 'commercial', label: 'Commercial' },
|
||||
]
|
||||
const PAGE_SIZE = 12
|
||||
|
||||
export function ProjectCard({ p, i = 0 }) {
|
||||
return (
|
||||
<motion.li initial={{ opacity: 0, y: 16 }} animate={{ opacity: 1, y: 0 }} transition={{ duration: 0.4, delay: (i % 6) * 0.05 }}>
|
||||
<Link to={`/projects/${p.slug}`} className="group flex h-full flex-col overflow-hidden rounded-[24px] bg-white ring-1 ring-line transition hover:-translate-y-1 hover:shadow-[0_16px_40px_rgba(15,23,42,0.10)]">
|
||||
<div className="relative aspect-[4/3] overflow-hidden bg-surface">
|
||||
{p.featured_image ? (
|
||||
<img src={p.featured_image.thumbnail_url} alt={p.title} className="size-full object-cover transition duration-700 group-hover:scale-105" loading="lazy" />
|
||||
) : (
|
||||
<div className="grid size-full place-items-center text-muted"><ImageOff className="size-8" /></div>
|
||||
)}
|
||||
<span className="absolute top-4 left-4 rounded-full bg-footer/80 px-3 py-1 text-[12px] font-extrabold tracking-[1px] text-white uppercase backdrop-blur">
|
||||
{p.category}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex flex-1 flex-col gap-3 p-6">
|
||||
<h3 className="text-[20px] leading-7 font-bold text-navy">{p.title}</h3>
|
||||
<div className="mt-auto flex flex-wrap gap-x-5 gap-y-1 text-[14px] font-semibold text-slate">
|
||||
{p.capacity_kw && <span className="flex items-center gap-1.5"><Zap className="size-4 text-yellow-badge" />{p.capacity_kw} kW</span>}
|
||||
{p.location && <span className="flex items-center gap-1.5"><MapPin className="size-4 text-muted" />{p.location}</span>}
|
||||
</div>
|
||||
</div>
|
||||
</Link>
|
||||
</motion.li>
|
||||
)
|
||||
}
|
||||
|
||||
export default function ProjectsPage() {
|
||||
const [params, setParams] = useSearchParams()
|
||||
const category = params.get('category') || ''
|
||||
const page = Math.max(1, Number(params.get('page')) || 1)
|
||||
const { data, loading, error, reload } = useApi('/projects', {
|
||||
params: { page, page_size: PAGE_SIZE, ...(category ? { category } : {}) },
|
||||
})
|
||||
const pages = data ? Math.max(1, Math.ceil(data.total / PAGE_SIZE)) : 1
|
||||
|
||||
useEffect(() => {
|
||||
document.title = 'Our Projects — Saura Shakti'
|
||||
}, [])
|
||||
|
||||
const setFilter = (value) => setParams(value ? { category: value } : {})
|
||||
|
||||
return (
|
||||
<div className="bg-surface-2 py-14 lg:py-20">
|
||||
<div className="container-site flex flex-col gap-10">
|
||||
<header className="flex flex-col gap-4">
|
||||
<Tag className="self-start">Completed installations</Tag>
|
||||
<h1 className="h2 text-navy">Our Solar Projects</h1>
|
||||
<p className="lead max-w-[720px] text-navy">Rooftop and on-grid systems installed by the Saura Shakti team for homes and businesses.</p>
|
||||
</header>
|
||||
|
||||
<div className="flex flex-wrap gap-2" role="tablist" aria-label="Filter projects">
|
||||
{FILTERS.map((f) => (
|
||||
<button
|
||||
key={f.value}
|
||||
type="button"
|
||||
role="tab"
|
||||
aria-selected={category === f.value}
|
||||
onClick={() => setFilter(f.value)}
|
||||
className={`h-[37px] rounded-full px-6 font-inter text-[14px] transition ${category === f.value ? 'bg-lime text-black' : 'border border-forest bg-white text-navy hover:bg-lime/30'}`}
|
||||
>
|
||||
{f.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{loading && !data ? (
|
||||
<div className="grid place-items-center py-24 text-brand"><Spinner className="size-8" /></div>
|
||||
) : error ? (
|
||||
<div className="rounded-[24px] bg-white p-10 text-center">
|
||||
<p className="text-[16px] text-[#B42318]">{error}</p>
|
||||
<button type="button" onClick={reload} className="mt-4 rounded-full bg-brand px-6 py-2.5 font-semibold text-white">Try again</button>
|
||||
</div>
|
||||
) : data.items.length === 0 ? (
|
||||
<div className="rounded-[24px] bg-white p-12 text-center">
|
||||
<p className="text-[18px] font-semibold text-navy">No projects published yet.</p>
|
||||
<p className="mt-2 text-slate">Check back soon — new installations are added regularly.</p>
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<ul className={`grid gap-6 sm:grid-cols-2 lg:grid-cols-3 ${loading ? 'opacity-60' : ''}`}>
|
||||
{data.items.map((p, i) => <ProjectCard key={p.id} p={p} i={i} />)}
|
||||
</ul>
|
||||
{pages > 1 && (
|
||||
<nav className="flex items-center justify-center gap-2" aria-label="Pagination">
|
||||
{Array.from({ length: pages }, (_, i) => i + 1).map((n) => (
|
||||
<button
|
||||
key={n}
|
||||
type="button"
|
||||
onClick={() => setParams({ ...(category ? { category } : {}), page: String(n) })}
|
||||
aria-current={n === page ? 'page' : undefined}
|
||||
className={`size-10 rounded-full font-inter text-[14px] font-semibold ${n === page ? 'bg-brand text-white' : 'bg-white text-navy ring-1 ring-line hover:bg-surface'}`}
|
||||
>
|
||||
{n}
|
||||
</button>
|
||||
))}
|
||||
</nav>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user