{"size": 3808, "ext": "js", "max_stars_repo_path": "diskreet-blockchain/ts/components/dialog/SessionNicknameDialog.js", "max_stars_repo_name": "woflydev/general-projects", "max_stars_repo_stars_event_min_datetime": "2022-03-13T22:46:43.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-13T22:46:43.000Z", "max_issues_repo_path": "diskreet-blockchain/ts/components/dialog/SessionNicknameDialog.js", "max_issues_repo_name": "woflydev/general-projects", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "diskreet-blockchain/ts/components/dialog/SessionNicknameDialog.js", "max_forks_repo_name": "woflydev/general-projects", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 51.4594594595, "max_line_length": 188, "alphanum_fraction": 0.6609768908}
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SessionNicknameDialog = void 0;
const react_1 = __importStar(require("react"));
const conversations_1 = require("../../session/conversations");
const lodash_1 = __importDefault(require("lodash"));
const Text_1 = require("../basic/Text");
const react_redux_1 = require("react-redux");
const modalDialog_1 = require("../../state/ducks/modalDialog");
const SessionButton_1 = require("../basic/SessionButton");
const SessionWrapperModal_1 = require("../SessionWrapperModal");
const SessionNicknameDialog = (props) => {
    const { conversationId } = props;
    const [nickname, setNickname] = (0, react_1.useState)('');
    const dispatch = (0, react_redux_1.useDispatch)();
    const onNicknameInput = async (event) => {
        if (event.key === 'Enter') {
            await saveNickname();
        }
        else {
            const currentNicknameEntered = event.target.value;
            setNickname(currentNicknameEntered);
        }
    };
    const onClickClose = () => {
        dispatch((0, modalDialog_1.changeNickNameModal)(null));
    };
    const saveNickname = async () => {
        if (!conversationId) {
            throw new Error('Cant save without conversation id');
        }
        const conversation = (0, conversations_1.getConversationController)().get(conversationId);
        await conversation.setNickname(nickname);
        onClickClose();
    };
    return (react_1.default.createElement(SessionWrapperModal_1.SessionWrapperModal, { title: window.i18n('changeNickname'), onClose: onClickClose, showExitIcon: false, showHeader: true },
        react_1.default.createElement("div", { className: "session-modal__centered" },
            react_1.default.createElement("span", { className: "subtle" }, window.i18n('changeNicknameMessage')),
            react_1.default.createElement(Text_1.SpacerLG, null)),
        react_1.default.createElement("input", { autoFocus: true, type: "nickname", id: "nickname-modal-input", placeholder: window.i18n('nicknamePlaceholder'), onKeyUp: e => {
                void onNicknameInput(lodash_1.default.cloneDeep(e));
            } }),
        react_1.default.createElement("div", { className: "session-modal__button-group" },
            react_1.default.createElement(SessionButton_1.SessionButton, { text: window.i18n('cancel'), onClick: onClickClose }),
            react_1.default.createElement(SessionButton_1.SessionButton, { text: window.i18n('ok'), onClick: saveNickname, buttonColor: SessionButton_1.SessionButtonColor.Green }))));
};
exports.SessionNicknameDialog = SessionNicknameDialog;
