import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { Button, Dropdown, DropdownType, IconButton, isDark, Size, Type } from '@dash/components'; import { action, computed, makeObservable, observable, reaction } from 'mobx'; import { observer } from 'mobx-react'; import * as React from 'react'; import { FaBug } from 'react-icons/fa'; import { ClientUtils, returnEmptyFilter, returnFalse, returnTrue } from '../../../ClientUtils'; import { Doc, DocListCast, returnEmptyDoclist } from '../../../fields/Doc'; import { AclAdmin, DashVersion } from '../../../fields/DocSymbols'; import { StrCast } from '../../../fields/Types'; import { GetEffectiveAcl } from '../../../fields/util'; import { emptyFunction } from '../../../Utils'; import { dropActionType } from '../../util/DropActionTypes'; import { PingManager } from '../../util/PingManager'; import { ReportManager } from '../../util/reportManager/ReportManager'; import { ServerStats } from '../../util/ServerStats'; import { SettingsManager } from '../../util/SettingsManager'; import { SharingManager } from '../../util/SharingManager'; import { SnappingManager } from '../../util/SnappingManager'; import { Transform } from '../../util/Transform'; import { CollectionDockingView } from '../collections/CollectionDockingView'; import { CollectionLinearView } from '../collections/collectionLinear'; import { DashboardView } from '../DashboardView'; import { Colors } from '../global/globalEnums'; import { DocumentView, DocumentViewInternal } from '../nodes/DocumentView'; import { ObservableReactComponent } from '../ObservableReactComponent'; import { DefaultStyleProvider, returnEmptyDocViewList } from '../StyleProvider'; import './TopBar.scss'; import { OpenWhere } from '../nodes/OpenWhere'; import { Docs } from '../../documents/Documents'; /** * ABOUT: This is the topbar in Dash, which included the current Dashboard as well as access to information on the user * and settings and help buttons. Future scope for this bar is to include the collaborators that are on the same Dashboard. */ @observer export class TopBar extends ObservableReactComponent { // eslint-disable-next-line no-use-before-define static Instance: TopBar; @observable private _flipDocumentation = 0; constructor(props: object) { super(props); makeObservable(this); TopBar.Instance = this; } navigateToHome = () => { (CollectionDockingView.Instance?.CaptureThumbnail() ?? new Promise(res => { res(); })) .then(() => { Doc.ActivePage = 'home'; DashboardView.closeActiveDashboard(); // bcz: if we do this, we need some other way to keep track, for user convenience, of the last dashboard in use }); // prettier-ignore }; @computed get color() { return SettingsManager.userColor; } @computed get variantColor() { return SettingsManager.userVariantColor; } @computed get backgroundColor() { return SettingsManager.userBackgroundColor; } @observable happyHeart: boolean = PingManager.Instance.IsBeating; setHappyHeart = action((status: boolean) => { this.happyHeart = status; }); dispose = reaction( () => PingManager.Instance.IsBeating, isBeating => this.setHappyHeart(isBeating) ); /** * Returns the left hand side of the topbar. * This side of the topbar contains the different modes. * The modes include: * - Explore mode * - Tracking mode */ @computed get topbarLeft() { return (
{Doc.ActiveDashboard ? ( !DocListCast(Doc.MySharedDocs?.viewed)?.includes(dash)) ? 'portrait' : 'home'} />} color={this.color} background={this.backgroundColor} /> ) : (
dash logo brown dash
)} {Doc.ActiveDashboard && (
); } @computed get dashMenuButtons() { const selDoc = Doc.MyTopBarBtns; return !(selDoc instanceof Doc) ? null : (
200} PanelHeight={() => 30} renderDepth={0} focus={emptyFunction} whenChildContentsActiveChanged={emptyFunction} childFilters={returnEmptyFilter} childFiltersByRanges={returnEmptyFilter} searchFilterDocs={returnEmptyDoclist} />
); } /** * Returns the center of the topbar * This part of the topbar contains everything related to the current dashboard including: * - Selection of dashboards * - Creating a new dashboard * - Taking a snapshot of a dashboard */ @computed get topbarCenter() { // const dashboardItems = myDashboards.map(board => { // const boardTitle = StrCast(board.title); // console.log(boardTitle); // return { // text: boardTitle, // onClick: () => DashboardView.openDashboard(board), // val: board, // }; // }); return Doc.ActiveDashboard ? (
) : null; } /** * Returns the right hand side of the topbar. * This part of the topbar includes information about the current user, * and allows the user to access their account settings etc. */ @computed get topbarRight() { const upToDate = DashVersion === SnappingManager.ServerVersion; return (
{Doc.ActiveDashboard ? (
); } /** * Make the documentation icon flip around to draw attention to it. */ FlipDocumentationIcon = action(() => { this._flipDocumentation += 1; }); render() { return ( // TODO:glr Add support for light / dark mode
{this.topbarLeft} {this.topbarCenter} {this.topbarRight}
); } }