diff --git a/components/dashboard/PeakHours.tsx b/components/dashboard/PeakHours.tsx index 0242531..a5e8c5a 100644 --- a/components/dashboard/PeakHours.tsx +++ b/components/dashboard/PeakHours.tsx @@ -1,6 +1,6 @@ 'use client' -import { useState, useEffect, useMemo, useRef } from 'react' +import { useState, useEffect, useMemo, useRef, type CSSProperties } from 'react' import { motion, AnimatePresence } from 'framer-motion' import { logger } from '@/lib/utils/logger' import { getDailyStats } from '@/lib/api/stats' @@ -14,19 +14,34 @@ interface PeakHoursProps { const DAYS = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] const HOUR_LABELS: Record = { 0: '12am', 6: '6am', 12: '12pm', 18: '6pm' } +// Orange intensity palette (light → dark) +const HIGHLIGHT_COLORS = [ + 'rgba(253,94,15,0.18)', + 'rgba(253,94,15,0.38)', + 'rgba(253,94,15,0.62)', + '#FD5E0F', +] + function formatHour(hour: number): string { if (hour === 0) return '12am' if (hour === 12) return '12pm' return hour < 12 ? `${hour}am` : `${hour - 12}pm` } +function getHighlightColor(value: number, max: number): string { + if (value === 0) return HIGHLIGHT_COLORS[0] + const ratio = value / max + if (ratio < 0.25) return HIGHLIGHT_COLORS[1] + if (ratio < 0.6) return HIGHLIGHT_COLORS[2] + return HIGHLIGHT_COLORS[3] +} + export default function PeakHours({ siteId, dateRange }: PeakHoursProps) { const [data, setData] = useState([]) const [isLoading, setIsLoading] = useState(true) const [animKey, setAnimKey] = useState(0) const [hovered, setHovered] = useState<{ day: number; hour: number } | null>(null) const [tooltipPos, setTooltipPos] = useState<{ x: number; y: number } | null>(null) - const [blobMode, setBlobMode] = useState(false) const gridRef = useRef(null) useEffect(() => { @@ -106,18 +121,6 @@ export default function PeakHours({ siteId, dateRange }: PeakHoursProps) {

Peak Hours

- {hasData && !isLoading && ( - - )}

When your visitors are most active @@ -134,62 +137,36 @@ export default function PeakHours({ siteId, dateRange }: PeakHoursProps) {

) : hasData ? ( <> -
+
{grid.map((hours, dayIdx) => (
{DAYS[dayIdx]} -
+
{hours.map((value, hour) => { const isHoveredCell = hovered?.day === dayIdx && hovered?.hour === hour const isBestCell = bestTime?.day === dayIdx && bestTime?.hour === hour - - const bgColor = value === 0 - ? (blobMode ? 'rgba(253,94,15,0.0)' : 'rgba(253,94,15,0.07)') - : `rgba(253,94,15,${Math.max(blobMode ? 0.25 : 0.15, (value / max) * (blobMode ? 1 : 0.92))})` + const isActive = value > 0 + const highlightColor = getHighlightColor(value, max) return ( - handleCellMouseEnter(e, dayIdx, hour)} onMouseLeave={() => { setHovered(null); setTooltipPos(null) }} /> @@ -212,7 +189,10 @@ export default function PeakHours({ siteId, dateRange }: PeakHoursProps) { {label} ))} - + 12am
@@ -257,7 +237,7 @@ export default function PeakHours({ siteId, dateRange }: PeakHoursProps) { Your busiest time is{' '} diff --git a/tailwind.config.ts b/tailwind.config.ts index 6c06a07..650517e 100644 --- a/tailwind.config.ts +++ b/tailwind.config.ts @@ -13,6 +13,21 @@ const config: Config = { ], theme: { extend: { + keyframes: { + 'cell-highlight': { + '0%': { backgroundColor: 'transparent' }, + '100%': { backgroundColor: 'var(--highlight)' }, + }, + 'cell-flash': { + '0%': { backgroundColor: 'transparent' }, + '50%': { backgroundColor: 'var(--highlight)' }, + '100%': { backgroundColor: 'transparent' }, + }, + }, + animation: { + 'cell-highlight': 'cell-highlight 0.5s ease forwards', + 'cell-flash': 'cell-flash 0.6s ease forwards', + }, fontFamily: { sans: ['var(--font-plus-jakarta-sans)', 'system-ui', 'sans-serif'], },