import React from 'react'; import { getUrlData, pushPath } from '$utils/history'; import { toTranslit } from '$utils/format'; import { TIPS } from '$constants/tips'; import { MODES } from '$constants/modes'; type Props = { address: String, // initial? title: String, // initial? save_error: String, save_finished: Boolean, save_overwriting: Boolean, save_processing: Boolean, setMode: Function, sendSaveRequest: Function, }; type State = { address: String, title: String, }; export class SaveDialog extends React.Component { constructor(props) { super(props); this.state = { address: props.address || '', title: props.title || '', }; } getAddress = () => { const { path } = getUrlData(); const { title, address } = this.state; return toTranslit(address.trim()) || toTranslit(title.trim().toLowerCase()) || toTranslit(path.trim()); }; setTitle = ({ target: { value } }) => this.setState({ title: (value || '') }); setAddress = ({ target: { value } }) => this.setState({ address: (value || '') }); // cancelSaving = () => this.props.editor.changeMode(MODES.NONE); cancelSaving = () => this.props.setMode(MODES.NONE); sendSaveRequest = (e, force = false) => { const { title } = this.state; const address = this.getAddress(); this.props.sendSaveRequest({ title, address, force, }); }; forceSaveRequest = e => this.sendSaveRequest(e, true); render() { const { title } = this.state; const { save_error, save_finished, save_overwriting, save_processing } = this.props; const { host } = getUrlData(); return (
{ save_error || TIPS.SAVE_INFO }
{ !save_finished &&
Отмена
} { !save_finished && !save_overwriting &&
Сохранить
} { save_overwriting &&
Перезаписать
} { save_finished &&
Отлично, спасибо!
}
); } }