diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2f795e00..98708043 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2,7 +2,7 @@ lockfileVersion: 5.4 specifiers: '@eartharoid/deep-merge': ^0.0.2 - '@eartharoid/i18n': 1.0.4 + '@eartharoid/i18n': 1.1.0 '@emotion/react': ^11.10.0 '@emotion/styled': ^11.10.0 '@floating-ui/react-dom': ^1.0.0 @@ -32,7 +32,7 @@ specifiers: vite: ^3.0.9 dependencies: - '@eartharoid/i18n': 1.0.4 + '@eartharoid/i18n': 1.1.0 '@emotion/react': 11.10.0_react@18.2.0 '@emotion/styled': 11.10.0_g566eayvhbit5eqxocdac5mhdm '@floating-ui/react-dom': 1.0.0_biqbaboplfbrettd7655fr4n2y @@ -1552,8 +1552,8 @@ packages: resolution: {integrity: sha512-t7kmNd6m7BOGxf25tE1YBhPZbgMEsXZT0tQyVV/Mlo+rcPEmiEEc6HV1DBnYm63MvMpgTk4o6yBkeAJYCMzvNg==} dev: true - /@eartharoid/i18n/1.0.4: - resolution: {integrity: sha512-jxILUazPjIpjiUN5h1Ql8m9eHpxaD0wijMUYQqIghrzT/KS8UBUHmxNUCZOUhXEVYnXtB99p3Xvav7sPFx8InQ==} + /@eartharoid/i18n/1.1.0: + resolution: {integrity: sha512-1bD92kOMaXbcUi0cHoB+NqVgBmNUjKErsPEi2lPHgv2nV7pnz3wJ1o3NyrcBVs2mmZ/6nEfrYztxAjlSffFZRQ==} dev: false /@emotion/babel-plugin/11.10.0: diff --git a/src/components/modals/main/marketplace/sections/Added.jsx b/src/components/modals/main/marketplace/sections/Added.jsx index 0bc272dc..9fc43491 100644 --- a/src/components/modals/main/marketplace/sections/Added.jsx +++ b/src/components/modals/main/marketplace/sections/Added.jsx @@ -2,20 +2,25 @@ import variables from 'modules/variables'; import { PureComponent } from 'react'; import { MdUpdate, MdOutlineExtensionOff } from 'react-icons/md'; import { toast } from 'react-toastify'; +import Modal from 'react-modal'; +import SideloadFailedModal from '../SideloadFailedModal'; +import FileUpload from '../../settings/FileUpload'; import Item from '../Item'; import Items from '../Items'; import Dropdown from '../../settings/Dropdown'; -import { uninstall, urlParser } from 'modules/helpers/marketplace'; +import { install, uninstall, urlParser } from 'modules/helpers/marketplace'; export default class Added extends PureComponent { - constructor() { - super(); + constructor(props) { + super(props); this.state = { installed: JSON.parse(localStorage.getItem('installed')), item: {}, button: '', + showFailed: false, + failedReason: '', }; this.buttons = { uninstall: ( @@ -26,6 +31,45 @@ export default class Added extends PureComponent { }; } + installAddon(input) { + let failedReason = ''; + if (!input.name) { + failedReason = variables.getMessage('modals.main.addons.sideload.errors.no_name'); + } else if (!input.author) { + failedReason = variables.getMessage('modals.main.addons.sideload.errors.no_author'); + } else if (!input.type) { + failedReason = variables.getMessage('modals.main.addons.sideload.errors.no_type'); + } else if (!input.version) { + failedReason = variables.getMessage('modals.main.addons.sideload.errors.no_version'); + } else if ( + input.type === 'photos' && + (!input.photos || + !input.photos.length || + !input.photos[0].url || + !input.photos[0].url.default || + !input.photos[0].photographer || + !input.photos[0].location) + ) { + failedReason = variables.getMessage('modals.main.addons.sideload.errors.invalid_photos'); + } else if ( + input.type === 'quotes' && + (!input.quotes || !input.quotes.length || !input.quotes[0].quote || !input.quotes[0].author) + ) { + failedReason = variables.getMessage('modals.main.addons.sideload.errors.invalid_quotes'); + } + + if (failedReason !== '') { + return this.setState({ + failedReason, + showFailed: true, + }); + } + + install(input.type, input); + toast(variables.getMessage('toasts.installed')); + variables.stats.postEvent('marketplace', 'Sideload'); + } + toggle(type, data) { if (type === 'item') { const installed = JSON.parse(localStorage.getItem('installed')); @@ -122,17 +166,49 @@ export default class Added extends PureComponent { } render() { + const sideLoadBackendElements = () => ( + <> + this.setState({ showFailed: false })} + isOpen={this.state.showFailed} + className="Modal resetmodal mainModal sideloadModal" + overlayClassName="Overlay resetoverlay" + ariaHideApp={false} + > + this.setState({ showFailed: false })} + reason={this.state.failedReason} + /> + + this.installAddon(JSON.parse(e))} + /> + + ); + if (this.state.installed.length === 0) { return ( -
-
- - {variables.getMessage('modals.main.addons.empty.title')} - - {variables.getMessage('modals.main.addons.empty.description')} - + <> + {sideLoadBackendElements()} + +
+
+ + + {variables.getMessage('modals.main.addons.empty.title')} + + + {variables.getMessage('modals.main.addons.empty.description')} + +
-
+ ); } @@ -148,7 +224,11 @@ export default class Added extends PureComponent { return ( <> + {sideLoadBackendElements()} {variables.getMessage('modals.main.addons.added')} +
- - - - - - - {this.state.customQuote.map((_url, index) => ( - + {this.state.customQuote.length > 1 ? ( +
{variables.getMessage('modals.main.settings.sections.quote.title')}{variables.getMessage('modals.main.settings.sections.quote.author')}{variables.getMessage('modals.main.settings.sections.quote.custom_buttons')}
+ + + - - + {this.state.customQuote.map((_url, index) => ( + + + + - - ))} -
{variables.getMessage('modals.main.settings.sections.quote.title')}{variables.getMessage('modals.main.settings.sections.quote.author')} - this.customQuote(e, true, index, 'quote')} - varient="outlined" - style={{ marginRight: '10px' }} - /> + {variables.getMessage('modals.main.settings.sections.quote.custom_buttons')} - this.customQuote(e, true, index, 'author')} - varient="outlined" - /> - - {this.state.customQuote.length > 1 ? ( +
+ this.customQuote(e, true, index, 'quote')} + varient="outlined" + style={{ marginRight: '10px' }} + /> + + this.customQuote(e, true, index, 'author')} + varient="outlined" + /> + - ) : null} -
+ + + ))} + + ) : ( +
+
+ + {variables.getMessage('modals.main.settings.sections.message.no_messages')} + + + {variables.getMessage('modals.main.settings.sections.message.add_some')} + + +
+
+ )} ); } else { diff --git a/src/components/widgets/message/Message.jsx b/src/components/widgets/message/Message.jsx index 6701ec75..fbc61f13 100644 --- a/src/components/widgets/message/Message.jsx +++ b/src/components/widgets/message/Message.jsx @@ -22,7 +22,7 @@ export default class Message extends PureComponent { this.message.current.style.display = 'block'; this.message.current.style.fontSize = `${ - 1.6 * Number((localStorage.getItem('zoomMessage') || 100) / 100) + 1 * Number((localStorage.getItem('zoomMessage') || 100) / 100) }em`; } }); @@ -30,7 +30,7 @@ export default class Message extends PureComponent { const messages = JSON.parse(localStorage.getItem('messages')) || []; this.message.current.style.fontSize = `${ - 1.6 * Number((localStorage.getItem('zoomMessage') || 100) / 100) + 1 * Number((localStorage.getItem('zoomMessage') || 100) / 100) }em`; if (messages.length === 0) { diff --git a/src/components/widgets/message/message.scss b/src/components/widgets/message/message.scss index 216446b9..e51db5c1 100644 --- a/src/components/widgets/message/message.scss +++ b/src/components/widgets/message/message.scss @@ -2,4 +2,5 @@ cursor: default; margin: 0; user-select: none; + font-size: 1em; } diff --git a/src/components/widgets/quote/Quote.jsx b/src/components/widgets/quote/Quote.jsx index 59d40f26..5a6044e0 100644 --- a/src/components/widgets/quote/Quote.jsx +++ b/src/components/widgets/quote/Quote.jsx @@ -198,13 +198,19 @@ export default class Quote extends PureComponent { customQuote = customQuote ? customQuote[Math.floor(Math.random() * customQuote.length)] : null; + - if (customQuote && customQuote !== '' && customQuote !== 'undefined') { + if (customQuote !== undefined) { return this.setState({ quote: '"' + customQuote.quote + '"', author: customQuote.author, authorlink: this.getAuthorLink(customQuote.author), authorimg: await this.getAuthorImg(customQuote.author), + noQuote: false + }); + } else { + this.setState({ + noQuote: true }); } break; @@ -396,6 +402,9 @@ export default class Quote extends PureComponent { } render() { + if (this.state.noQuote === true) { + return <>; + } return (