import React, { useState } from 'react'; import { useAppDispatch, useAppSelector } from '../app/hooks'; import { shortenUrl, selectShortUrl, selectUrlStatus, selectUrlError, clearShortUrl, } from '../features/url/urlSlice'; const Home: React.FC = () => { // Component-level state const [longUrl, setLongUrl] = useState(''); // Redux state const dispatch = useAppDispatch(); const shortUrl = useAppSelector(selectShortUrl); const status = useAppSelector(selectUrlStatus); const error = useAppSelector(selectUrlError); // Methods const handleKeyDown = (e: React.KeyboardEvent) => { if (e.key === 'Enter' && longUrl.trim() !== '') { dispatch(shortenUrl(longUrl)); } }; const handleCopy = () => { if (shortUrl) { navigator.clipboard.writeText(shortUrl); } }; return (

minxa.lol

setLongUrl(e.target.value)} onKeyDown={handleKeyDown} className="w-full p-3 rounded-md text-lg border border-gray-300 shadow-sm focus:outline-none focus:ring-2 focus:ring-orange-400" /> {/* Loading State */} {status === 'loading' && (

Shortening your URL...

)} {/* Error Message */} {status === 'failed' && error && (

{error}

)} {/* Short URL Display */} {status === 'succeeded' && shortUrl && (

Your short URL: {shortUrl}

)}
); }; export default Home;