From 70dbd1b32d13d30e15c03ee91b0fab7bfdf429b3 Mon Sep 17 00:00:00 2001
From: Maximilian Hils <git@maximilianhils.com>
Date: Mon, 25 Jul 2016 17:03:50 -0700
Subject: web: refactor ContentLoader

---
 web/src/js/components/ContentView/ViewSelector.jsx | 51 +++++++++++++++-------
 1 file changed, 35 insertions(+), 16 deletions(-)

(limited to 'web/src/js/components/ContentView/ViewSelector.jsx')

diff --git a/web/src/js/components/ContentView/ViewSelector.jsx b/web/src/js/components/ContentView/ViewSelector.jsx
index 9b151a5b..973d2333 100644
--- a/web/src/js/components/ContentView/ViewSelector.jsx
+++ b/web/src/js/components/ContentView/ViewSelector.jsx
@@ -1,28 +1,47 @@
 import React, { PropTypes } from 'react'
 import classnames from 'classnames'
-import views, { ViewAuto } from './ContentViews'
+import { connect } from 'react-redux'
+import * as ContentViews from './ContentViews'
+import { setContentView } from "../../ducks/ui/flow";
+
+
+function ViewButton({ name, setContentView, children, activeView }) {
+    return (
+        <button
+            onClick={() => setContentView(name)}
+            className={classnames('btn btn-default', { active: name === activeView })}>
+            {children}
+        </button>
+    )
+}
+ViewButton = connect(state => ({
+    activeView: state.ui.flow.contentView
+}), {
+    setContentView
+})(ViewButton)
+
 
 ViewSelector.propTypes = {
-    active: PropTypes.func.isRequired,
     message: PropTypes.object.isRequired,
-    onSelectView: PropTypes.func.isRequired,
 }
+export default function ViewSelector({ message }) {
+
+    let autoView = ContentViews.ViewAuto.findView(message)
+    let autoViewName = (autoView.displayName || autoView.name)
+        .toLowerCase()
+        .replace('view', '')
+        .replace(/ContentLoader\((.+)\)/,"$1")
 
-export default function ViewSelector({ active, message, onSelectView }) {
     return (
         <div className="view-selector btn-group btn-group-xs">
-            {views.map(View => (
-                <button
-                    key={View.name}
-                    onClick={() => onSelectView(View.name)}
-                    className={classnames('btn btn-default', { active: View === active })}>
-                    {View === ViewAuto ? (
-                        `auto: ${ViewAuto.findView(message).name.toLowerCase().replace('view', '')}`
-                    ) : (
-                        View.name.toLowerCase().replace('view', '')
-                    )}
-                </button>
-            ))}
+
+            <ViewButton name="AutoView">auto: {autoViewName}</ViewButton>
+
+            {Object.keys(ContentViews).map(name =>
+                name !== "ViewAuto" &&
+                <ViewButton key={name} name={name}>{name.toLowerCase().replace('view', '')}</ViewButton>
+            )}
+
         </div>
     )
 }
-- 
cgit v1.2.3


From e1587b2bc1b425a162af30d6c271bcd392047b02 Mon Sep 17 00:00:00 2001
From: Maximilian Hils <git@maximilianhils.com>
Date: Mon, 25 Jul 2016 17:12:39 -0700
Subject: make empty buttons editable

---
 web/src/js/components/ContentView/ViewSelector.jsx | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'web/src/js/components/ContentView/ViewSelector.jsx')

diff --git a/web/src/js/components/ContentView/ViewSelector.jsx b/web/src/js/components/ContentView/ViewSelector.jsx
index 973d2333..89b36231 100644
--- a/web/src/js/components/ContentView/ViewSelector.jsx
+++ b/web/src/js/components/ContentView/ViewSelector.jsx
@@ -35,7 +35,7 @@ export default function ViewSelector({ message }) {
     return (
         <div className="view-selector btn-group btn-group-xs">
 
-            <ViewButton name="AutoView">auto: {autoViewName}</ViewButton>
+            <ViewButton name="ViewAuto">auto: {autoViewName}</ViewButton>
 
             {Object.keys(ContentViews).map(name =>
                 name !== "ViewAuto" &&
-- 
cgit v1.2.3

