about summary refs log tree commit diff
path: root/app/javascript/flavours/glitch/util
diff options
context:
space:
mode:
authorkibigo! <marrus-sh@users.noreply.github.com>2017-12-26 16:54:28 -0800
committerkibigo! <marrus-sh@users.noreply.github.com>2018-01-04 18:21:59 -0800
commit3c29f5740447270a4122b334281a907ecbdd4165 (patch)
treedd3daba631f2eddf0ede5af76b8e29eda8874854 /app/javascript/flavours/glitch/util
parent924ffe81d477a8cf890c8117efb94b908760bccc (diff)
WIP <Compose> Refactor; <Drawer> ed.
Diffstat (limited to 'app/javascript/flavours/glitch/util')
-rw-r--r--app/javascript/flavours/glitch/util/dom_helpers.js8
-rw-r--r--app/javascript/flavours/glitch/util/react_helpers.js2
-rw-r--r--app/javascript/flavours/glitch/util/redux_helpers.js9
3 files changed, 18 insertions, 1 deletions
diff --git a/app/javascript/flavours/glitch/util/dom_helpers.js b/app/javascript/flavours/glitch/util/dom_helpers.js
index ee95ef8dd..3e1f4a26d 100644
--- a/app/javascript/flavours/glitch/util/dom_helpers.js
+++ b/app/javascript/flavours/glitch/util/dom_helpers.js
@@ -4,3 +4,11 @@ import detectPassiveEvents from 'detect-passive-events';
 //  This will either be a passive lister options object (if passive
 //  events are supported), or `false`.
 export const withPassive = detectPassiveEvents.hasSupport ? { passive: true } : false;
+
+//  Focuses the root element.
+export function focusRoot () {
+  let e;
+  if (document && (e = document.querySelector('.ui')) && (e = e.parentElement)) {
+    e.focus();
+  }
+}
diff --git a/app/javascript/flavours/glitch/util/react_helpers.js b/app/javascript/flavours/glitch/util/react_helpers.js
index 0826f3584..087e3969d 100644
--- a/app/javascript/flavours/glitch/util/react_helpers.js
+++ b/app/javascript/flavours/glitch/util/react_helpers.js
@@ -14,7 +14,7 @@ export function assignHandlers (target, handlers) {
 //  This function only returns the component if the result of calling
 //  `test` with `data` is `true`.  Useful with funciton binding.
 export function conditionalRender (test, data, component) {
-  return test ? component : null;
+  return test(data) ? component : null;
 }
 
 //  This object provides props to make the component not visible.
diff --git a/app/javascript/flavours/glitch/util/redux_helpers.js b/app/javascript/flavours/glitch/util/redux_helpers.js
index 3bc8bc86f..c0f5eeb28 100644
--- a/app/javascript/flavours/glitch/util/redux_helpers.js
+++ b/app/javascript/flavours/glitch/util/redux_helpers.js
@@ -1,3 +1,6 @@
+import { injectIntl } from 'react-intl';
+import { connect } from 'react-redux';
+
 //  Merges react-redux props.
 export function mergeProps (stateProps, dispatchProps, ownProps) {
   Object.assign({}, ownProps, {
@@ -5,3 +8,9 @@ export function mergeProps (stateProps, dispatchProps, ownProps) {
     state: Object.assign({}, stateProps, ownProps.state || {}),
   });
 }
+
+//  Connects a component.
+export function wrap (Component, mapStateToProps, mapDispatchToProps, options) {
+  const withIntl = typeof options === 'object' ? options.withIntl : !!options;
+  return (withIntl ? injectIntl : i => i)(connect(mapStateToProps, mapDispatchToProps, mergeProps)(Component));
+}