mirror of
https://github.com/mue/mue.git
synced 2026-07-16 13:34:03 +02:00
refactor: cleanup
This commit is contained in:
@@ -29,7 +29,7 @@ export default class Background extends PureComponent {
|
||||
const backgroundImage = document.getElementById('backgroundImage');
|
||||
|
||||
if (this.state.url !== '') {
|
||||
const url = (localStorage.getItem('ddgProxy') === 'true' && this.state.photoInfo.offline !== true && !this.state.url.startsWith('data:')) ? window.constants.DDG_IMAGE_PROXY + this.state.url : this.state.url;
|
||||
const url = (localStorage.getItem('ddgProxy') === 'true' && this.state.photoInfo.offline !== true && !this.state.url.startsWith('data:')) ? variables.constants.DDG_IMAGE_PROXY + this.state.url : this.state.url;
|
||||
const photoInformation = document.querySelector('.photoInformation');
|
||||
|
||||
// just set the background
|
||||
@@ -113,14 +113,14 @@ export default class Background extends PureComponent {
|
||||
let requestURL, data;
|
||||
switch (backgroundAPI) {
|
||||
case 'unsplash':
|
||||
requestURL = `${window.constants.PROXY_URL}/images/unsplash?quality=${apiQuality}&map=${(photoMap === 'true')}`;
|
||||
requestURL = `${variables.constants.PROXY_URL}/images/unsplash?quality=${apiQuality}&map=${(photoMap === 'true')}`;
|
||||
break;
|
||||
case 'pexels':
|
||||
requestURL = `${window.constants.PROXY_URL}/images/pexels?quality=${apiQuality}`;
|
||||
requestURL = `${variables.constants.PROXY_URL}/images/pexels?quality=${apiQuality}`;
|
||||
break;
|
||||
// Defaults to Mue
|
||||
default:
|
||||
requestURL = `${window.constants.API_URL}/images/random?category=${apiCategory}&quality=${apiQuality}`;
|
||||
requestURL = `${variables.constants.API_URL}/images/random?category=${apiCategory}&quality=${apiQuality}`;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ export default class Favourite extends PureComponent {
|
||||
this.setState({
|
||||
favourited: this.buttons.unfavourited
|
||||
});
|
||||
window.stats.postEvent('feature', 'Background favourite');
|
||||
variables.stats.postEvent('feature', 'Background favourite');
|
||||
} else {
|
||||
const url = document.getElementById('backgroundImage').style.backgroundImage.replace('url("', '').replace('")', '');
|
||||
|
||||
@@ -47,7 +47,7 @@ export default class Favourite extends PureComponent {
|
||||
this.setState({
|
||||
favourited: this.buttons.favourited
|
||||
});
|
||||
window.stats.postEvent('feature', 'Background unfavourite');
|
||||
variables.stats.postEvent('feature', 'Background unfavourite');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ export default class Favourite extends PureComponent {
|
||||
return (
|
||||
<Tooltip title={variables.language.getMessage(variables.languagecode, 'modals.main.settings.sections.background.buttons.favourite')}>
|
||||
{this.state.favourited}
|
||||
{window.keybinds.favouriteBackground && window.keybinds.favouriteBackground !== '' ? <Hotkeys keyName={window.keybinds.favouriteBackground} onKeyDown={() => this.favourite()} /> : null}
|
||||
{variables.keybinds.favouriteBackground && variables.keybinds.favouriteBackground !== '' ? <Hotkeys keyName={variables.keybinds.favouriteBackground} onKeyDown={() => this.favourite()} /> : null}
|
||||
</Tooltip>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -44,14 +44,14 @@ export default class Maximise extends PureComponent {
|
||||
});
|
||||
|
||||
this.setAttribute(0, 100);
|
||||
window.stats.postEvent('feature', 'Background maximise');
|
||||
variables.stats.postEvent('feature', 'Background maximise');
|
||||
} else {
|
||||
this.setState({
|
||||
hidden: false
|
||||
});
|
||||
|
||||
this.setAttribute(localStorage.getItem('blur'), localStorage.getItem('brightness'), true);
|
||||
window.stats.postEvent('feature', 'Background unmaximise');
|
||||
variables.stats.postEvent('feature', 'Background unmaximise');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ export default class Maximise extends PureComponent {
|
||||
return (
|
||||
<Tooltip title={variables.language.getMessage(variables.languagecode, 'modals.main.settings.sections.background.buttons.view')}>
|
||||
<Fullscreen onClick={this.maximise} className='topicons' />
|
||||
{window.keybinds.maximiseBackground && window.keybinds.maximiseBackground !== '' ? <Hotkeys keyName={window.keybinds.maximiseBackground} onKeyDown={this.maximise} /> : null}
|
||||
{variables.keybinds.maximiseBackground && variables.keybinds.maximiseBackground !== '' ? <Hotkeys keyName={variables.keybinds.maximiseBackground} onKeyDown={this.maximise} /> : null}
|
||||
</Tooltip>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ const downloadImage = async (info) => {
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
window.stats.postEvent('feature', 'Background download');
|
||||
variables.stats.postEvent('feature', 'Background download');
|
||||
};
|
||||
|
||||
export default function PhotoInformation({ info, url, api }) {
|
||||
@@ -58,7 +58,7 @@ export default function PhotoInformation({ info, url, api }) {
|
||||
setWidth(event.target.width);
|
||||
setHeight(event.target.height);
|
||||
};
|
||||
img.src = (ddgProxy && !info.offline && !url.startsWith('data:')) ? window.constants.DDG_IMAGE_PROXY + url : url;
|
||||
img.src = (ddgProxy && !info.offline && !url.startsWith('data:')) ? variables.constants.DDG_IMAGE_PROXY + url : url;
|
||||
|
||||
// info is still there because we want the favourite button to work
|
||||
if (localStorage.getItem('photoInformation') === 'false') {
|
||||
@@ -100,11 +100,11 @@ export default function PhotoInformation({ info, url, api }) {
|
||||
const zoom = 12;
|
||||
const lat = lat2tile(info.latitude, zoom);
|
||||
const lon = lon2tile(info.longitude, zoom);
|
||||
const tile = `${window.constants.MAPBOX_URL}/styles/v1/mapbox/streets-v11/tiles/${zoom}/${lon}/${lat}?access_token=${info.maptoken}`;
|
||||
const tile = `${variables.constants.MAPBOX_URL}/styles/v1/mapbox/streets-v11/tiles/${zoom}/${lon}/${lat}?access_token=${info.maptoken}`;
|
||||
|
||||
let icon = window.constants.CDN_URL + '/mapbox/mapbox-logo-dark.png';
|
||||
let icon = variables.constants.CDN_URL + '/mapbox/mapbox-logo-dark.png';
|
||||
if (document.body.classList.contains('dark')) {
|
||||
icon = window.constants.CDN_URL + '/mapbox/mapbox-logo-white.png';
|
||||
icon = variables.constants.CDN_URL + '/mapbox/mapbox-logo-white.png';
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -150,8 +150,8 @@ export default function PhotoInformation({ info, url, api }) {
|
||||
</>
|
||||
: null}
|
||||
</div>
|
||||
{window.keybinds.downloadBackground && window.keybinds.downloadBackground !== '' ? <Hotkeys keyName={window.keybinds.downloadBackground} onKeyDown={() => downloadBackground()} /> : null}
|
||||
{window.keybinds.showBackgroundInformation && window.keybinds.showBackgroundInformation !== '' ? <Hotkeys keyName={window.keybinds.showBackgroundInformation} onKeyDown={() => showBackgroundInformation()} /> : null}
|
||||
{variables.keybinds.downloadBackground && variables.keybinds.downloadBackground !== '' ? <Hotkeys keyName={variables.keybinds.downloadBackground} onKeyDown={() => downloadBackground()} /> : null}
|
||||
{variables.keybinds.showBackgroundInformation && variables.keybinds.showBackgroundInformation !== '' ? <Hotkeys keyName={variables.keybinds.showBackgroundInformation} onKeyDown={() => showBackgroundInformation()} /> : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ export default class Navbar extends PureComponent {
|
||||
</div>
|
||||
: null}
|
||||
|
||||
{(window.constants.BETA_VERSION === true) ?
|
||||
{(variables.constants.BETA_VERSION === true) ?
|
||||
<Tooltip title={variables.language.getMessage(variables.languagecode, 'widgets.navbar.tooltips.feedback')}>
|
||||
<Report className='topicons' onClick={() => this.props.openModal('feedbackModal')}/>
|
||||
</Tooltip>
|
||||
|
||||
@@ -23,7 +23,7 @@ export default class Notes extends PureComponent {
|
||||
};
|
||||
|
||||
pin() {
|
||||
window.stats.postEvent('feature', 'Notes pin');
|
||||
variables.stats.postEvent('feature', 'Notes pin');
|
||||
|
||||
if (localStorage.getItem('notesPinned') === 'true') {
|
||||
localStorage.setItem('notesPinned', false);
|
||||
@@ -39,7 +39,7 @@ export default class Notes extends PureComponent {
|
||||
}
|
||||
|
||||
copy() {
|
||||
window.stats.postEvent('feature', 'Notes copied');
|
||||
variables.stats.postEvent('feature', 'Notes copied');
|
||||
navigator.clipboard.writeText(this.state.notes);
|
||||
toast(variables.language.getMessage(variables.languagecode, 'toasts.notes'));
|
||||
}
|
||||
@@ -54,8 +54,8 @@ export default class Notes extends PureComponent {
|
||||
<TextareaAutosize rowsmax={50} placeholder={variables.language.getMessage(variables.languagecode, 'widgets.navbar.notes.placeholder')} value={this.state.notes} onChange={this.setNotes}/>
|
||||
<button onClick={() => this.pin()} className='pinNote'><PushPin/></button>
|
||||
<button onClick={() => this.copy()} className='copyNote'><FileCopyRounded/></button>
|
||||
{window.keybinds.pinNotes && window.keybinds.pinNotes !== '' ? <Hotkeys keyName={window.keybinds.pinNotes} onKeyDown={() => this.pin()}/> : null}
|
||||
{window.keybinds.copyNotes && window.keybinds.copyNotes !== '' ? <Hotkeys keyName={window.keybinds.copyNotes} onKeyDown={() => this.copy()}/> : null}
|
||||
{variables.keybinds.pinNotes && variables.keybinds.pinNotes !== '' ? <Hotkeys keyName={variables.keybinds.pinNotes} onKeyDown={() => this.pin()}/> : null}
|
||||
{variables.keybinds.copyNotes && variables.keybinds.copyNotes !== '' ? <Hotkeys keyName={variables.keybinds.copyNotes} onKeyDown={() => this.copy()}/> : null}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ export default class QuickLinks extends PureComponent {
|
||||
items: data
|
||||
});
|
||||
|
||||
window.stats.postEvent('feature', 'Quicklink delete');
|
||||
variables.stats.postEvent('feature', 'Quicklink delete');
|
||||
}
|
||||
|
||||
addLink = () => {
|
||||
@@ -80,7 +80,7 @@ export default class QuickLinks extends PureComponent {
|
||||
url: ''
|
||||
});
|
||||
|
||||
window.stats.postEvent('feature', 'Quicklink add');
|
||||
variables.stats.postEvent('feature', 'Quicklink add');
|
||||
|
||||
this.toggleAdd();
|
||||
|
||||
@@ -191,7 +191,7 @@ export default class QuickLinks extends PureComponent {
|
||||
<button className='pinNote' onClick={this.addLink}>{this.getMessage('widgets.quicklinks.add')}</button>
|
||||
</div>
|
||||
</span>
|
||||
{window.keybinds.toggleQuicklinks && window.keybinds.toggleQuicklinks !== '' ? <Hotkeys keyName={window.keybinds.toggleQuicklinks} onKeyDown={this.toggleAdd} /> : null}
|
||||
{variables.keybinds.toggleQuicklinks && variables.keybinds.toggleQuicklinks !== '' ? <Hotkeys keyName={variables.keybinds.toggleQuicklinks} onKeyDown={this.toggleAdd} /> : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -146,7 +146,7 @@ export default class Quote extends PureComponent {
|
||||
// First we try and get a quote from the API...
|
||||
try {
|
||||
const quotelanguage = localStorage.getItem('quotelanguage');
|
||||
const data = await (await fetch(window.constants.API_URL + '/quotes/random?language=' + quotelanguage)).json();
|
||||
const data = await (await fetch(variables.constants.API_URL + '/quotes/random?language=' + quotelanguage)).json();
|
||||
|
||||
// If we hit the ratelimit, we fallback to local quotes
|
||||
if (data.statusCode === 429) {
|
||||
@@ -173,13 +173,13 @@ export default class Quote extends PureComponent {
|
||||
}
|
||||
|
||||
copyQuote() {
|
||||
window.stats.postEvent('feature', 'Quote copied');
|
||||
variables.stats.postEvent('feature', 'Quote copied');
|
||||
navigator.clipboard.writeText(`${this.state.quote} - ${this.state.author}`);
|
||||
toast(variables.language.getMessage(variables.languagecode, 'toasts.quote'));
|
||||
}
|
||||
|
||||
tweetQuote() {
|
||||
window.stats.postEvent('feature', 'Quote tweet');
|
||||
variables.stats.postEvent('feature', 'Quote tweet');
|
||||
window.open(`https://twitter.com/intent/tweet?text=${this.state.quote} - ${this.state.author} on @getmue`, '_blank').focus();
|
||||
}
|
||||
|
||||
@@ -196,7 +196,7 @@ export default class Quote extends PureComponent {
|
||||
});
|
||||
}
|
||||
|
||||
window.stats.postEvent('feature', 'Quote favourite');
|
||||
variables.stats.postEvent('feature', 'Quote favourite');
|
||||
}
|
||||
|
||||
init() {
|
||||
@@ -277,9 +277,9 @@ export default class Quote extends PureComponent {
|
||||
<br/>
|
||||
{this.state.copy} {this.state.tweet} {this.state.favourited}
|
||||
</h1>
|
||||
{window.keybinds.favouriteQuote && window.keybinds.favouriteQuote !== '' ? <Hotkeys keyName={window.keybinds.favouriteQuote} onKeyDown={() => this.favourite()} /> : null}
|
||||
{window.keybinds.tweetQuote && window.keybinds.tweetQuote !== '' ? <Hotkeys keyName={window.keybinds.tweetQuote} onKeyDown={() => this.tweetQuote()} /> : null}
|
||||
{window.keybinds.copyQuote && window.keybinds.copyQuote !== '' ? <Hotkeys keyName={window.keybinds.copyQuote} onKeyDown={() => this.copyQuote()} /> : null}
|
||||
{variables.keybinds.favouriteQuote && variables.keybinds.favouriteQuote !== '' ? <Hotkeys keyName={variables.keybinds.favouriteQuote} onKeyDown={() => this.favourite()} /> : null}
|
||||
{variables.keybinds.tweetQuote && variables.keybinds.tweetQuote !== '' ? <Hotkeys keyName={variables.keybinds.tweetQuote} onKeyDown={() => this.tweetQuote()} /> : null}
|
||||
{variables.keybinds.copyQuote && variables.keybinds.copyQuote !== '' ? <Hotkeys keyName={variables.keybinds.copyQuote} onKeyDown={() => this.copyQuote()} /> : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ export default class Search extends PureComponent {
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
window.stats.postEvent('feature', 'Voice search');
|
||||
variables.stats.postEvent('feature', 'Voice search');
|
||||
window.location.href = this.state.url + `?${this.state.query}=` + searchText.value;
|
||||
}, 1000);
|
||||
};
|
||||
@@ -52,7 +52,7 @@ export default class Search extends PureComponent {
|
||||
searchButton = (e) => {
|
||||
e.preventDefault();
|
||||
const value = e.target.value || document.getElementById('searchtext').value || 'mue fast';
|
||||
window.stats.postEvent('feature', 'Search');
|
||||
variables.stats.postEvent('feature', 'Search');
|
||||
window.location.href = this.state.url + `?${this.state.query}=` + value;
|
||||
}
|
||||
|
||||
@@ -195,7 +195,7 @@ export default class Search extends PureComponent {
|
||||
{this.state.microphone}
|
||||
<SearchIcon onClick={this.searchButton}/>
|
||||
<AutocompleteInput placeholder={variables.language.getMessage(variables.languagecode, 'widgets.search')} id='searchtext' suggestions={this.state.suggestions} onChange={(e) => this.getSuggestions(e)} onClick={this.searchButton}/>
|
||||
{window.keybinds.focusSearch && window.keybinds.focusSearch !== '' ? <Hotkeys keyName={window.keybinds.focusSearch} onKeyDown={() => document.getElementById('searchtext').focus()}/> : null}
|
||||
{variables.keybinds.focusSearch && variables.keybinds.focusSearch !== '' ? <Hotkeys keyName={variables.keybinds.focusSearch} onKeyDown={() => document.getElementById('searchtext').focus()}/> : null}
|
||||
</form>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -112,7 +112,6 @@ export default class DateWidget extends PureComponent {
|
||||
componentDidMount() {
|
||||
EventBus.on('refresh', (data) => {
|
||||
if (data === 'date' || data === 'timezone') {
|
||||
|
||||
if (localStorage.getItem('date') === 'false') {
|
||||
return this.date.current.style.display = 'none';
|
||||
}
|
||||
@@ -124,7 +123,6 @@ export default class DateWidget extends PureComponent {
|
||||
});
|
||||
|
||||
this.date.current.style.fontSize = `${Number((localStorage.getItem('zoomDate') || 100) / 100)}em`;
|
||||
|
||||
this.getDate();
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ export default class Weather extends PureComponent {
|
||||
};
|
||||
|
||||
if (!this.state.weather.temp) {
|
||||
data = await (await fetch(window.constants.PROXY_URL + `/weather/current?city=${this.state.location}&lang=${variables.languagecode}`)).json();
|
||||
data = await (await fetch(variables.constants.PROXY_URL + `/weather/current?city=${this.state.location}&lang=${variables.languagecode}`)).json();
|
||||
}
|
||||
|
||||
if (data.cod === '404') {
|
||||
|
||||
Reference in New Issue
Block a user