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

Room header and copy link #34

Merged
merged 5 commits into from
Aug 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/components/Join/Join.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ class Join extends Component {
};
}

handleChange = (e) => {
handleChange = (e) => { // eslint-disable-line
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this way, we will always add eslint-disable-line to bypass this line.

If you don't like .bind(this), I think we can move () => into component like onSubmit={() => this.handleSubmit()}.

Copy link
Member Author

@hyjk2000 hyjk2000 Aug 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is false-positive, and strangely it doesn't happen every time or on every machine, please check out the issue I mentioned in the PR description. This is a bug of eslint or babel-eslint and it should be fixed in the future.

As for workarounds, there are many of them, including binding them manually in constructor. Actually the method you gave looks less appealing than that, and it seems won't work. handleSubmit is still not bound to the class context. I'll try this when I got time.

this.setState({
[e.target.name]: e.target.value
});
};

handleSubmit = (e) => {
handleSubmit = (e) => { // eslint-disable-line
e.preventDefault();
this.props.onSubmit(this.state.myName);
};
Expand Down
60 changes: 60 additions & 0 deletions src/components/Share/Share.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
.Share {
position: absolute;
top: 0;
right: 0;
left: 0;
margin: 0.5rem;
line-height: 1.5rem;

h1 {
display: inline-block;
font-size: 1.5rem;
font-weight: 100;

strong {
font-weight: 600;
}
}

input {
position: absolute;
left: -99999px;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know why you mentioned it's hacky now...

Could we use other hacky way instead of setting the left to a strange value?

Copy link
Member Author

@hyjk2000 hyjk2000 Aug 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try those ways we discussed about, but frankly, they look pretty much the same to me. 😉

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, not a big problem, just think -99999px is not good looking.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<input> needs to be visible for this trick to work, and by visible it means it cannot be display: none or visibility: hidden. opacity: 0 and/or width: 0; height: 0 works, but does not look any less hacky. Actually, kicking elements off screen like this is a common trick used in front end development for years.

}

a {
display: inline-block;
margin-left: 0.5rem;
border-bottom: 2px solid black;
color: inherit;
text-decoration: none;
vertical-align: top;
}

[aria-label] {
position: relative;
}

[aria-label]:hover:before {
content: ' ';
position: absolute;
top: 50%;
right: -1rem;
margin-top: -0.1rem;
width: 0.5rem;
height: 0.5rem;
background: black;
transform: rotate(45deg);
}

[aria-label]:hover:after {
content: attr(aria-label);
position: absolute;
margin-left: 0.7rem;
padding: 0.1rem 0.4rem;
border-radius: 3px;
background: black;
font-size: 0.5rem;
color: white;
white-space: nowrap;
}
}
45 changes: 45 additions & 0 deletions src/components/Share/Share.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React, { Component } from 'react';
import './Share.css';

const defaultTooltip = 'Click to copy link';

class Share extends Component {
constructor(props) {
super(props);
this.state = {
tooltip: defaultTooltip
};
}

handleCopy = (e) => { // eslint-disable-line
e.preventDefault();
this.textInput.select();
document.execCommand('copy');
this.setState({ tooltip: 'Copied!' });
};

handleDone = (e) => { // eslint-disable-line
this.setState({ tooltip: defaultTooltip });
};

render() {
const { roomName } = this.props;
const caption = `${process.env.REACT_APP_DOMAIN}/${roomName}`;
const link = `${window.location.protocol}//${caption}`;

return (
<div className="Share">
<h1>Poker4<strong>Fun</strong></h1>
<input type="text" value={link} ref={(input) => { this.textInput = input; }} readOnly />
<a
href={link}
onClick={this.handleCopy}
onMouseLeave={this.handleDone}
aria-label={this.state.tooltip}>
{caption}</a>
</div>
);
}
}

export default Share;
8 changes: 8 additions & 0 deletions src/components/Share/Share.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react';
import ReactDOM from 'react-dom';
import Share from './Share';

it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<Share />, div);
});
4 changes: 4 additions & 0 deletions src/pages/App/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@
justify-content: center;
align-items: center;
height: 100%;

input {
border-radius: none;
}
}
4 changes: 2 additions & 2 deletions src/pages/Landing/Landing.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ class Landing extends Component {
};
}

handleChange = (e) => {
handleChange = (e) => { // eslint-disable-line
this.setState({
roomName: e.target.value
});
};

handleSubmit = (e) => {
handleSubmit = (e) => { // eslint-disable-line
e.preventDefault();
const roomName = this.state.roomName || this.state.randomRoomName;
this.props.history.push(roomName);
Expand Down
13 changes: 8 additions & 5 deletions src/pages/Room/Room.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { Component } from 'react';
import Share from 'components/Share/Share';
import Notification from 'components/Notification/Notification';
import Join from 'components/Join/Join';
import Actions from 'components/Actions/Actions';
Expand Down Expand Up @@ -57,12 +58,12 @@ class Room extends Component {
this.socket.close();
}

handleReconn = (e) => {
handleReconn = (e) => { // eslint-disable-line
e.preventDefault();
this.socket.open();
};

handlePlayerJoin = (name) => {
handlePlayerJoin = (name) => { // eslint-disable-line
this.setState({
me: {
id: this.socket.id,
Expand All @@ -75,7 +76,7 @@ class Room extends Component {
this.socket.emit('play', name);
};

handleVote = (e) => {
handleVote = (e) => { // eslint-disable-line
const score = e.target.value;
this.setState(prevState => ({
me: Object.assign({}, prevState.me, { score, voted: true }),
Expand All @@ -84,11 +85,11 @@ class Room extends Component {
this.socket.emit('vote', score);
};

handleShow = () => {
handleShow = () => { // eslint-disable-line
this.socket.emit('show');
};

handleClear = () => {
handleClear = () => { // eslint-disable-line
this.setState(prevState => ({
me: Object.assign({}, prevState.me, { score: null, voted: false }),
myScore: null,
Expand All @@ -105,6 +106,8 @@ class Room extends Component {
const playerName = localStorage.getItem('playerName') || '';
return (
<div className="Room">
<Share
roomName={this.room} />
<Notification
active={disconnected}
reconnCountdown={reconnCountdown}
Expand Down