import React, { useState, useEffect, useRef } from 'react'; import { Link } from 'react-router-dom'; import { ArrowLeftIcon, DownloadSimple, Trash, CloudRain, FloppyDisk, FolderOpen, ArrowsOutLineVerticalIcon, } from '@phosphor-icons/react'; import Seo from '../../components/Seo'; import { useToast } from '../../hooks/useToast'; import ConfirmationModal from '../../components/ConfirmationModal'; import usePersistentState from '../../hooks/usePersistentState'; const NotepadPage = () => { const [text, setText] = useState(''); const [isRainy, setIsRainy] = useState(false); const [isClearModalOpen, setIsClearModalOpen] = useState(false); const [isFixedSize, setIsFixedSize] = usePersistentState( 'fezcodex-notepad-fixed-size', true, ); // Default to true for fixed height const textareaRef = useRef(null); const fileInputRef = useRef(null); const { addToast } = useToast(); // Load saved text from local storage on mount useEffect(() => { const savedText = localStorage.getItem('fezcodex-notepad-content'); if (savedText) { setText(savedText); } }, []); // Save text to local storage whenever it changes (Autosave) useEffect(() => { localStorage.setItem('fezcodex-notepad-content', text); }, [text]); // Memoize rain drops to prevent re-calculation on every render const rainDrops = React.useMemo(() => { return [...Array(20)].map(() => ({ left: `${Math.random() * 100}%`, top: `-${Math.random() * 20}%`, height: `${Math.random() * 20 + 10}%`, duration: `${Math.random() * 1 + 0.5}s`, delay: `${Math.random() * 2}s`, })); }, []); const handleSave = () => { localStorage.setItem('fezcodex-notepad-content', text); addToast({ title: 'Saved', message: 'Note manually saved to local storage.', duration: 3000, }); }; const handleLoad = () => { fileInputRef.current.click(); }; const handleFileUpload = (event) => { const file = event.target.files[0]; if (file) { const reader = new FileReader(); reader.onload = (e) => { setText(e.target.result); addToast({ title: 'Loaded', message: `Loaded content from ${file.name}`, duration: 3000, }); }; reader.readAsText(file); } // Reset input so the same file can be selected again if needed event.target.value = null; }; const handleDownload = () => { const element = document.createElement('a'); const file = new Blob([text], { type: 'text/plain' }); element.href = URL.createObjectURL(file); element.download = 'note.txt'; document.body.appendChild(element); element.click(); document.body.removeChild(element); addToast({ title: 'Downloaded', message: 'Your note has been saved.', duration: 3000, }); }; const handleClear = () => { setIsClearModalOpen(true); }; const confirmClear = () => { setText(''); setIsClearModalOpen(false); addToast({ title: 'Cleared', message: 'Notepad cleared.', duration: 3000 }); }; const toggleRain = () => { setIsRainy(!isRainy); addToast({ title: isRainy ? 'Sunlight' : 'Rainy Mood', message: isRainy ? 'Rain effect disabled.' : 'Rain effect enabled.', duration: 2000, }); }; const toggleFixedSize = () => { setIsFixedSize((prev) => !prev); addToast({ title: isFixedSize ? 'Expanded' : 'Fixed Height', message: isFixedSize ? 'Notepad expanded to fill space.' : 'Notepad height is now fixed.', duration: 2000, }); }; return (
{/* Rain Effect Overlay */} {isRainy && (
{/* Simple CSS Rain */} {rainDrops.map((drop, i) => (
))}
)}
{/* Header */}
Back to Apps

Notepad

{/* Notepad Area */}
{/* Paper Lines Background */}
{/* Red Margin Line */}