// TODO: make it work with pins or on click or smth import variables from 'config/variables'; import { PureComponent, memo, useState } from 'react'; import { MdPlaylistRemove, MdOutlineApps } from 'react-icons/md'; import { Tooltip } from 'components/Elements'; import { shift, useFloating } from '@floating-ui/react-dom'; import EventBus from 'utils/eventbus'; class Apps extends PureComponent { constructor() { super(); this.state = { apps: JSON.parse(localStorage.getItem('applinks')), visibility: localStorage.getItem('appsPinned') === 'true' ? 'visible' : 'hidden', marginLeft: localStorage.getItem('refresh') === 'false' ? '-200px' : '-130px', showApps: localStorage.getItem('appsPinned') === 'true', }; } setZoom() { this.setState({ zoomFontSize: Number(((localStorage.getItem('zoomNavbar') || 100) / 100) * 1.2) + 'rem', }); } componentDidMount() { EventBus.on('refresh', (data) => { if (data === 'navbar') { this.forceUpdate(); try { this.setZoom(); } catch { // Ignore errors } } }); this.setZoom(); } componentWillUnmount() { EventBus.off('refresh'); } showApps() { this.setState({ showApps: true }); } hideApps() { this.setState({ showApps: localStorage.getItem('AppsPinned') === 'true' }); } render() { const appsInfo = this.state.apps; return (
this.hideApps()} onFocus={() => this.showApps()}> {this.state.showApps && (
{variables.getMessage('widgets.navbar.apps.title')}
{appsInfo.length > 0 ? (
{appsInfo.map((info, i) => ( Google {info.name} ))}
) : (
{variables.language.getMessage( variables.languagecode, 'widgets.navbar.apps.no_apps', )}
)}
)}
); } } function AppsWrapper() { const [reference, setReference] = useState(null); const { x, y, refs, strategy } = useFloating({ placement: 'bottom', middleware: [shift()], elements: { reference }, }); return ( ); } const MemoizedAppsWrapper = memo(AppsWrapper); export { MemoizedAppsWrapper as default, MemoizedAppsWrapper as Apps };