import * as queryString from 'query-string'; import {Dropdown, Icon, Menu} from 'semantic-ui-react'; import {FormattedMessage} from 'react-intl'; import {IndiInfo, JsonGedcomData} from 'topola'; import {Link} from 'react-router-dom'; import {Media} from '../util/media'; import {MenuType} from './menu_item'; import {SearchBar} from './search'; import {UploadMenu} from './upload_menu'; import {UrlMenu} from './url_menu'; import {useHistory, useLocation} from 'react-router'; import {WikiTreeLoginMenu, WikiTreeMenu} from './wikitree_menu'; enum ScreenSize { LARGE, SMALL, } interface EventHandlers { onSelection: (indiInfo: IndiInfo) => void; onPrint: () => void; onDownloadPdf: () => void; onDownloadPng: () => void; onDownloadSvg: () => void; } interface Props { /** True if the application is currently showing a chart. */ showingChart: boolean; /** Data used for the search index. */ data?: JsonGedcomData; standalone: boolean; /** Whether to show the "All relatives" chart type in the menu. */ allowAllRelativesChart: boolean; eventHandlers: EventHandlers; /** Whether to show additional WikiTree menus. */ showWikiTreeMenus: boolean; } export function TopBar(props: Props) { const history = useHistory(); const location = useLocation(); function changeView(view: string) { const search = queryString.parse(location.search); if (search.view !== view) { search.view = view; location.search = queryString.stringify(search); history.push(location); } } function chartMenus(screenSize: ScreenSize) { if (!props.showingChart) { return null; } const chartTypeItems = ( <> changeView('hourglass')}> {props.allowAllRelativesChart ? ( changeView('relatives')}> ) : null} changeView('fancy')}> ); switch (screenSize) { case ScreenSize.LARGE: return ( <> } className="item" > } className="item" > {chartTypeItems} ); case ScreenSize.SMALL: return ( <> {chartTypeItems} ); } } function title() { return ( Topola Genealogy ); } function fileMenus(screenSize: ScreenSize) { // In standalone WikiTree mode, show only the "Select WikiTree ID" menu. if (!props.standalone && props.showWikiTreeMenus) { switch (screenSize) { case ScreenSize.LARGE: return ; case ScreenSize.SMALL: return ( <> ); } } // Don't show "open" menus in non-standalone mode. if (!props.standalone) { return null; } switch (screenSize) { case ScreenSize.LARGE: // Show dropdown if chart is shown, otherwise show individual menu // items. const menus = props.showingChart ? ( } className="item" > ) : ( <> ); return menus; case ScreenSize.SMALL: return ( <> ); } } function wikiTreeLoginMenu(screenSize: ScreenSize) { if (!props.showWikiTreeMenus) { return null; } return ( <> {screenSize === ScreenSize.SMALL ? : null} ); } function mobileMenus() { return ( <> } className="item" icon={null} > {fileMenus(ScreenSize.SMALL)} {chartMenus(ScreenSize.SMALL)} {wikiTreeLoginMenu(ScreenSize.SMALL)} {props.standalone ? {title()} : title()} ); } function desktopMenus() { return ( <> {props.standalone ? {title()} : null} {fileMenus(ScreenSize.LARGE)} {chartMenus(ScreenSize.LARGE)} {wikiTreeLoginMenu(ScreenSize.LARGE)} ); } return ( <> {desktopMenus()} {mobileMenus()} ); }