import variables from 'modules/variables'; import { PureComponent, memo } 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 '../../helpers/tooltip/Tooltip'; import { saveFile } from 'modules/helpers/settings/modals'; import EventBus from 'modules/helpers/eventbus'; class Notes extends PureComponent { constructor() { super(); this.state = { notes: localStorage.getItem('notes') || '', visibility: localStorage.getItem('notesPinned') === 'true' ? 'visible' : 'hidden', showNotes: localStorage.getItem('notesPinned') === 'true' ? true : false, }; } setZoom() { this.setState({ zoomFontSize: Number(((localStorage.getItem('zoomNavbar') || 100) / 100) * 1.2) + 'rem', }); } componentDidMount() { EventBus.on('refresh', (data) => { if (data === 'navbar') { this.forceUpdate(); try { this.setZoom(); } catch (e) {} } }); this.setZoom(); } componentWillUnmount() { EventBus.off('refresh'); } setNotes = (e) => { localStorage.setItem('notes', e.target.value); this.setState({ notes: e.target.value, }); }; showNotes() { this.setState({ showNotes: true, }); } hideNotes() { this.setState({ showNotes: localStorage.getItem('notesPinned') === 'true', }); } pin() { variables.stats.postEvent('feature', 'Notes pin'); const notesPinned = localStorage.getItem('notesPinned') === 'true'; localStorage.setItem('notesPinned', !notesPinned); this.setState({ showNotes: !notesPinned, }); } copy() { variables.stats.postEvent('feature', 'Notes copied'); navigator.clipboard.writeText(this.state.notes); toast(variables.getMessage('toasts.notes')); } download() { const notes = localStorage.getItem('notes'); if (!notes || notes === '') { return; } variables.stats.postEvent('feature', 'Notes download'); saveFile(this.state.notes, 'mue-notes.txt', 'text/plain'); } render() { return (
this.hideNotes()} onFocus={() => this.showNotes()}> {this.state.showNotes && (
{variables.getMessage('widgets.navbar.notes.title')}
)}
); } } function NotesWrapper() { const { x, y, reference, floating, strategy } = useFloating({ placement: 'bottom', middleware: [shift()], }); return ( ); } export default memo(NotesWrapper);