Skip to content

Commit

Permalink
Fixes Remeic#9
Browse files Browse the repository at this point in the history
  • Loading branch information
gkkirilov committed Oct 29, 2018
1 parent 66bbd66 commit 30113f2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/Mail.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@ import React, { Component } from 'react';
import { ToastContainer, toast } from 'react-toastify';
import gen from './wordGenerator';
import polyglot from './translator';
import copyTextToClipboard from "./copyToClipboard";

class Mail extends Component {
constructor(props) {
super(props);
let lengthWord = 4;
let suffix = '@mailnesia.com';
let newWord = gen(lengthWord);
copyTextToClipboard(newWord + suffix);
this.notify();

this.state = {
lengthWord: lengthWord,
suffix: '@mailnesia.com',
word: gen(lengthWord)
suffix: suffix,
word: newWord
};
}

Expand All @@ -21,7 +27,10 @@ class Mail extends Component {
};

newMail = () => {
this.setState({ word: gen(this.state.lengthWord) });
const newWord = gen(this.state.lengthWord);
copyTextToClipboard(newWord + this.state.suffix);
this.notify();
this.setState({ word: newWord });
};

copy = () => {
Expand Down
9 changes: 9 additions & 0 deletions src/copyToClipboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function copyTextToClipboard(text) {
navigator.clipboard.writeText(text).then(function() {
console.log('Async: Copying to clipboard was successful!');
}, function(err) {
console.error('Async: Could not copy text: ', err);
});
}

export default copyTextToClipboard;

0 comments on commit 30113f2

Please sign in to comment.