diff --git a/src/components/modals/settings/sections/BackgroundSettings.jsx b/src/components/modals/settings/sections/BackgroundSettings.jsx index 9a234c51..9d6fe085 100644 --- a/src/components/modals/settings/sections/BackgroundSettings.jsx +++ b/src/components/modals/settings/sections/BackgroundSettings.jsx @@ -2,12 +2,14 @@ import React from 'react'; import { toast } from 'react-toastify'; export default class BackgroundSettings extends React.PureComponent { + DefaultGradientSettings = { "angle": "180", "gradient": [{ "colour": "Disabled", "stop": 0 }], "type": "linear" }; + constructor(...args) { super(...args); this.state = { blur: 0, brightness: 100, - gradientSettings: '' + gradientSettings: this.DefaultGradientSettings }; } @@ -15,7 +17,7 @@ export default class BackgroundSettings extends React.PureComponent { switch (key) { case 'customBackgroundColour': localStorage.setItem('customBackgroundColour', ''); - this.setState({ gradientSettings: '' }); + this.setState({ gradientSettings: this.DefaultGradientSettings }); break; case 'customBackground': document.getElementById('customBackground').value = ''; break; case 'blur': @@ -48,7 +50,7 @@ export default class BackgroundSettings extends React.PureComponent { }; const hex = localStorage.getItem('customBackgroundColour'); - let gradientSettings = ''; + let gradientSettings = undefined; if (hex !== '') { try { gradientSettings = JSON.parse(hex); @@ -56,6 +58,9 @@ export default class BackgroundSettings extends React.PureComponent { //Disregard exception. } } + if (gradientSettings === undefined) { + gradientSettings = this.DefaultGradientSettings + } this.setState({ blur: localStorage.getItem('blur'), @@ -112,7 +117,7 @@ export default class BackgroundSettings extends React.PureComponent { } currentGradientSettings = () => { - if (typeof this.state.gradientSettings === 'object') { + if (typeof this.state.gradientSettings === 'object' && this.state.gradientSettings.gradient.every(g => g.colour !== 'Disabled')) { const clampNumber = (num, a, b) => Math.max(Math.min(num, Math.max(a, b)), Math.min(a, b)); return JSON.stringify({ ...this.state.gradientSettings, @@ -123,7 +128,7 @@ export default class BackgroundSettings extends React.PureComponent { } render() { - let colourSettings; + let colourSettings = null; if (typeof this.state.gradientSettings === 'object') { const gradientInputs = this.state.gradientSettings.gradient.map((g, i) => { const gradientHasMoreThanOneColour = this.state.gradientSettings.gradient.length > 1; @@ -131,7 +136,7 @@ export default class BackgroundSettings extends React.PureComponent {