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

Refactoring view.jsx removes code duplication #4154

Merged
Changes from 1 commit
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
Next Next commit
Refactoring view.jsx removes code duplication
  • Loading branch information
Aswathprabhu committed Oct 1, 2019
commit 9192354dcc9c2614c15d7f611fce5bbf1719fa02
57 changes: 36 additions & 21 deletions app/javascript/chat/view.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
import { h, Component } from 'preact';

const setupButton = ({className = '', onClickCallback, dataContent = '', btnLabel = ''}) => {
return (
<button
className={className}
onClick={onClickCallback}
data-content={dataContent}
>
{btnLabel}
</button>
)
}

export default class View extends Component {
channel = (props) => {
return (
Expand All @@ -8,20 +20,22 @@ export default class View extends Component {
<div>
<em>{props.channel.description}</em>
</div>
<button
className="cta"
onClick={this.props.onAcceptInvitation}
data-content={props.channel.membership_id}
>
Accept
</button>
<button
className="cta"
onClick={this.props.onDeclineInvitation}
data-content={props.channel.membership_id}
>
Decline
</button>
{
setupButton({
className: 'cta',
onClickCallback: this.props.onAcceptInvitation,
dataContent: props.channel.membership_id,
btnLabel: 'Accept'
})
}
{
setupButton({
className: 'cta',
onClickCallback: this.props.onDeclineInvitation,
dataContent: props.channel.membership_id,
btnLabel: 'Decline'
})
}
</div>
);
};
Expand All @@ -33,13 +47,14 @@ export default class View extends Component {
return (
<div className="chatNonChatView">
<div className="container">
<button
className="chatNonChatView_exitbutton"
data-content="exit"
onClick={this.props.onViewExit}
>
×
</button>
{
setupButton({
className: 'chatNonChatView_exitbutton',
onClickCallback: this.props.onViewExit,
dataContent: 'exit',
btnLabel: '×'
})
}
<h1>Channel Invitations 🤗</h1>
{channels}
</div>
Expand Down