From 2274efaed7203a59d830a17d0c770c5eced40b71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Daubensch=C3=BCtz?= Date: Mon, 27 Jul 2015 14:21:26 +0200 Subject: [PATCH] implement hashing toggle --- .../slides_container.js | 14 +++- .../file_drag_and_drop_dialog.js | 71 +++++++++++++++---- .../react_s3_fine_uploader.js | 3 +- sass/ascribe_uploader.scss | 10 +++ 4 files changed, 79 insertions(+), 19 deletions(-) diff --git a/js/components/ascribe_slides_container/slides_container.js b/js/components/ascribe_slides_container/slides_container.js index 7e37c6c9..4f4220de 100644 --- a/js/components/ascribe_slides_container/slides_container.js +++ b/js/components/ascribe_slides_container/slides_container.js @@ -34,7 +34,12 @@ let SlidesContainer = React.createClass({ // check if slide_num was defined, and if not then default to 0 let queryParams = this.getQuery(); if(!('slide_num' in queryParams)) { - this.replaceWith(this.getPathname(), null, {slide_num: 0}); + + // we're first requiring all the other possible queryParams and then set + // the specific one we need instead of overwriting them + queryParams.slide_num = 0; + + this.replaceWith(this.getPathname(), null, queryParams); } // init container width @@ -60,7 +65,12 @@ let SlidesContainer = React.createClass({ setSlideNum(slideNum) { if(slideNum < 0 || slideNum < React.Children.count(this.props.children)) { - this.replaceWith(this.getPathname(), null, {slide_num: slideNum}); + // we're first requiring all the other possible queryParams in order to not + // delete some of them that might be needed by other components + let queryParams = this.getQuery(); + queryParams.slide_num = slideNum; + + this.replaceWith(this.getPathname(), null, queryParams); this.setState({ slideNum: slideNum }); diff --git a/js/components/ascribe_uploader/file_drag_and_drop_dialog.js b/js/components/ascribe_uploader/file_drag_and_drop_dialog.js index e859f213..397ac0a1 100644 --- a/js/components/ascribe_uploader/file_drag_and_drop_dialog.js +++ b/js/components/ascribe_uploader/file_drag_and_drop_dialog.js @@ -1,9 +1,14 @@ 'use strict'; import React from 'react'; +import Router from 'react-router'; + +import ButtonLink from 'react-router-bootstrap/lib/ButtonLink'; import { getLangText } from '../../utils/lang_utils'; +let Link = Router.Link; + let FileDragAndDropDialog = React.createClass({ propTypes: { hasFiles: React.PropTypes.bool, @@ -12,30 +17,66 @@ let FileDragAndDropDialog = React.createClass({ localHashing: React.PropTypes.bool }, + mixins: [Router.State], + render() { + const queryParams = this.getQuery(); + if(this.props.hasFiles) { return null; } else { - if(this.props.multipleFiles) { + if(!queryParams.method) { + + let queryParamsHash = Object.assign({}, queryParams); + queryParamsHash.method = 'hash'; + + let queryParamsUpload = Object.assign({}, queryParams); + queryParamsUpload.method = 'upload'; + return ( - - {getLangText('Click or drag to add files')} + +

{getLangText('Would you rather')}

+ + + {getLangText('Hash your work')} + + + + or + + + + {getLangText('Upload and hash your work')} + +
); } else { - let dialog = this.props.localHashing ? getLangText('choose a file to hash') : getLangText('choose a file to upload'); - - return ( - -

{getLangText('Drag a file here')}

-

{getLangText('or')}

- - {dialog} + if(this.props.multipleFiles) { + return ( + + {getLangText('Click or drag to add files')} - - ); + ); + } else { + let dialog = queryParams.method === 'hash' ? getLangText('choose a file to hash') : getLangText('choose a file to upload'); + + return ( + +

{getLangText('Drag a file here')}

+

{getLangText('or')}

+ + {dialog} + +
+ ); + } } } } diff --git a/js/components/ascribe_uploader/react_s3_fine_uploader.js b/js/components/ascribe_uploader/react_s3_fine_uploader.js index 53f74b0d..a3b2bc63 100644 --- a/js/components/ascribe_uploader/react_s3_fine_uploader.js +++ b/js/components/ascribe_uploader/react_s3_fine_uploader.js @@ -281,8 +281,7 @@ var ReactS3FineUploader = React.createClass({ } else { throw new Error(getLangText('Could not find a url to download.')); } - console.log(res); - resolve(res.key); + resolve(res); }) .catch((err) => { reject(err); diff --git a/sass/ascribe_uploader.scss b/sass/ascribe_uploader.scss index 3f9e7e30..c96109ed 100644 --- a/sass/ascribe_uploader.scss +++ b/sass/ascribe_uploader.scss @@ -19,6 +19,16 @@ outline: 0; } +.present-options { + > p { + margin-bottom: .75em !important; + } + + .btn { + margin: 0 1em 0 1em; + } +} + .file-drag-and-drop .file-drag-and-drop-dialog > p:first-child { font-size: 1.5em !important;