From 281f20ef1e9ac33a7e210ba562eb2914f6d187e6 Mon Sep 17 00:00:00 2001
From: Clemens <cle1000.cb@gmail.com>
Date: Tue, 19 Jul 2016 16:13:26 +0200
Subject: added flow_content update

---
 web/src/js/components/ContentView.jsx | 54 +++++++++++++++++++++++++----------
 1 file changed, 39 insertions(+), 15 deletions(-)

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

diff --git a/web/src/js/components/ContentView.jsx b/web/src/js/components/ContentView.jsx
index 0b93d3f0..766de26f 100644
--- a/web/src/js/components/ContentView.jsx
+++ b/web/src/js/components/ContentView.jsx
@@ -5,9 +5,8 @@ import * as ContentViews from './ContentView/ContentViews'
 import * as MetaViews from './ContentView/MetaViews'
 import ContentLoader from './ContentView/ContentLoader'
 import ViewSelector from './ContentView/ViewSelector'
-import { setContentView, setDisplayLarge } from '../ducks/ui'
+import { setContentView, setDisplayLarge, setModifiedFlowContent } from '../ducks/ui'
 import CodeEditor from './common/CodeEditor'
-import {setModifiedFlowContent} from '../ducks/flows'
 
 ContentView.propTypes = {
     // It may seem a bit weird at the first glance:
@@ -20,7 +19,7 @@ ContentView.propTypes = {
 ContentView.isContentTooLarge = msg => msg.contentLength > 1024 * 1024 * (ContentViews.ViewImage.matches(msg) ? 10 : 0.2)
 
 function ContentView(props) {
-    const { flow, message, contentView, selectView, displayLarge, setDisplayLarge } = props
+    const { flow, message, contentView, selectView, displayLarge, setDisplayLarge, onContentChange, isFlowEditorOpen, setModifiedFlowContent } = props
 
     if (message.contentLength === 0) {
         return <MetaViews.ContentEmpty {...props}/>
@@ -38,20 +37,43 @@ function ContentView(props) {
 
     return (
         <div>
-            {View.textView ? (
+            {isFlowEditorOpen ? (
                 <ContentLoader flow={flow} message={message}>
-                    <View content="" />
-                </ContentLoader>
-            ) : (
-                <View flow={flow} message={message} />
+                        <CodeEditor content="" onChange={content =>{setModifiedFlowContent(content)}}/>
+                    </ContentLoader>
+            ): (
+                <div>
+                    {View.textView ? (
+                        <ContentLoader flow={flow} message={message}>
+                            <View content="" />
+                        </ContentLoader>
+                    ) : (
+                        <View flow={flow} message={message} />
+                    )}
+                    <div className="view-options text-center">
+                        <ViewSelector onSelectView={selectView} active={View} message={message}/>
+                        &nbsp;
+                        <a className="btn btn-default btn-xs"
+                           href={MessageUtils.getContentURL(flow, message)}
+                           title="Download the content of the flow.">
+                            <i className="fa fa-download"/>
+                        </a>
+                        &nbsp;
+                        <a  className="btn btn-default btn-xs"
+                            onClick={() => ContentView.fileInput.click()}
+                            title="Upload a file to replace the content."
+                        >
+                            <i className="fa fa-upload"/>
+                        </a>
+                        <input
+                            ref={ref => ContentView.fileInput = ref}
+                            className="hidden"
+                            type="file"
+                            onChange={e => {if(e.target.files.length > 0) onContentChange(e.target.files[0])}}
+                        />
+                    </div>
+                </div>
             )}
-            <div className="view-options text-center">
-                <ViewSelector onSelectView={selectView} active={View} message={message}/>
-                &nbsp;
-                <a className="btn btn-default btn-xs" href={MessageUtils.getContentURL(flow, message)}>
-                    <i className="fa fa-download"/>
-                </a>
-            </div>
         </div>
     )
 }
@@ -60,9 +82,11 @@ export default connect(
     state => ({
         contentView: state.ui.contentView,
         displayLarge: state.ui.displayLarge,
+        isFlowEditorOpen : state.ui.isFlowEditorOpen
     }),
     {
         selectView: setContentView,
         setDisplayLarge,
+        setModifiedFlowContent
     }
 )(ContentView)
-- 
cgit v1.2.3

