Skip to content

Commit

Permalink
Merge pull request #104 from sproogen/f/#99-autolink-urls
Browse files Browse the repository at this point in the history
Added url auto linking in questions and answers
  • Loading branch information
sproogen committed Aug 12, 2017
2 parents 006092d + 72a9d9f commit dffaae4
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 7 deletions.
5 changes: 3 additions & 2 deletions app/Resources/client/src/routes/Answer/Answer.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React from 'react'
import { Helmet } from 'react-helmet'
import { connect } from 'react-redux'
import PropTypes from 'prop-types'
import { mergeAll } from 'ramda'
import Helmet from 'react-helmet'
import Linkify from 'react-linkify'
import { browserHistory } from 'react-router'
import { pollSelector, hasQuestionSelector } from 'store/poll'
import { fetchPoll, APIError } from 'store/api'
Expand Down Expand Up @@ -45,7 +46,7 @@ class Answer extends React.Component {
<Back />
<div className='container header-container answer-header-container'>
<div className='header center-text'>
<h2>{ this.props.poll.question }</h2>
<h2><Linkify properties={{ target: '_blank' }}>{ this.props.poll.question }</Linkify></h2>
<Sharing poll={this.props.poll} />
</div>
</div>
Expand Down
27 changes: 22 additions & 5 deletions app/Resources/client/src/routes/Answer/components/Answer/Answer.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,38 @@
import React from 'react'
import PropTypes from 'prop-types'
import { merge } from 'ramda'
import { connect } from 'react-redux'
import { withRouter } from 'react-router'
import Linkify from 'react-linkify'
import { postResponse } from 'store/api'
import { userRespondedAnswerSelector } from 'store/poll'
import './Answer.scss'

export class Answer extends React.Component {
constructor (props) {
super(props)
this.state = { animating: false }
this.state = { animating : false }
this.linkClicked = false
}

handleClick = () => {
this.setState({ animating: true })
setTimeout(() => { this.setState({ animating: false }) }, 550)
this.props.postResponse()
if (!this.linkClicked) {
this.setState((prevState) =>
merge(prevState, { animating : true })
)
setTimeout(() => {
this.setState((prevState) =>
merge(prevState, { animating : false })
)
}, 550)
this.props.postResponse()
} else {
this.linkClicked = false
}
}

linkClick = () => {
this.linkClicked = true
}

calculateWidth = () => {
Expand All @@ -41,7 +58,7 @@ export class Answer extends React.Component {
htmlFor={'answer-' + this.props.index}
className={'input-label input-label-options' + (this.state.animating ? ' input-label-options--click' : '')}
onClick={this.handleClick}>
{ this.props.answer.answer }
<Linkify properties={{ target: '_blank', onClick: this.linkClick }}>{ this.props.answer.answer }</Linkify>
</label>
<span htmlFor={'answer-' + this.props.index} className='input-label-votes'>
{this.props.answer.responsesCount} votes
Expand Down
20 changes: 20 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"react": "^15.5.4",
"react-dom": "^15.5.4",
"react-helmet": "^5.1.3",
"react-linkify": "^0.2.1",
"react-redux": "^5.0.4",
"react-router": "^3.0.0",
"redbox-react": "^1.3.6",
Expand Down

0 comments on commit dffaae4

Please sign in to comment.