import variables from 'modules/variables'; import React, { PureComponent } from 'react'; import { MdCancel, MdAdd } from 'react-icons/md'; import TextareaAutosize from '@mui/material/TextareaAutosize'; import Header from '../Header'; import Checkbox from '../Checkbox'; import Dropdown from '../Dropdown'; import SettingsItem from '../SettingsItem'; import { toast } from 'react-toastify'; import EventBus from 'modules/helpers/eventbus'; export default class QuoteSettings extends PureComponent { getMessage = (text) => variables.language.getMessage(variables.languagecode, text); constructor() { super(); this.state = { quoteType: localStorage.getItem('quoteType') || 'api', customQuote: this.getCustom(), }; } marketplaceType = () => { if (localStorage.getItem('quote_packs')) { return ( ); } }; resetCustom = () => { localStorage.setItem('customQuote', '[{"quote": "", "author": ""}]'); this.setState({ customQuote: [ { quote: '', author: '', }, ], }); toast(this.getMessage('toasts.reset')); EventBus.dispatch('refresh', 'background'); }; customQuote(e, text, index, type) { const result = text === true ? e.target.value : e.target.result; const customQuote = this.state.customQuote; customQuote[index][type] = result; this.setState({ customQuote, }); this.forceUpdate(); localStorage.setItem('customQuote', JSON.stringify(customQuote)); document.querySelector('.reminder-info').style.display = 'flex'; localStorage.setItem('showReminder', true); } modifyCustomQuote(type, index) { const customQuote = this.state.customQuote; if (type === 'add') { customQuote.push({ quote: '', author: '', }); } else { customQuote.splice(index, 1); } this.setState({ customQuote, }); this.forceUpdate(); localStorage.setItem('customQuote', JSON.stringify(customQuote)); } getCustom() { let data = JSON.parse(localStorage.getItem('customQuote')); if (data === null) { data = [ { quote: localStorage.getItem('customQuote') || '', author: localStorage.getItem('customQuoteAuthor') || '', }, ]; } return data; } render() { let customSettings; if (this.state.quoteType === 'custom') { customSettings = ( <> {this.state.customQuote.map((_url, index) => ( ))}
Quote Author Buttons
this.customQuote(e, true, index, 'quote')} varient="outlined" style={{ marginRight: '10px' }} /> this.customQuote(e, true, index, 'author')} varient="outlined" /> {this.state.customQuote.length > 1 ? ( ) : null}
); } else { // api customSettings = ( ); } return ( <>
this.setState({ quoteType: value })} category="quote" > {this.marketplaceType()} {customSettings} ); } }