aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/topbar/TopBar.tsx
blob: be248ab9294496a536cf8b8208530892a526b682 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { Tooltip } from "@material-ui/core";
import { action } from "mobx";
import { observer } from "mobx-react";
import * as React from 'react';
import { Doc, DocListCast } from '../../../fields/Doc';
import { Id } from '../../../fields/FieldSymbols';
import { StrCast } from '../../../fields/Types';
import { Utils } from '../../../Utils';
import { CurrentUserUtils } from "../../util/CurrentUserUtils";
import { SettingsManager } from "../../util/SettingsManager";
import { undoBatch, UndoManager } from "../../util/UndoManager";
import { Borders, Colors } from "../global/globalEnums";
import { MainView } from "../MainView";
import "./TopBar.scss";

/**
 * 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 React.Component {
    render() {
        const myDashboards = DocListCast(CurrentUserUtils.MyDashboards.data);
        return (
            //TODO:glr Add support for light / dark mode
            <div style={{ pointerEvents: "all" }} className="topbar-container">
                <div className="topbar-bar" style={{ background: Colors.DARK_GRAY, borderBottom: Borders.STANDARD }}>
                    <div className="topbar-left">
                        <div className="topbar-lozenge-user">
                            {`${Doc.CurrentUserEmail}`}
                        </div>
                        <div className="topbar-icon" onClick={() => window.location.assign(Utils.prepend("/logout"))}>
                            {"Log out"}
                        </div>
                    </div>
                    <div className="topbar-center" >
                        <div className="topbar-lozenge-dashboard">
                            <select className="topbar-dashSelect" onChange={undoBatch(e => CurrentUserUtils.openDashboard(Doc.UserDoc(), myDashboards[Number(e.target.value)]))}
                                value={myDashboards.indexOf(CurrentUserUtils.ActiveDashboard)}
                                style={{ color: Colors.WHITE }}>
                                {myDashboards.map((dash, i) => <option key={dash[Id]} value={i}> {StrCast(dash.title)} </option>)}
                            </select>
                        </div>
                        <div className="topbar-dashboards">
                            <Tooltip title={<div className="dash-tooltip">Create a new dashboard </div>} placement="bottom"><div className="topbar-icon" onClick={async () => {
                                const batch = UndoManager.StartBatch("new dash");
                                await CurrentUserUtils.createNewDashboard(Doc.UserDoc());
                                batch.end();
                            }}>
                                {"New"}<FontAwesomeIcon icon="plus" />
                            </div>
                            </Tooltip>
                            <Tooltip title={<div className="dash-tooltip">Work on a copy of the dashboard layout</div>} placement="bottom">
                                <div className="topbar-icon" onClick={async () => {
                                    const batch = UndoManager.StartBatch("snapshot");
                                    await CurrentUserUtils.snapshotDashboard(Doc.UserDoc());
                                    batch.end();
                                }}>
                                    {"Snapshot"}<FontAwesomeIcon icon="camera" />
                                </div>
                            </Tooltip>
                            <Tooltip title={<div className="dash-tooltip">Browsing mode for directly navigating to documents</div>} placement="bottom">
                                <div className="topbar-icon" style={{ background: MainView.Instance._exploreMode ? Colors.LIGHT_BLUE : undefined }} onClick={action(() => MainView.Instance._exploreMode = !MainView.Instance._exploreMode)}>
                                    {"Explore"}<FontAwesomeIcon icon="map" />
                                </div>
                            </Tooltip>
                        </div>
                    </div>
                    <div className="topbar-right" >
                        <div className="topbar-icon" onClick={() => window.open(
                            "https://brown-dash.github.io/Dash-Documentation/", "_blank")}>
                            {"Help"}<FontAwesomeIcon icon="question-circle" />
                        </div>
                        <div className="topbar-icon" onClick={() => SettingsManager.Instance.open()}>
                            {"Settings"}<FontAwesomeIcon icon="cog" />
                        </div>
                    </div>
                </div>
            </div >
        );
    }
}