From d1ab279f7401c80e11a1f8dd84334ddd49ba128a Mon Sep 17 00:00:00 2001 From: Riley Davis Date: Fri, 21 Apr 2017 13:26:32 -0600 Subject: [PATCH] add a little keyboard shortcut widget --- .../src/components/ModerationKeysModal.css | 44 +++++++++ .../src/components/ModerationKeysModal.js | 95 ++++++++++++++----- client/coral-admin/src/translations.json | 8 ++ 3 files changed, 122 insertions(+), 25 deletions(-) diff --git a/client/coral-admin/src/components/ModerationKeysModal.css b/client/coral-admin/src/components/ModerationKeysModal.css index a030b6efa..73697d930 100644 --- a/client/coral-admin/src/components/ModerationKeysModal.css +++ b/client/coral-admin/src/components/ModerationKeysModal.css @@ -18,3 +18,47 @@ border-radius: 4px; border: 1px solid #999; } + +.callToAction { + position: fixed; + left: 10px; + bottom: 10px; + width: 280px; + height: 200px; + background: white; + padding: 15px; + box-sizing: border-box; + box-shadow: 0px 3px 5px 0px rgba(0,0,0,0.15); + + .ctaHeader { + font-size: 16px; + margin-bottom: 5px; + } + + ul { + padding-left: 0; + list-style: none; + margin: 0 0 10px 0; + } + + p, li { + font-size: 12px; + margin-bottom: 5px; + } + + li span:first-child, p:last-child span:first-child { + display: inline-block; + width: 120px; + } +} + +.closeButton { + float: right; + font-size: 20px; + cursor: pointer; +} + +.smallKey { + padding: 5px; + border: 1px solid #ccc; +} diff --git a/client/coral-admin/src/components/ModerationKeysModal.js b/client/coral-admin/src/components/ModerationKeysModal.js index 5a951e588..60933dee0 100644 --- a/client/coral-admin/src/components/ModerationKeysModal.js +++ b/client/coral-admin/src/components/ModerationKeysModal.js @@ -4,6 +4,8 @@ import React from 'react'; import Modal from 'components/Modal'; import styles from './ModerationKeysModal.css'; +const lang = new I18n(translations); + const shortcuts = [ { title: 'modqueue.navigation', @@ -23,29 +25,72 @@ const shortcuts = [ } ]; -export default ({open, onClose}) => ( - -

{lang.t('modqueue.shortcuts')}

-
- {shortcuts.map((shortcut, i) => ( - - - - - - - - {Object.keys(shortcut.shortcuts).map(key => ( - - - - - ))} - -
{lang.t(shortcut.title)}
{key}{lang.t(shortcut.shortcuts[key])}
- ))} -
-
-); +export default class ModerationKeysModal extends React.Component { + constructor (props) { + super(props); + try { + if (window.localStorage.getItem('coral:shortcutsNote') === null) { + window.localStorage.setItem('coral:shortcutsNote', 'show'); + } + } catch (e) { -const lang = new I18n(translations); + // above will fail in Private Mode in some browsers. + } + this.state = { + shortcutsNote: window.localStorage.getItem('coral:shortcutsNote') || 'show' + }; + } + + closeCallToAction = () => { + try { + window.localStorage.setItem('coral:shortcutsNote', 'hide'); + this.setState({foo: Math.random()}); // apparently this.forceUpdate() is bad, but we need a re-render + } catch (e) { + + // when setItem fails in Safari Private mode + this.setState({shortcutsNote: 'hide'}); + } + } + + render () { + const {open, onClose} = this.props; + const hideShortcutsNote = window.localStorage.getItem('coral:shortcutsNote') === 'hide' || + this.state.dashboardNote === 'hide'; // for Safari Incognito + return ( +
+
+
×
+

{lang.t('modqueue.mod-faster')}

+

{lang.t('modqueue.try-these')}:

+
    +
  • {lang.t('modqueue.approve')} t
  • +
  • {lang.t('modqueue.reject')} r
  • +
+

{lang.t('modqueue.view-more-shortcuts')} {lang.t('modqueue.shift-key')} + /

+
+ +

{lang.t('modqueue.shortcuts')}

+
+ {shortcuts.map((shortcut, i) => ( + + + + + + + + {Object.keys(shortcut.shortcuts).map(key => ( + + + + + ))} + +
{lang.t(shortcut.title)}
{key}{lang.t(shortcut.shortcuts[key])}
+ ))} +
+
+
+ ); + } +} diff --git a/client/coral-admin/src/translations.json b/client/coral-admin/src/translations.json index f317b71a7..9e167232e 100644 --- a/client/coral-admin/src/translations.json +++ b/client/coral-admin/src/translations.json @@ -44,6 +44,10 @@ "close": "Close", "actions": "Actions", "navigation": "Navigation", + "mod-faster": "Moderate faster with keyboard shortcuts", + "try-these": "Try these", + "view-more-shortcuts": "View more shortcuts", + "shift-key": "⇧", "approve": "Approve comment", "reject": "Reject comment", "nextcomment": "Go to the next comment", @@ -226,6 +230,10 @@ "rejected": "rechazado", "flagged": "marcado", "shortcuts": "Atajos de teclado", + "mod-faster": "Moderar más rápido con atajos del teclado", + "try-these": "Intenta estos", + "view-more-shortcuts": "Ver más atajos", + "shift-key": "⇧", "close": "Cerrar", "emptyqueue": "No se encontro ningún usuario. Están escondidos.", "showshortcuts": "Mostrar atajos",