mue/src/components/widgets/navbar/Navbar.jsx

118 lines
3.7 KiB
React
Raw Normal View History

import variables from 'modules/variables';
2021-08-27 22:08:32 +00:00
import { PureComponent, createRef } from 'react';
import { MdRefresh, MdSettings } from 'react-icons/md';
2021-01-16 18:39:03 +00:00
import Notes from './Notes';
import Todo from './Todo';
import Maximise from '../background/Maximise';
2021-08-28 14:34:12 +00:00
import Tooltip from 'components/helpers/tooltip/Tooltip';
2020-11-29 14:32:08 +00:00
2021-08-28 14:34:12 +00:00
import EventBus from 'modules/helpers/eventbus';
import './scss/index.scss';
2019-11-06 19:03:17 +00:00
2021-08-14 19:10:48 +00:00
export default class Navbar extends PureComponent {
2021-08-27 22:08:32 +00:00
constructor() {
super();
this.navbarContainer = createRef();
this.refreshEnabled = localStorage.getItem('refresh');
this.refreshValue = localStorage.getItem('refreshOption');
this.state = {
classList: localStorage.getItem('widgetStyle') === 'legacy' ? 'navbar old' : 'navbar new',
};
2021-08-27 22:08:32 +00:00
}
2021-08-16 13:36:34 +00:00
setZoom() {
const zoomNavbar = Number((localStorage.getItem('zoomNavbar') || 100) / 100);
2021-08-27 22:08:32 +00:00
this.navbarContainer.current.style.fontSize = `${zoomNavbar}em`;
2021-08-16 13:36:34 +00:00
}
componentDidMount() {
EventBus.on('refresh', (data) => {
if (data === 'navbar' || data === 'background') {
this.refreshEnabled = localStorage.getItem('refresh');
this.refreshValue = localStorage.getItem('refreshOption');
this.forceUpdate();
2021-08-16 13:36:34 +00:00
this.setZoom();
}
});
2021-08-16 13:36:34 +00:00
this.setZoom();
}
2021-08-28 17:56:59 +00:00
refresh() {
switch (this.refreshValue) {
2021-08-28 17:56:59 +00:00
case 'background':
EventBus.dispatch('refresh', 'backgroundrefresh');
break;
case 'quote':
EventBus.dispatch('refresh', 'quoterefresh');
break;
case 'quotebackground':
EventBus.dispatch('refresh', 'quoterefresh');
EventBus.dispatch('refresh', 'backgroundrefresh');
break;
default:
window.location.reload();
}
}
render() {
const backgroundEnabled = localStorage.getItem('background') === 'true';
const navbar = (
<div className="navbar-container" ref={this.navbarContainer}>
<div className={this.state.classList}>
{localStorage.getItem('view') === 'true' && backgroundEnabled ? <Maximise /> : null}
{localStorage.getItem('notesEnabled') === 'true' ? <Notes /> : null}
{localStorage.getItem('todo') === 'true' ? <Todo /> : null}
{this.refreshEnabled !== 'false' ? (
<Tooltip
title={variables.language.getMessage(
variables.languagecode,
'widgets.navbar.tooltips.refresh',
)}
>
<button onClick={() => this.refresh()}>
<MdRefresh className="refreshicon topicons" />
</button>
</Tooltip>
) : null}
2022-04-08 21:05:14 +00:00
{/*<InfoTooltip
title="You can now sync your settings"
subtitle={'All settings, such as theme can now be synced across clients'}
linkURL={'https://www.youtube.com/watch?v=dQw4w9WgXcQ'}
linkText={'Learn more'}
2022-04-08 21:05:14 +00:00
>
</InfoTooltip>*/}
<Tooltip
title={variables.language.getMessage(
variables.languagecode,
'modals.main.navbar.settings',
)}
>
<button onClick={() => this.props.openModal('mainModal')}>
<MdSettings className="settings-icon topicons" />
</button>
</Tooltip>
</div>
{/*<div className="notification">
<span className="title">New Update</span>
<span className="subtitle">
The newest update includes a lot of cheese plus urmm donate to david ralph on github.
</span>
<button>Learn More</button>
</div>*/}
</div>
);
return localStorage.getItem('navbarHover') === 'true' ? (
<div className="navbar-hover">{navbar}</div>
) : (
navbar
);
}
}