import { CollectionSubView } from "./CollectionSubView"; import { Transform } from "../../util/Transform"; import React = require("react"); import { computed, action, IReactionDisposer, reaction, runInAction, observable } from "mobx"; import { Doc } from "../../../new_fields/Doc"; import { NumCast } from "../../../new_fields/Types"; import "./CollectionStaffView.scss"; import { observer } from "mobx-react"; @observer export class CollectionStaffView extends CollectionSubView(doc => doc) { private getTransform = (): Transform => this.props.ScreenToLocalTransform().translate(0, -this._mainCont.current!.scrollTop); private _mainCont = React.createRef(); private _reactionDisposer: IReactionDisposer | undefined; @observable private _staves = NumCast(this.props.Document.staves); componentDidMount = () => { this._reactionDisposer = reaction( () => NumCast(this.props.Document.staves), (staves) => runInAction(() => this._staves = staves) ); this.props.Document.staves = 5; } @computed get addStaffButton() { return
+
; } @computed get staves() { const staves = []; for (let i = 0; i < this._staves; i++) { const rows = []; for (let j = 0; j < 5; j++) { rows.push(
); } staves.push(
{rows}
); } return staves; } @action addStaff = (e: React.PointerEvent) => { this.props.Document.staves = this._staves + 1; } render() { return
{this.staves} {this.addStaffButton}
; } }