SentenceSelectorViewPresenter.ts 1.45 KB
import { Presenter } from "../../../common/classbase/PresenterBase";
import { RegPresenter } from "../PresenterCCViewFactory";
import { SentenceSelectorView, SentenceSelectorViewProps, SentenceSelectorViewType } from "../view/type/SentenceSelectorView";


@RegPresenter(SentenceSelectorViewType)
export default class SentenceSelectorViewPresenter extends Presenter<SentenceSelectorViewProps, SentenceSelectorView> {
    static uuid = "SentenceSelectorView";

    private _viewProps: SentenceSelectorViewProps;

    selectIndexEventCall: (index: number) => void;

    constructor() {
        super();
        this._viewProps =
        {
            sentence: undefined,
            backgroundpath: "",
            clickcausehide: false,
            onSelectIndexCallback: this.onSelectIndexCallback
        };
    }

    onSelectIndexCallback = (index: number) => {
        if (this.selectIndexEventCall != undefined) {
            this.selectIndexEventCall(index);
            this.view.close();
        }
    }

    onOpen(props: SentenceSelectorViewProps) {
        super.onOpen(props);
        this.selectIndexEventCall = props.onSelectIndexCallback;
        this._viewProps = { ...props, onSelectIndexCallback: this.onSelectIndexCallback };
        this._view.setProps(this._viewProps);
    }

    onClose() {
        super.onClose();
        this._viewProps.sentence = undefined;
        this._view.setProps(this._viewProps);
    }
}