ali

"use client"; import { useState, useEffect, useRef } from "react"; import { Button } from "@/components/ui/button"; import { Textarea } from "@/components/ui/textarea"; import { motion, AnimatePresence } from "framer-motion"; export default function AliApp() { const [text, setText] = useState(""); const [storedText, setStoredText] = useState(null); const [isEditing, setIsEditing] = useState(false); const [editValue, setEditValue] = useState(""); const [showCopied, setShowCopied] = useState(false); const [buttonState, setButtonState] = useState<"idle" | "storing" | "copying">("idle"); const longPressTimer = useRef(null); // Load stored text from localStorage on component mount useEffect(() => { const savedText = localStorage.getItem("aliAppText"); if (savedText) { setStoredText(savedText); } }, []); // Save text to localStorage whenever storedText changes useEffect(() => { if (storedText !== null) { localStorage.setItem("aliAppText", storedText); } }, [storedText]); const handleCopy = () => { if (text) { navigator.clipboard.writeText(text); triggerCopyFeedback(); } }; const handleEnglishButton = () => { if (storedText === null) { // First tap - store text setStoredText(text); setButtonState("storing"); setTimeout(() => setButtonState("idle"), 1500); } else { // Subsequent taps - copy stored text navigator.clipboard.writeText(storedText); triggerCopyFeedback(); setButtonState("copying"); setTimeout(() => setButtonState("idle"), 1500); } }; const triggerCopyFeedback = () => { setShowCopied(true); setTimeout(() => setShowCopied(false), 1500); }; const startLongPress = () => { if (storedText === null) return; longPressTimer.current = setTimeout(() => { setIsEditing(true); setEditValue(storedText); }, 500); }; const cancelLongPress = () => { if (longPressTimer.current) { clearTimeout(longPressTimer.current); longPressTimer.current = null; } }; const saveEditedText = () => { setStoredText(editValue); setIsEditing(false); }; const cancelEdit = () => { setIsEditing(false); }; return (
{/* Copy Feedback Animation */} {showCopied && (
Copied to clipboard!
)}
{/* Button State Feedback */} {buttonState !== "idle" && (
{buttonState === "storing" ? (
Text stored successfully
) : (
Copied stored text
)}
)}