client/src/components/SlateEditor/ToolbarButtons.js
author ymh <ymh.work@gmail.com>
Fri, 30 Nov 2018 10:53:15 +0100
changeset 183 f8f3af9e5c83
parent 173 0e6703cd0968
permissions -rw-r--r--
Change the settings to avoid using Session authentication for rest framework as it raise exceptions in case client and backend are on the same domain On the filter, adapt to take into account new version of django_filters
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
173
0e6703cd0968 Correct the Note editor.
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
import React from 'react';
0e6703cd0968 Correct the Note editor.
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
import { Trans } from 'react-i18next';
0e6703cd0968 Correct the Note editor.
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
import { connect } from 'react-redux';
0e6703cd0968 Correct the Note editor.
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
import { bindActionCreators } from 'redux';
0e6703cd0968 Correct the Note editor.
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
0e6703cd0968 Correct the Note editor.
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
import { getAutoSubmit } from '../../selectors/authSelectors';
0e6703cd0968 Correct the Note editor.
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
import * as userActions from '../../actions/userActions';
0e6703cd0968 Correct the Note editor.
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
0e6703cd0968 Correct the Note editor.
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
function mapStateToProps(state, props) {
0e6703cd0968 Correct the Note editor.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
0e6703cd0968 Correct the Note editor.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
  const autoSubmit = getAutoSubmit(state);
0e6703cd0968 Correct the Note editor.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
0e6703cd0968 Correct the Note editor.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
  return {
0e6703cd0968 Correct the Note editor.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
    autoSubmit,
0e6703cd0968 Correct the Note editor.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
  };
0e6703cd0968 Correct the Note editor.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
}
0e6703cd0968 Correct the Note editor.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
0e6703cd0968 Correct the Note editor.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
function mapDispatchToProps(dispatch) {
0e6703cd0968 Correct the Note editor.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
  return {
0e6703cd0968 Correct the Note editor.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
    userActions: bindActionCreators(userActions, dispatch)
0e6703cd0968 Correct the Note editor.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
  }
0e6703cd0968 Correct the Note editor.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
}
0e6703cd0968 Correct the Note editor.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
0e6703cd0968 Correct the Note editor.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
// see https://github.com/facebook/react/issues/3005 for explanation about the timeout.
0e6703cd0968 Correct the Note editor.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
const ToolbarCheckbox = connect(mapStateToProps, mapDispatchToProps)(({ autoSubmit, userActions }) => (
0e6703cd0968 Correct the Note editor.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
  <div className="checkbox float-right">
0e6703cd0968 Correct the Note editor.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
    <label className="mr-2">
0e6703cd0968 Correct the Note editor.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
      <input type="checkbox" checked={autoSubmit} onChange={(e) => { setTimeout(userActions.setAutoSubmit, 0, e.target.checked) }} value="enterBox" /><small className="text-muted ml-1"><Trans i18nKey="slate_editor.press_enter_msg">Appuyer sur <kbd className="bg-irinotes-form text-muted ml-1">Entrée</kbd> pour ajouter une note</Trans></small>
0e6703cd0968 Correct the Note editor.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
    </label>
0e6703cd0968 Correct the Note editor.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
  </div>
0e6703cd0968 Correct the Note editor.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
));
0e6703cd0968 Correct the Note editor.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
0e6703cd0968 Correct the Note editor.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
export default ({ hasNote, isButtonDisabled, submitNote }) => (
0e6703cd0968 Correct the Note editor.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
  <div>
0e6703cd0968 Correct the Note editor.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
    <button type="button" id="btn-editor" className="btn btn-primary btn-sm text-secondary font-weight-bold float-right text-capitalize" disabled={isButtonDisabled} onClick={submitNote}>
0e6703cd0968 Correct the Note editor.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
      { hasNote ? <Trans i18nKey="common.save">Save</Trans> : <Trans i18nKey="common.add">Add</Trans> }
0e6703cd0968 Correct the Note editor.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
    </button>
0e6703cd0968 Correct the Note editor.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
    { !hasNote && <ToolbarCheckbox /> }
0e6703cd0968 Correct the Note editor.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
  </div>
0e6703cd0968 Correct the Note editor.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
);
0e6703cd0968 Correct the Note editor.
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41