diff --git a/README.md b/README.md
index 64f8e2ff..18e3c16c 100644
--- a/README.md
+++ b/README.md
@@ -28,7 +28,7 @@ Background pattern from http://subtlepatterns.com/, commercial and non-commercia
### Desktop screenshot
insert_drive_file
-
{filename} ({this.props.size})
+
{filename} ({this.props.size})
@@ -2422,7 +2496,8 @@
scrollPosition: 0,
readOnly: false,
writeOnly: false,
- typingIndicator: false
+ typingIndicator: false,
+ imagePreview: null
};
},
@@ -2483,6 +2558,7 @@
this.setState({
messages: msgs,
topic: props.topic,
+ imagePreview: null,
scrollPosition: 0
});
tryToResubscribe = true;
@@ -2618,6 +2694,14 @@
}
},
+ handleImagePreview: function(content) {
+ this.setState({ imagePreview: content });
+ },
+
+ handleCloseImagePreview: function() {
+ this.setState({ imagePreview: null });
+ },
+
handleContextClick: function(e) {
e.preventDefault();
e.stopPropagation();
@@ -2678,7 +2762,8 @@
+ sequence={sequence} received={msgReceived}
+ onImagePreview={this.handleImagePreview} key={msg.seq} />
);
}
@@ -2700,7 +2785,7 @@
@@ -2740,6 +2825,9 @@
disabled={this.state.readOnly}
sendMessage={this.props.sendMessage}
onError={this.props.onError} />
+ {this.state.imagePreview ?
+
: null}
);
} else {
@@ -2766,11 +2854,18 @@
handleAttachImage: function(e) {
if (e.target.files && e.target.files.length > 0) {
var file = e.target.files[0];
- if (file.size > MAX_ATTACHMENT_SIZE) {
- this.props.onError("The image size " + bytesToHumanSize(file.size) +
- " exceeds the " + bytesToHumanSize(MAX_ATTACHMENT_SIZE) + " limit.", "err");
- return;
- }
+ var instance = this;
+ imageFileToBase64(file, function(bits, width, height) {
+ if (bits.length > MAX_ATTACHMENT_SIZE) {
+ this.props.onError("The image size " + bytesToHumanSize(bits.length) +
+ " exceeds the " + bytesToHumanSize(MAX_ATTACHMENT_SIZE) + " limit.", "err");
+ return;
+ }
+
+ instance.props.sendMessage(Drafty.insertImage(null,
+ 0, file.type, bits.split(',')[1], width, height,
+ file.name));
+ });
}
},
@@ -2785,7 +2880,7 @@
var reader = new FileReader();
var instance = this;
- reader.addEventListener("load", function () {
+ reader.addEventListener("load", function() {
instance.props.sendMessage(Drafty.attachFile(null, file.type, reader.result.split(',')[1], file.name));
}, false);
reader.readAsDataURL(file);
@@ -2872,45 +2967,63 @@
);
}
});
- /* END Conversation panel */
- /* This is a div which covers the entire AppView and shows selected modal dialog box */
- var ModalDialogWrapper = React.createClass({
- render: function() {
- var dialog = null;
- switch (this.props.dialog) {
- case "new-topic":
- dialog =
;
- break;
- default:
- break;
- }
- if (dialog) {
- dialog =
{dialog}
;
- }
- return dialog;
- }
- });
+ MessagesView.ImagePreview = React.createClass({
+ getInitialState: function() {
+ return {};
+ },
+
+ componentDidMount: function() {
+ this.setState({
+ width: this.container.clientWidth,
+ height: this.container.clientHeight - REM_SIZE * 7
+ });
+ },
- ModalDialogWrapper.NewTopic = React.createClass({
render: function() {
+ if (!this.props.content) {
+ return null;
+ }
+
+ var instance = this;
+ var width = null, height = null;
+ console.log(this.props.content.width, this.props.content.height, this.state.width, this.state.height);
+ if (this.props.content.width && this.props.content.height) {
+ width = Math.max(Math.min(this.state.width, this.props.content.width), 8);
+ height = Math.max(Math.min(this.state.height, this.props.content.height), 8);
+ var scale = Math.min(width / this.props.content.width, height / this.props.content.height, 1.0);
+ width = (this.props.content.width * scale) | 0;
+ height = (this.props.content.height * scale) | 0;
+ }
+ var filename = this.props.content.filename;
+ if (filename.length > 20) {
+ filename = filename.slice(0, 8) + "..." + filename.slice(-8);
+ }
return (
-
-
- New topic
+
+
-
Not implemented
-
);
}
});
- /* End of modal dialog wrapper */
+ /* END Conversation panel */
/* The top-level class to hold all fuinctionality together */
var AppView = React.createClass({
@@ -3385,11 +3498,6 @@
render: function() {
return (
-
-