2021-09-10 15:38:53 +00:00
|
|
|
import variables from 'modules/variables';
|
2021-08-14 19:10:48 +00:00
|
|
|
import { PureComponent } from 'react';
|
2022-04-07 09:25:01 +00:00
|
|
|
import { MdStar, MdStarBorder } from 'react-icons/md';
|
2021-11-17 21:50:34 +00:00
|
|
|
//import Hotkeys from 'react-hot-keys';
|
2021-01-17 18:07:26 +00:00
|
|
|
|
2021-08-14 19:10:48 +00:00
|
|
|
export default class Favourite extends PureComponent {
|
2021-07-12 10:34:05 +00:00
|
|
|
buttons = {
|
2022-04-08 13:48:36 +00:00
|
|
|
favourited: <MdStar onClick={() => this.favourite()} className="topicons" />,
|
|
|
|
unfavourited: <MdStarBorder onClick={() => this.favourite()} className="topicons" />,
|
|
|
|
};
|
2021-07-12 10:34:05 +00:00
|
|
|
|
2021-03-23 13:10:34 +00:00
|
|
|
constructor() {
|
|
|
|
super();
|
2021-03-17 13:01:53 +00:00
|
|
|
this.state = {
|
2022-04-08 13:48:36 +00:00
|
|
|
favourited: localStorage.getItem('favourite')
|
|
|
|
? this.buttons.favourited
|
|
|
|
: this.buttons.unfavourited,
|
2021-03-17 13:01:53 +00:00
|
|
|
};
|
|
|
|
}
|
2020-09-16 11:32:09 +00:00
|
|
|
|
2021-07-12 20:48:08 +00:00
|
|
|
favourite() {
|
2021-03-17 13:01:53 +00:00
|
|
|
if (localStorage.getItem('favourite')) {
|
|
|
|
localStorage.removeItem('favourite');
|
|
|
|
this.setState({
|
2022-04-08 13:48:36 +00:00
|
|
|
favourited: this.buttons.unfavourited,
|
2021-03-17 13:01:53 +00:00
|
|
|
});
|
2021-09-28 22:04:04 +00:00
|
|
|
variables.stats.postEvent('feature', 'Background favourite');
|
2021-03-17 13:01:53 +00:00
|
|
|
} else {
|
2021-11-11 20:43:33 +00:00
|
|
|
const type = localStorage.getItem('backgroundType');
|
2022-04-16 18:25:42 +00:00
|
|
|
|
2021-11-11 20:43:33 +00:00
|
|
|
switch (type) {
|
|
|
|
case 'colour':
|
|
|
|
return;
|
|
|
|
case 'random_colour':
|
|
|
|
case 'random_gradient':
|
2022-04-08 13:48:36 +00:00
|
|
|
localStorage.setItem(
|
|
|
|
'favourite',
|
|
|
|
JSON.stringify({
|
|
|
|
type: localStorage.getItem('backgroundType'),
|
|
|
|
url: document.getElementById('backgroundImage').style.background,
|
|
|
|
}),
|
|
|
|
);
|
2021-11-11 20:43:33 +00:00
|
|
|
break;
|
|
|
|
default:
|
2022-04-08 13:48:36 +00:00
|
|
|
const url = document
|
|
|
|
.getElementById('backgroundImage')
|
|
|
|
.style.backgroundImage.replace('url("', '')
|
|
|
|
.replace('")', '')
|
|
|
|
.replace(variables.constants.DDG_IMAGE_PROXY, '');
|
2021-03-17 13:01:53 +00:00
|
|
|
|
2021-11-11 20:43:33 +00:00
|
|
|
if (!url) {
|
|
|
|
return;
|
|
|
|
}
|
2021-08-20 10:52:05 +00:00
|
|
|
|
2021-11-11 20:43:33 +00:00
|
|
|
if (type === 'custom') {
|
2022-04-08 13:48:36 +00:00
|
|
|
localStorage.setItem(
|
|
|
|
'favourite',
|
|
|
|
JSON.stringify({
|
|
|
|
type,
|
|
|
|
url,
|
|
|
|
}),
|
|
|
|
);
|
2021-11-11 20:43:33 +00:00
|
|
|
} else {
|
|
|
|
// photo information now hides information if it isn't sent, unless if photoinformation hover is hidden
|
|
|
|
const location = document.getElementById('infoLocation');
|
|
|
|
const camera = document.getElementById('infoCamera');
|
2022-04-08 13:48:36 +00:00
|
|
|
|
|
|
|
localStorage.setItem(
|
|
|
|
'favourite',
|
|
|
|
JSON.stringify({
|
|
|
|
type,
|
|
|
|
url,
|
|
|
|
credit: document.getElementById('credit').textContent || '',
|
|
|
|
location: location ? location.innerText : 'N/A',
|
|
|
|
camera: camera ? camera.innerText : 'N/A',
|
|
|
|
resolution: document.getElementById('infoResolution').textContent || '',
|
|
|
|
}),
|
|
|
|
);
|
2021-11-11 20:43:33 +00:00
|
|
|
}
|
|
|
|
}
|
2021-03-17 13:01:53 +00:00
|
|
|
|
|
|
|
this.setState({
|
2022-04-08 13:48:36 +00:00
|
|
|
favourited: this.buttons.favourited,
|
2021-03-17 13:01:53 +00:00
|
|
|
});
|
2021-09-28 22:04:04 +00:00
|
|
|
variables.stats.postEvent('feature', 'Background unfavourite');
|
2021-03-17 13:01:53 +00:00
|
|
|
}
|
2020-09-16 11:32:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2022-04-16 18:25:42 +00:00
|
|
|
if (localStorage.getItem('backgroundType') === 'colour') {
|
2021-01-16 22:43:46 +00:00
|
|
|
return null;
|
|
|
|
}
|
2021-03-17 13:01:53 +00:00
|
|
|
|
2021-08-25 12:28:41 +00:00
|
|
|
return (
|
2022-04-08 13:48:36 +00:00
|
|
|
<>
|
2021-08-25 12:28:41 +00:00
|
|
|
{this.state.favourited}
|
2021-11-17 21:50:34 +00:00
|
|
|
{/*variables.keybinds.favouriteBackground && variables.keybinds.favouriteBackground !== '' ? <Hotkeys keyName={variables.keybinds.favouriteBackground} onKeyDown={() => this.favourite()} /> : null*/}
|
2022-04-08 13:48:36 +00:00
|
|
|
</>
|
2021-08-25 12:28:41 +00:00
|
|
|
);
|
2020-09-16 11:32:09 +00:00
|
|
|
}
|
2021-03-17 13:01:53 +00:00
|
|
|
}
|