From f885965824f76be69e6bd26109a5df85dc43eb80 Mon Sep 17 00:00:00 2001 From: bobzel Date: Wed, 26 Apr 2023 13:11:58 -0400 Subject: added stats button to mainview --- src/client/util/ServerStats.tsx | 55 ++++++++++++++++++++++++++++++++++++++ src/client/util/SharingManager.tsx | 9 +++---- src/client/views/MainView.tsx | 2 ++ src/client/views/topbar/TopBar.tsx | 14 +++++----- 4 files changed, 68 insertions(+), 12 deletions(-) create mode 100644 src/client/util/ServerStats.tsx (limited to 'src') diff --git a/src/client/util/ServerStats.tsx b/src/client/util/ServerStats.tsx new file mode 100644 index 000000000..0ab411bff --- /dev/null +++ b/src/client/util/ServerStats.tsx @@ -0,0 +1,55 @@ +import { action, computed, observable, runInAction } from 'mobx'; +import { observer } from 'mobx-react'; +import * as React from 'react'; +import { MainViewModal } from '../views/MainViewModal'; +import { DocumentView } from '../views/nodes/DocumentView'; +import './SharingManager.scss'; + +@observer +export class ServerStats extends React.Component<{}> { + public static Instance: ServerStats; + @observable private isOpen = false; // whether the SharingManager modal is open or not + + // private get linkVisible() { + // return this.targetDoc ? this.targetDoc["acl-" + PublicKey] !== SharingPermissions.None : false; + // } + + @action + public open = async () => { + /** + * Populates the list of users. + */ + fetch('/stats').then((res: Response) => res.text().then(action(stats => (this._stats = JSON.parse(stats))))); + + this.isOpen = true; + }; + + public close = action(() => { + this.isOpen = false; + }); + + constructor(props: {}) { + super(props); + ServerStats.Instance = this; + } + + @observable _stats: { [key: string]: any } | undefined; + + /** + * @returns the main interface of the SharingManager. + */ + @computed get sharingInterface() { + return ( +
+ Active users:{this._stats?.socketMap.length} + {this._stats?.socketMap.map((user: any) => ( +

{user.username}

+ ))} +
+ ); + } + + render() { + return ; + } +} diff --git a/src/client/util/SharingManager.tsx b/src/client/util/SharingManager.tsx index a73eda04c..4937866f8 100644 --- a/src/client/util/SharingManager.tsx +++ b/src/client/util/SharingManager.tsx @@ -5,14 +5,13 @@ import { observer } from 'mobx-react'; import * as React from 'react'; import Select from 'react-select'; import * as RequestPromise from 'request-promise'; -import { AclAdmin, AclPrivate, AclSym, AclUnset, DataSym, Doc, DocListCast, DocListCastAsync, HierarchyMapping, Opt } from '../../fields/Doc'; +import { AclAdmin, AclPrivate, AclSym, AclUnset, DataSym, Doc, DocListCast, DocListCastAsync, HierarchyMapping } from '../../fields/Doc'; import { Id } from '../../fields/FieldSymbols'; import { List } from '../../fields/List'; -import { Cast, NumCast, PromiseValue, StrCast } from '../../fields/Types'; +import { NumCast, StrCast } from '../../fields/Types'; import { distributeAcls, GetEffectiveAcl, normalizeEmail, SharingPermissions, TraceMobx } from '../../fields/util'; import { Utils } from '../../Utils'; import { DocServer } from '../DocServer'; -import { CollectionView } from '../views/collections/CollectionView'; import { DictationOverlay } from '../views/DictationOverlay'; import { MainViewModal } from '../views/MainViewModal'; import { DocumentView } from '../views/nodes/DocumentView'; @@ -21,7 +20,6 @@ import { SearchBox } from '../views/search/SearchBox'; import { DocumentManager } from './DocumentManager'; import { GroupManager, UserOptions } from './GroupManager'; import { GroupMemberView } from './GroupMemberView'; -import { LinkManager } from './LinkManager'; import { SelectionManager } from './SelectionManager'; import './SharingManager.scss'; @@ -581,9 +579,8 @@ export class SharingManager extends React.Component<{}> { ); }); - return ( -
+
{GroupManager.Instance?.currentGroup ? (GroupManager.Instance.currentGroup = undefined))} /> : null}

diff --git a/src/client/views/MainView.tsx b/src/client/views/MainView.tsx index e4554c339..43f56dd8c 100644 --- a/src/client/views/MainView.tsx +++ b/src/client/views/MainView.tsx @@ -26,6 +26,7 @@ import { ScriptingGlobals } from '../util/ScriptingGlobals'; import { SelectionManager } from '../util/SelectionManager'; import { ColorScheme, SettingsManager } from '../util/SettingsManager'; import { SharingManager } from '../util/SharingManager'; +import { ServerStats } from '../util/ServerStats'; import { SnappingManager } from '../util/SnappingManager'; import { Transform } from '../util/Transform'; import { TimelineMenu } from './animationtimeline/TimelineMenu'; @@ -969,6 +970,7 @@ export class MainView extends React.Component { {this.inkResources} + diff --git a/src/client/views/topbar/TopBar.tsx b/src/client/views/topbar/TopBar.tsx index d63c25dbe..9bd2ba5ce 100644 --- a/src/client/views/topbar/TopBar.tsx +++ b/src/client/views/topbar/TopBar.tsx @@ -1,21 +1,22 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; -import { Button, FontSize, IconButton, Size } from 'browndash-components'; +import { Button, IconButton, Size } from 'browndash-components'; import { action, computed, observable } from 'mobx'; import { observer } from 'mobx-react'; import * as React from 'react'; -import { FaBug, FaCamera } from 'react-icons/fa'; -import { AclAdmin, Doc, DocListCast } from '../../../fields/Doc'; +import { FaBug, FaCamera, FaStamp } from 'react-icons/fa'; +import { AclAdmin, Doc } from '../../../fields/Doc'; import { StrCast } from '../../../fields/Types'; import { GetEffectiveAcl } from '../../../fields/util'; import { DocumentManager } from '../../util/DocumentManager'; import { ReportManager } from '../../util/ReportManager'; +import { ServerStats } from '../../util/ServerStats'; import { SettingsManager } from '../../util/SettingsManager'; import { SharingManager } from '../../util/SharingManager'; import { UndoManager } from '../../util/UndoManager'; import { CollectionDockingView } from '../collections/CollectionDockingView'; import { ContextMenu } from '../ContextMenu'; import { DashboardView } from '../DashboardView'; -import { Borders, Colors } from '../global/globalEnums'; +import { Colors } from '../global/globalEnums'; import { MainView } from '../MainView'; import './TopBar.scss'; @@ -132,9 +133,10 @@ export class TopBar extends React.Component { @computed get topbarRight() { return (

- ReportManager.Instance.open()} icon={} /> + } /> + } /> window.open('https://brown-dash.github.io/Dash-Documentation/', '_blank')} icon={} /> - SettingsManager.Instance.open()} icon={} /> + } /> {/*
); -- cgit v1.2.3-70-g09d2