import variables from 'config/variables'; import { memo, useState, useEffect } from 'react'; import { MdContentCopy, MdAssignment, MdPushPin, MdDownload } from 'react-icons/md'; import { useFloating, shift } from '@floating-ui/react-dom'; import TextareaAutosize from '@mui/material/TextareaAutosize'; import { toast } from 'react-toastify'; import { Tooltip } from 'components/Elements'; import { saveFile } from 'utils/saveFile'; import EventBus from 'utils/eventbus'; const Notes = ({ notesRef, floatRef, position, xPosition, yPosition }) => { const [notes, setNotes] = useState(localStorage.getItem('notes') || ''); const [showNotes, setShowNotes] = useState(localStorage.getItem('notesPinned') === 'true'); const [zoomFontSize, setZoomFontSize] = useState('1.2rem'); useEffect(() => { const handleRefresh = (data) => { if (data === 'navbar') { setZoomFontSize(Number(((localStorage.getItem('zoomNavbar') || 100) / 100) * 1.2) + 'rem'); } }; setZoomFontSize(Number(((localStorage.getItem('zoomNavbar') || 100) / 100) * 1.2) + 'rem'); EventBus.on('refresh', handleRefresh); return () => { EventBus.off('refresh'); }; }, []); const handleSetNotes = (e) => { localStorage.setItem('notes', e.target.value); setNotes(e.target.value); }; const handleShowNotes = () => { setShowNotes(true); }; const handleHideNotes = () => { setShowNotes(localStorage.getItem('notesPinned') === 'true'); }; const handlePin = () => { variables.stats.postEvent('feature', 'Notes pin'); const notesPinned = localStorage.getItem('notesPinned') === 'true'; localStorage.setItem('notesPinned', !notesPinned); setShowNotes(!notesPinned); }; const handleCopy = () => { variables.stats.postEvent('feature', 'Notes copied'); navigator.clipboard.writeText(notes); toast(variables.getMessage('toasts.notes')); }; const handleDownload = () => { if (!notes || notes === '') { return; } variables.stats.postEvent('feature', 'Notes download'); saveFile(notes, 'mue-notes.txt', 'text/plain'); }; return (