'use client' import { useState, useRef, useEffect } from 'react' // import Turnstile, { useTurnstile } from "react-turnstile"; import { Button } from "@/components/ui/button" import { Input } from "@/components/ui/input" import { Label } from "@/components/ui/label" import { Card, CardContent, CardFooter, CardHeader, CardTitle } from "@/components/ui/card" import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert" import { AlertCircle, Github, ExternalLink } from "lucide-react" import "./App.css" const fantasicLoadingText = [ 'Finding Elon Musk...', 'Generating BlueSky...', 'Creating Circle...', 'Uninstalling X...', 'Banning by Elon Musk...', 'Launching Rocket...', ] export default function Component() { // const turnstile = useTurnstile() const [handle, setHandle] = useState('') const [captchaKey,] = useState('') const [imageData, setImageData] = useState(null) const [backgroundColor, setBackgroundColor] = useState('#0085ff') const [isLoading, setIsLoading] = useState(false) const [loadingText, setLoadingText] = useState('Generating...') const [error, setError] = useState(null) const canvasRef = useRef(null) const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setIsLoading(true) setError(null) setImageData(null) // turnstile.reset() try { const response = await fetch(`/generate`, { method: 'POST', body: new URLSearchParams({ handle, captchaKey }), headers: { 'Content-Type': 'application/x-www-form-urlencoded', }, }) if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`) } const blob = await response.blob() const reader = new FileReader() reader.onloadend = () => { const base64data = reader.result as string setImageData(base64data) } reader.readAsDataURL(blob) } catch (error) { console.error('Error fetching image:', error) setError('Failed to generate image. Please try again.') } finally { setIsLoading(false) } } useEffect(() => { if (isLoading) { const interval = setInterval(() => { setLoadingText(fantasicLoadingText[Math.floor(Math.random() * fantasicLoadingText.length)]) }, 1000) return () => clearInterval(interval) } }, [isLoading]) useEffect(() => { if (imageData && canvasRef.current) { const canvas = canvasRef.current const ctx = canvas.getContext('2d') const img = new Image() img.onload = () => { canvas.width = img.width canvas.height = img.height ctx!.fillStyle = backgroundColor ctx!.fillRect(0, 0, canvas.width, canvas.height) ctx!.drawImage(img, 0, 0) } img.src = imageData } }, [imageData, backgroundColor]) const handleSave = () => { if (canvasRef.current) { const link = document.createElement('a') link.download = `${handle}-bluesky-circlr.png` link.href = canvasRef.current.toDataURL() link.click() } } return (
BlueSky Circle Generator
setHandle(e.target.value)} onBlur={(e) => { // remove @ from handle setHandle(e.target.value.replace('@', '')) // remove invalid characters setHandle(e.target.value.replace(/[^a-zA-Z0-9_\-.]/g, '')) }} pattern='@{0,1}[a-zA-Z0-9_\-.]*' placeholder="Enter BlueSky Handle" required />
{/* { setCaptchaKey(token) }} /> */} {error && ( Error {error} )} {imageData && (
)}
{imageData && (
setBackgroundColor(e.target.value)} />
)}
) }