Browse Source

feature(contacts): editable contact capacity

renovate/lint-staged-8.x
Jack Mallers 7 years ago
parent
commit
9a31c68b17
  1. 40
      app/components/Contacts/ContactsForm.js
  2. 23
      app/components/Contacts/ContactsForm.scss
  3. 16
      app/reducers/contactsform.js
  4. 3
      app/routes/contacts/containers/ContactsContainer.js

40
app/components/Contacts/ContactsForm.js

@ -5,17 +5,31 @@ import { MdClose } from 'react-icons/lib/md'
import { FaCircle } from 'react-icons/lib/fa' import { FaCircle } from 'react-icons/lib/fa'
import styles from './ContactsForm.scss' import styles from './ContactsForm.scss'
const ContactsForm = ({ class ContactsForm extends React.Component {
constructor(props) {
super(props)
this.state = {
editing: false
}
}
render() {
const {
contactsform, contactsform,
closeContactsForm, closeContactsForm,
updateContactFormSearchQuery, updateContactFormSearchQuery,
updateContactCapacity,
openChannel, openChannel,
activeChannelPubkeys, activeChannelPubkeys,
nonActiveChannelPubkeys, nonActiveChannelPubkeys,
pendingOpenChannelPubkeys, pendingOpenChannelPubkeys,
filteredNetworkNodes filteredNetworkNodes
}) => { } = this.props
const { editing } = this.state
const renderRightSide = (node) => { const renderRightSide = (node) => {
if (activeChannelPubkeys.includes(node.pub_key)) { if (activeChannelPubkeys.includes(node.pub_key)) {
return ( return (
@ -53,13 +67,19 @@ const ContactsForm = ({
<span <span
className={`${styles.connect} hint--left`} className={`${styles.connect} hint--left`}
data-hint='Connect with 0.1 BTC' data-hint='Connect with 0.1 BTC'
onClick={() => openChannel({ pubkey: node.pub_key, host: node.addresses[0].addr, local_amt: 0.1 })} onClick={() => openChannel({ pubkey: node.pub_key, host: node.addresses[0].addr, local_amt: contactsform.contactsform.contactCapacity })}
> >
Connect Connect
</span> </span>
) )
} }
const inputClicked = () => {
if (editing) { return }
this.setState({ editing: true })
}
return ( return (
<div> <div>
<ReactModal <ReactModal
@ -80,7 +100,7 @@ const ContactsForm = ({
</div> </div>
</header> </header>
<div className={styles.form} onKeyPress={event => event.charCode === 13 && console.log('gaaaang')}> <div className={styles.form}>
<div className={styles.search}> <div className={styles.search}>
<input <input
type='text' type='text'
@ -122,7 +142,15 @@ const ContactsForm = ({
<footer className={styles.footer}> <footer className={styles.footer}>
<div> <div>
<span className={styles.amount}> <span className={styles.amount}>
0.1 <input
type='text'
value={contactsform.contactCapacity}
onChange={event => updateContactCapacity(event.target.value)}
onClick={inputClicked}
onKeyPress={event => event.charCode === 13 && this.setState({ editing: false })}
readOnly={!editing}
style={{ width: `${editing ? 20 : contactsform.contactCapacity.toString().length + 1}%` }}
/>
</span> </span>
<span className={styles.caption}> <span className={styles.caption}>
BTC per contact BTC per contact
@ -133,6 +161,8 @@ const ContactsForm = ({
</div> </div>
) )
} }
}
ContactsForm.propTypes = { ContactsForm.propTypes = {

23
app/components/Contacts/ContactsForm.scss

@ -122,10 +122,31 @@
.footer { .footer {
padding: 10px 15px; padding: 10px 15px;
border-top: 1px solid $darkgrey; border-top: 1px solid $darkgrey;
font-size: 14px;
span { span {
&:nth-child(1) { &.amount {
&:hover {
input {
border: 1px solid $darkgrey;
cursor: text;
}
}
input {
border: 1px solid transparent;
padding: 0;
outline: 0;
font-weight: bold; font-weight: bold;
font-size: 14px;
line-height: 14px;
transition: all 0.25s;
&.isEditing {
width: 100%;
border-bottom: 1px solid $darkgrey;
}
}
} }
&:nth-child(2) { &:nth-child(2) {

16
app/reducers/contactsform.js

@ -5,7 +5,8 @@ import filter from 'lodash/filter'
// Initial State // Initial State
const initialState = { const initialState = {
isOpen: false, isOpen: false,
searchQuery: '' searchQuery: '',
contactCapacity: 0.1
} }
// Constants // Constants
@ -15,6 +16,8 @@ export const CLOSE_CONTACTS_FORM = 'CLOSE_CONTACTS_FORM'
export const UPDATE_CONTACT_FORM_SEARCH_QUERY = 'UPDATE_CONTACT_FORM_SEARCH_QUERY' export const UPDATE_CONTACT_FORM_SEARCH_QUERY = 'UPDATE_CONTACT_FORM_SEARCH_QUERY'
export const UPDATE_CONTACT_CAPACITY = 'UPDATE_CONTACT_CAPACITY'
// ------------------------------------ // ------------------------------------
// Actions // Actions
// ------------------------------------ // ------------------------------------
@ -37,6 +40,13 @@ export function updateContactFormSearchQuery(searchQuery) {
} }
} }
export function updateContactCapacity(contactCapacity) {
return {
type: UPDATE_CONTACT_CAPACITY,
contactCapacity
}
}
// ------------------------------------ // ------------------------------------
// Action Handlers // Action Handlers
// ------------------------------------ // ------------------------------------
@ -44,7 +54,9 @@ const ACTION_HANDLERS = {
[OPEN_CONTACTS_FORM]: state => ({ ...state, isOpen: true }), [OPEN_CONTACTS_FORM]: state => ({ ...state, isOpen: true }),
[CLOSE_CONTACTS_FORM]: state => ({ ...state, isOpen: false }), [CLOSE_CONTACTS_FORM]: state => ({ ...state, isOpen: false }),
[UPDATE_CONTACT_FORM_SEARCH_QUERY]: (state, { searchQuery }) => ({ ...state, searchQuery }) [UPDATE_CONTACT_FORM_SEARCH_QUERY]: (state, { searchQuery }) => ({ ...state, searchQuery }),
[UPDATE_CONTACT_CAPACITY]: (state, { contactCapacity }) => ({ ...state, contactCapacity })
} }
// ------------------------------------ // ------------------------------------

3
app/routes/contacts/containers/ContactsContainer.js

@ -21,6 +21,7 @@ import {
openContactsForm, openContactsForm,
closeContactsForm, closeContactsForm,
updateContactFormSearchQuery, updateContactFormSearchQuery,
updateContactCapacity,
contactFormSelectors contactFormSelectors
} from 'reducers/contactsform' } from 'reducers/contactsform'
@ -30,6 +31,7 @@ const mapDispatchToProps = {
openContactsForm, openContactsForm,
closeContactsForm, closeContactsForm,
updateContactFormSearchQuery, updateContactFormSearchQuery,
updateContactCapacity,
openChannel, openChannel,
updateChannelSearchQuery, updateChannelSearchQuery,
toggleFilterPulldown, toggleFilterPulldown,
@ -63,6 +65,7 @@ const mergeProps = (stateProps, dispatchProps, ownProps) => {
const contactsFormProps = { const contactsFormProps = {
closeContactsForm: dispatchProps.closeContactsForm, closeContactsForm: dispatchProps.closeContactsForm,
updateContactFormSearchQuery: dispatchProps.updateContactFormSearchQuery, updateContactFormSearchQuery: dispatchProps.updateContactFormSearchQuery,
updateContactCapacity: dispatchProps.updateContactCapacity,
openChannel: dispatchProps.openChannel, openChannel: dispatchProps.openChannel,
contactsform: stateProps.contactsform, contactsform: stateProps.contactsform,

Loading…
Cancel
Save