'use client'; import { useState, useEffect, Suspense } from 'react'; import { useSearchParams, useRouter } from 'next/navigation'; import { ColorPicker } from '@/components/color/ColorPicker'; import { ColorDisplay } from '@/components/color/ColorDisplay'; import { ColorInfo } from '@/components/color/ColorInfo'; import { ManipulationPanel } from '@/components/tools/ManipulationPanel'; import { useColorInfo } from '@/lib/api/queries'; import { useKeyboard } from '@/lib/hooks/useKeyboard'; import { useColorHistory } from '@/lib/stores/historyStore'; import { Loader2, Share2, History, X } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { toast } from 'sonner'; function PlaygroundContent() { const searchParams = useSearchParams(); const router = useRouter(); const [color, setColor] = useState(() => { // Initialize from URL if available const urlColor = searchParams.get('color'); return urlColor ? `#${urlColor.replace('#', '')}` : '#ff0099'; }); const { data, isLoading, isError, error } = useColorInfo({ colors: [color], }); const colorInfo = data?.colors[0]; // Color history const { history, addColor, removeColor, clearHistory, getRecent } = useColorHistory(); const recentColors = getRecent(10); // Update URL and history when color changes useEffect(() => { const hex = color.replace('#', ''); router.push(`/playground?color=${hex}`, { scroll: false }); addColor(color); }, [color, router, addColor]); // Share color via URL const handleShare = () => { const url = `${window.location.origin}/playground?color=${color.replace('#', '')}`; navigator.clipboard.writeText(url); toast.success('Link copied to clipboard!'); }; // Copy color to clipboard const handleCopyColor = () => { navigator.clipboard.writeText(color); toast.success('Color copied to clipboard!'); }; // Random color generation const handleRandomColor = () => { const randomHex = '#' + Math.floor(Math.random() * 16777215).toString(16).padStart(6, '0'); setColor(randomHex); }; // Keyboard shortcuts useKeyboard([ { key: 'c', meta: true, handler: handleCopyColor, description: 'Copy color', }, { key: 's', meta: true, handler: handleShare, description: 'Share color', }, { key: 'r', meta: true, handler: handleRandomColor, description: 'Random color', }, ]); return (
Interactive color manipulation and analysis tool
Error loading color information
{error?.message || 'Unknown error'}