mirror of
https://github.com/mue/mue.git
synced 2026-07-18 14:34:12 +02:00
fix: quicklinks modal, notes length, create download
This commit is contained in:
@@ -18,6 +18,7 @@ export default class QuickLinks extends PureComponent {
|
||||
items: JSON.parse(localStorage.getItem('quicklinks')),
|
||||
showAddModal: false,
|
||||
urlError: '',
|
||||
iconError: '',
|
||||
edit: false,
|
||||
editData: '',
|
||||
};
|
||||
@@ -40,22 +41,20 @@ export default class QuickLinks extends PureComponent {
|
||||
|
||||
addLink(name, url, icon) {
|
||||
const data = JSON.parse(localStorage.getItem('quicklinks'));
|
||||
let urlError;
|
||||
|
||||
// regex: https://ihateregex.io/expr/url/
|
||||
// eslint-disable-next-line no-useless-escape
|
||||
if (
|
||||
url.length <= 0 ||
|
||||
/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()!@:%_.~#?&=]*)/.test(
|
||||
url,
|
||||
) === false
|
||||
) {
|
||||
urlError = variables.getMessage('widgets.quicklinks.url_error');
|
||||
const urlRegex =
|
||||
/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()!@:%_.~#?&=]*)/;
|
||||
if (url.length <= 0 || urlRegex.test(url) === false) {
|
||||
return this.setState({
|
||||
urlError: variables.getMessage('widgets.quicklinks.url_error'),
|
||||
});
|
||||
}
|
||||
|
||||
if (urlError) {
|
||||
if (icon.length > 0 && urlRegex.test(icon) === false) {
|
||||
return this.setState({
|
||||
urlError,
|
||||
iconError: variables.getMessage('widgets.quicklinks.url_error'),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -76,6 +75,7 @@ export default class QuickLinks extends PureComponent {
|
||||
items: data,
|
||||
showAddModal: false,
|
||||
urlError: '',
|
||||
iconError: '',
|
||||
});
|
||||
|
||||
variables.stats.postEvent('feature', 'Quicklink add');
|
||||
@@ -278,7 +278,7 @@ export default class QuickLinks extends PureComponent {
|
||||
</div>
|
||||
<Modal
|
||||
closeTimeoutMS={100}
|
||||
onRequestClose={() => this.setState({ showAddModal: false, urlError: '' })}
|
||||
onRequestClose={() => this.setState({ showAddModal: false, urlError: '', iconError: '' })}
|
||||
isOpen={this.state.showAddModal}
|
||||
className="Modal resetmodal mainModal"
|
||||
overlayClassName="Overlay resetoverlay"
|
||||
@@ -290,7 +290,7 @@ export default class QuickLinks extends PureComponent {
|
||||
editLink={(og, name, url, icon) => this.editLink(og, name, url, icon)}
|
||||
edit={this.state.edit}
|
||||
editData={this.state.editData}
|
||||
closeModal={() => this.setState({ showAddModal: false, urlError: '' })}
|
||||
closeModal={() => this.setState({ showAddModal: false, urlError: '', iconError: '' })}
|
||||
/>
|
||||
</Modal>
|
||||
</>
|
||||
|
||||
@@ -5,7 +5,7 @@ import Tooltip from 'components/helpers/tooltip/Tooltip';
|
||||
|
||||
import variables from 'modules/variables';
|
||||
|
||||
function AddModal({ urlError, addLink, closeModal, edit, editData, editLink }) {
|
||||
function AddModal({ urlError, iconError, addLink, closeModal, edit, editData, editLink }) {
|
||||
const [name, setName] = useState(edit ? editData.name : '');
|
||||
const [url, setUrl] = useState(edit ? editData.url : '');
|
||||
const [icon, setIcon] = useState(edit ? editData.url : '');
|
||||
@@ -25,23 +25,24 @@ function AddModal({ urlError, addLink, closeModal, edit, editData, editLink }) {
|
||||
maxRows={1}
|
||||
placeholder={variables.getMessage('widgets.quicklinks.name')}
|
||||
value={name}
|
||||
onChange={(e) => setName(e.target.value)}
|
||||
onChange={(e) => setName(e.target.value.replace(/(\r\n|\n|\r)/gm, ""))}
|
||||
/>
|
||||
<span className="dropdown-error" />
|
||||
<TextareaAutosize
|
||||
maxRows={10}
|
||||
placeholder={variables.getMessage('widgets.quicklinks.url')}
|
||||
value={url}
|
||||
onChange={(e) => setUrl(e.target.value)}
|
||||
onChange={(e) => setUrl(e.target.value.replace(/(\r\n|\n|\r)/gm, ""))}
|
||||
/>
|
||||
<span className="dropdown-error">{urlError}</span>
|
||||
<TextareaAutosize
|
||||
maxRows={10}
|
||||
maxLines={1}
|
||||
placeholder={variables.getMessage('widgets.quicklinks.icon')}
|
||||
value={icon}
|
||||
onChange={(e) => setIcon(e.target.value)}
|
||||
onChange={(e) => setIcon(e.target.value.replace(/(\r\n|\n|\r)/gm, ""))}
|
||||
/>
|
||||
<span className="dropdown-error" />
|
||||
<span className="dropdown-error">{iconError}</span>
|
||||
{edit ? (
|
||||
<button
|
||||
style={{
|
||||
|
||||
Reference in New Issue
Block a user