-
Notifications
You must be signed in to change notification settings - Fork 1
/
website_src_components_canvas_preview_SaveImgBtn.jsx.html
201 lines (170 loc) · 9.86 KB
/
website_src_components_canvas_preview_SaveImgBtn.jsx.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: website/src/components/canvas/preview/SaveImgBtn.jsx</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: website/src/components/canvas/preview/SaveImgBtn.jsx</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>/**
* @file Button to save rendered 3D preview image.
*/
import React, { Component, PropTypes } from 'react';
import { connect } from 'react-redux';
import IconButton from 'material-ui/IconButton';
import PhotoCamera from 'material-ui/svg-icons/image/photo-camera';
import Snackbar from 'material-ui/Snackbar';
import * as CC from '../CanvasConstants';
import * as FBHelper from '../../../helpers/FirebaseHelper';
import * as FBStorageHelper from '../../../helpers/FirebaseStorageHelper';
import { grey800 } from 'material-ui/styles/colors';
const styles = {
icon: {
height: 32,
padding: 3,
width: 32,
},
size: {
height: 64,
padding: 10,
position: 'absolute',
right: 0,
top: -2,
width: 64,
zIndex: 200,
},
};
/**
* @classdesc Save image button for the 3D previewer.
*/
class SaveImgBtn extends Component {
/**
* Constructor for the save image button.
* @param {Object} props The props to be passed in.
*/
constructor(props) {
super(props);
this.state = {
snackbarOpen: false,
};
this.save3DImage = this.save3DImage.bind(this);
this.createSnackbarHandler = this.createSnackbarHandler.bind(this);
}
/**
* Gets the image URL for the 3D render.
* @returns {String} The URL for the image.
* @throws Will throw if canvas has not been loaded onto the page yet.
*/
getImageURL() {
const renderWrapper = document.getElementById(CC.RENDER_WRAPPER_ID);
if (renderWrapper !== null) {
const canvas = renderWrapper.getElementsByTagName('canvas')[0];
return canvas.toDataURL();
} else {
throw CC.CANVAS_MISSING;
}
}
/**
* Saves off an image of the current 3D Renderer to firebase.
* @returns {void}
*/
save3DImage() {
const openSnackbarHandler = this.createSnackbarHandler(true);
let imageURL = null;
try {
imageURL = this.getImageURL();
} catch(e) {
console.error(e);
return;
}
if (!this.props.hasCanvasImage) {
FBHelper.setHasCanvasImage(this.props.currentCanvas);
}
const processingUpload = (snapshot) => {
if (snapshot.state === 'paused') {
console.error(CC.IMAGE_UPLOAD_PAUSED);
}
};
const uploadSuccessful = () => {
openSnackbarHandler();
}
const uploadError = () => {
console.error(CC.IMAGE_UPLOAD_ERROR);
}
FBStorageHelper.saveRenderedImage(this.props.currentCanvas, imageURL,
uploadSuccessful, uploadError, processingUpload);
}
/**
* Creates a handler for opening and closing the snackbar.
* @param {boolean} toSet Whether the handler sets the snackbar open or closed.
* @returns {Function} The hanlder to control the snackbar.
*/
createSnackbarHandler(toSet) {
let handler = () => {
this.setState({
snackbarOpen: toSet,
});
}
handler = handler.bind(this);
return handler;
}
/**
* Renders the HTML for the save image button.
* @returns {HTML} The html for the save image button.
*/
render() {
return (
<div>
<IconButton
disabled={!this.props.hasCode}
key={CC.SAVE_3D_IMAGE_BUTTON}
onClick={this.save3DImage}
style={styles.size}
tooltip="Capture Image"
tooltipPosition="top-center"
touch={true}
>
<PhotoCamera color={grey800} />
</IconButton>
<Snackbar
autoHideDuration={2000}
message={CC.IMAGE_SAVE_MESSAGE}
onRequestClose={this.createSnackbarHandler(false)}
open={this.state.snackbarOpen}
/>
</div>
);
}
}
SaveImgBtn.propTypes = {
currentCanvas: PropTypes.string,
dispatch: PropTypes.func,
hasCanvasImage: PropTypes.bool,
hasCode: PropTypes.bool,
}
export default connect()(SaveImgBtn);
</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Canvas.html">Canvas</a></li><li><a href="CanvasElement.html">CanvasElement</a></li><li><a href="CanvasList.html">CanvasList</a></li><li><a href="CanvasOrientationBtns.html">CanvasOrientationBtns</a></li><li><a href="CanvasView.html">CanvasView</a></li><li><a href="ClearPreviewBtn.html">ClearPreviewBtn</a></li><li><a href="CreateCanvas.html">CreateCanvas</a></li><li><a href="DashNavBar.html">DashNavBar</a></li><li><a href="ExportModal.html">ExportModal</a></li><li><a href="ImportModelModal.html">ImportModelModal</a></li><li><a href="Landing.html">Landing</a></li><li><a href="MainLayout.html">MainLayout</a></li><li><a href="OptionsBar.html">OptionsBar</a></li><li><a href="Preview3D.html">Preview3D</a></li><li><a href="Render3DBtn.html">Render3DBtn</a></li><li><a href="ResizeTextfields.html">ResizeTextfields</a></li><li><a href="RotationSlider.html">RotationSlider</a></li><li><a href="SaveImgBtn.html">SaveImgBtn</a></li><li><a href="ShareCanvasModal.html">ShareCanvasModal</a></li><li><a href="Sidebar.html">Sidebar</a></li></ul><h3>Global</h3><ul><li><a href="global.html#activeElementReducer">activeElementReducer</a></li><li><a href="global.html#addCanvas">addCanvas</a></li><li><a href="global.html#addCanvasUser">addCanvasUser</a></li><li><a href="global.html#addElement">addElement</a></li><li><a href="global.html#addUserToCanvasByEmail">addUserToCanvasByEmail</a></li><li><a href="global.html#addUserToCanvasByUid">addUserToCanvasByUid</a></li><li><a href="global.html#CanvasError">CanvasError</a></li><li><a href="global.html#canvasReducer">canvasReducer</a></li><li><a href="global.html#clear">clear</a></li><li><a href="global.html#cloneElement">cloneElement</a></li><li><a href="global.html#craftmlCodeReducer">craftmlCodeReducer</a></li><li><a href="global.html#Dashboard">Dashboard</a></li><li><a href="global.html#deleteElement">deleteElement</a></li><li><a href="global.html#formPostBody">formPostBody</a></li><li><a href="global.html#generateScript">generateScript</a></li><li><a href="global.html#getAuthState">getAuthState</a></li><li><a href="global.html#getFirebaseUserByEmail">getFirebaseUserByEmail</a></li><li><a href="global.html#getRenderedImageUrl">getRenderedImageUrl</a></li><li><a href="global.html#getRequest">getRequest</a></li><li><a href="global.html#getUserInfo">getUserInfo</a></li><li><a href="global.html#handleCorsRequest">handleCorsRequest</a></li><li><a href="global.html#initElements">initElements</a></li><li><a href="global.html#initFirebase">initFirebase</a></li><li><a href="global.html#insertIntoState">insertIntoState</a></li><li><a href="global.html#LandingContent">LandingContent</a></li><li><a href="global.html#LandingNavBar">LandingNavBar</a></li><li><a href="global.html#LoadingIndicator">LoadingIndicator</a></li><li><a href="global.html#mainReducers">mainReducers</a></li><li><a href="global.html#PageNotFound">PageNotFound</a></li><li><a href="global.html#performAndDispatchLogin">performAndDispatchLogin</a></li><li><a href="global.html#postRequest">postRequest</a></li><li><a href="global.html#removeCanvas">removeCanvas</a></li><li><a href="global.html#removeCanvasUser">removeCanvasUser</a></li><li><a href="global.html#removeElement">removeElement</a></li><li><a href="global.html#removeElementAndPersist">removeElementAndPersist</a></li><li><a href="global.html#removeField">removeField</a></li><li><a href="global.html#Routes">Routes</a></li><li><a href="global.html#saveRenderedImage">saveRenderedImage</a></li><li><a href="global.html#setAuthState">setAuthState</a></li><li><a href="global.html#setAutoCodeUpdate">setAutoCodeUpdate</a></li><li><a href="global.html#setCanvasName">setCanvasName</a></li><li><a href="global.html#setCanvasNameAndPersist">setCanvasNameAndPersist</a></li><li><a href="global.html#setCanvasOrientation">setCanvasOrientation</a></li><li><a href="global.html#setCanvasOrientationAndPersist">setCanvasOrientationAndPersist</a></li><li><a href="global.html#setCanvasOwner">setCanvasOwner</a></li><li><a href="global.html#setCode">setCode</a></li><li><a href="global.html#setElementLocation">setElementLocation</a></li><li><a href="global.html#setElementRotation">setElementRotation</a></li><li><a href="global.html#setElementSize">setElementSize</a></li><li><a href="global.html#setHasCanvasImage">setHasCanvasImage</a></li><li><a href="global.html#SideBar">SideBar</a></li><li><a href="global.html#signOut">signOut</a></li><li><a href="global.html#storeConstructor">storeConstructor</a></li><li><a href="global.html#targetElement">targetElement</a></li><li><a href="global.html#updateAndPersist">updateAndPersist</a></li><li><a href="global.html#updateElement">updateElement</a></li><li><a href="global.html#updateElementReducer">updateElementReducer</a></li><li><a href="global.html#updateUserInfo">updateUserInfo</a></li><li><a href="global.html#userInfoReducer">userInfoReducer</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.0-dev</a> on Fri May 05 2017 07:15:02 GMT-0600 (Mountain Daylight Time)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>