Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.7.4: Fixing the PasteUploader refs issue. Replaced refs with state #19

Merged
merged 3 commits into from Jun 8, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "fdns-ui-react",
"version": "0.7.2",
"version": "0.7.3",
"description": "This is the open source UI library for react components using Foundation Services (FDNS).",
"main": "dist/index.js",
"jsnext:main": "dist/index.js",
Expand Down
52 changes: 30 additions & 22 deletions src/components/UploaderPaste.js
Expand Up @@ -26,40 +26,47 @@ class UploaderDrop extends Component {
// init
constructor(props) {
super(props);
this.handleUpload = this.handleUpload.bind(this);
this.handleReset = this.handleReset.bind(this);
this.reset = this.reset.bind(this);
this.textareaRef = React.createRef();
this.state = {
textValue: '',
}
}

// handle drop
handleUpload() {
let value = '';
const textarea = this.textareaRef;
if (textarea) value = textarea.current.value;
handleUpload = () => {
if (this.state.textValue.length > 0) {
const value = this.state.textValue;

// create file
const date = new Date();
const file = new Blob([value], { type: 'text/plain' });
file.name = `${this.props.prefix}${date.getTime()}.txt`;
file.lastModified = date;
// create file
const date = new Date();
const file = new Blob([value], { type: 'text/plain' });
file.name = `${this.props.prefix}${date.getTime()}.txt`;
file.lastModified = date;

// reset
if (this.props.resetOnUpload) this.reset();
// reset
if (this.props.resetOnUpload) this.reset();

// trigger the onUpload event with the file
this.props.onUpload(file);
// trigger the onUpload event with the file
this.props.onUpload(file);
}
}

// handle reset
handleReset() {
handleReset = () => {
this.reset();
}

handleChange = (e) => {
this.setState({
textValue: e.target.value
});
}

// reset the textarea
reset() {
const textarea = this.textareaRef.current;
if (textarea) textarea.value = '';
reset = () => {
const textarea = this.textareaRef;
russell-ingram marked this conversation as resolved.
Show resolved Hide resolved
this.setState({
textValue: ''
});
}

// main render method
Expand All @@ -70,7 +77,8 @@ class UploaderDrop extends Component {
aria-label="Paste Text to Upload"
component="textarea"
placeholder={this.props.placeholder}
ref={this.textareaRef}
onChange={this.handleChange}
value={this.state.textValue}
/>
<hr />
<div className="icon-buttons pull-right">
Expand Down