diff options
| author | James Hu <51237606+jameshu111@users.noreply.github.com> | 2023-05-04 10:36:59 -0400 |
|---|---|---|
| committer | James Hu <51237606+jameshu111@users.noreply.github.com> | 2023-05-04 10:36:59 -0400 |
| commit | 725bf38dc018cb218d8a88605234e95a2beee446 (patch) | |
| tree | 9150905cf1b67b06c03fdd8d10ac6da6e8246832 /src/client/util/ServerStats.tsx | |
| parent | 96465f2dccc974a821fa912c90def988b76808e5 (diff) | |
| parent | 1c24114bbe8f69f61948f7531277305457926498 (diff) | |
Merge branch 'master' into james-server-stats
Diffstat (limited to 'src/client/util/ServerStats.tsx')
| -rw-r--r-- | src/client/util/ServerStats.tsx | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/client/util/ServerStats.tsx b/src/client/util/ServerStats.tsx new file mode 100644 index 000000000..f84ad8598 --- /dev/null +++ b/src/client/util/ServerStats.tsx @@ -0,0 +1,54 @@ +import { action, computed, observable } from 'mobx'; +import { observer } from 'mobx-react'; +import * as React from 'react'; +import { MainViewModal } from '../views/MainViewModal'; +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 ( + <div> + <span>Active users:{this._stats?.socketMap.length}</span> + {this._stats?.socketMap.map((user: any) => ( + <p>{user.username}</p> + ))} + </div> + ); + } + + render() { + return <MainViewModal contents={this.sharingInterface} isDisplayed={this.isOpen} interactive={true} closeOnExternalClick={this.close} />; + } +} |
