aboutsummaryrefslogtreecommitdiff
path: root/src/client/util/ServerStats.tsx
blob: f84ad8598972d102f3db31f645109dad526b535f (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
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} />;
    }
}