import './navbar.less'; import React from 'react'; import { Dropdown } from '@components/dropdown/dropdown.jsx'; import NewBrew from './newbrew.navitem'; import PrintNavitem from './print.navitem.jsx'; import ShareNavitem from './share.navitem.jsx'; import HelpNavitem from './help.navitem.jsx'; import RecentNavItems from './recent.navitem.jsx'; import Account from './account.navitem.jsx'; const { both: RecentNavItem } = RecentNavItems; import Nav from './nav.jsx'; const Navbar = ({ children, brew, title = '', props }) => { const version = global.version || '0.0.0'; const isMac = navigator.platform.toUpperCase().includes('MAC'); const mod = isMac ? '⌘' : 'Ctrl'; const isBrew = !!brew && brew.shareId; const account = global.account; const slots = React.Children.toArray(children).reduce((acc, child) => { if (React.isValidElement(child)) { if (child.type === Navbar.File) acc.file = child; if (child.type === Navbar.Edit) acc.edit = child; if (child.type === Navbar.Go) acc.go = child; } return acc; }, {}); const renderTitle = () => { const cleanTitle = title.replace(/^\/+|\/+$/g, ''); if (!isBrew) return {cleanTitle || 'Home'}; return ( {brew.title} ); }; const renderDownloadLink = () => { if (!isBrew) return Get txt; let shareLink = brew.shareId; if (brew.googleId && !brew.stubbed) { shareLink = brew.googleId + shareLink; } return ( Get txt ); }; const renderFile = () => { return ( File>} icon={null} key={'file'}> Save document {renderDownloadLink()} Delete File Publish File Transfer File {slots.file?.props.children} ); }; const renderEdit = () => { return ( Edit>} icon={null} key={'edit'}> {slots.edit} Undo Redo cut copy paste Find / Replace ); }; const renderGo = () => { return ( Go>} icon={null} key={'go'}> Patreon Vault Changelog Recent Brews>} icon={null} key={'recent'}> ); }; return ( Home {renderFile()} {renderEdit()} {renderGo()} Help>} icon={null} key={'help'}> {renderTitle()} {account.username}>} icon={null} key={account.username}> ); }; Navbar.File = () => null; Navbar.Edit = () => null; Navbar.Go = () => null; export default Navbar;