aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/presentationview/PresentationList.tsx
blob: 930ce202e15600c0879c8372ffd9a8ec88818505 (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
import { action } from "mobx";
import { observer } from "mobx-react";
import { Doc, DocListCast } from "../../../new_fields/Doc";
import { Id } from "../../../new_fields/FieldSymbols";
import { NumCast } from "../../../new_fields/Types";
import PresentationElement from "./PresentationElement";
import "./PresentationView.scss";
import React = require("react");


interface PresListProps {
    mainDocument: Doc;
    deleteDocument(index: number): void;
    gotoDocument(index: number, fromDoc: number): Promise<void>;
    PresElementsMappings: Map<Doc, PresentationElement>;
    setChildrenDocs: (docList: Doc[]) => void;
    presStatus: boolean;
    removeDocByRef(doc: Doc): boolean;
    clearElemMap(): void;

}


@observer
/**
 * Component that takes in a document prop and a boolean whether it's collapsed or not.
 */
export default class PresentationViewList extends React.Component<PresListProps> {


    /**
     * Initially every document starts with a viewScale 1, which means
     * that they will be displayed in a canvas with scale 1.
     */
    @action
    initializeScaleViews = (docList: Doc[]) => {
        docList.forEach((doc: Doc) => {
            let curScale = NumCast(doc.viewScale, null);
            if (curScale === undefined) {
                doc.viewScale = 1;
            }
        });
    }

    render() {
        const children = DocListCast(this.props.mainDocument.data);
        this.initializeScaleViews(children);
        this.props.setChildrenDocs(children);
        this.props.clearElemMap();
        return (
            <div className="presentationView-listCont" >
                {children.map((doc: Doc, index: number) =>
                    <PresentationElement
                        ref={(e) => {
                            if (e && e !== null) {
                                this.props.PresElementsMappings.set(doc, e);
                            }
                        }}
                        key={doc[Id]}
                        mainDocument={this.props.mainDocument}
                        document={doc}
                        index={index}
                        deleteDocument={this.props.deleteDocument}
                        gotoDocument={this.props.gotoDocument}
                        allListElements={children}
                        presStatus={this.props.presStatus}
                        removeDocByRef={this.props.removeDocByRef}
                        PresElementsMappings={this.props.PresElementsMappings}
                    />
                )}
            </div>
        );
    }
}