Browse Source

fix(refresh channels): refresh channels on new channel route

renovate/lint-staged-8.x
Jack Mallers 7 years ago
parent
commit
9b37690a62
  1. 50
      app/reducers/channels.js
  2. 23
      app/routes/channels/components/Channels.js
  3. 12
      app/routes/channels/components/Channels.scss
  4. 4
      app/routes/channels/containers/ChannelsContainer.js
  5. 21
      app/routes/wallet/components/Wallet.js
  6. 2
      app/routes/wallet/containers/WalletContainer.js

50
app/reducers/channels.js

@ -237,18 +237,18 @@ channelsSelectors.channelModalOpen = createSelector(
channel => (!!channel) channel => (!!channel)
) )
channelsSelector.activeChannels = createSelector( const activeChannels = createSelector(
channelsSelector, channelsSelector,
openChannels => openChannels.filter(channel => channel.active) openChannels => openChannels.filter(channel => channel.active)
) )
channelsSelector.closingPendingChannels = createSelector( const closingPendingChannels = createSelector(
pendingClosedChannelsSelector, pendingClosedChannelsSelector,
pendingForceClosedChannelsSelector, pendingForceClosedChannelsSelector,
(pendingClosedChannels, pendingForcedClosedChannels) => [...pendingClosedChannels, ...pendingForcedClosedChannels] (pendingClosedChannels, pendingForcedClosedChannels) => [...pendingClosedChannels, ...pendingForcedClosedChannels]
) )
channelsSelectors.allChannels = createSelector( const allChannels = createSelector(
channelsSelector, channelsSelector,
pendingOpenChannelsSelector, pendingOpenChannelsSelector,
pendingClosedChannelsSelector, pendingClosedChannelsSelector,
@ -276,17 +276,41 @@ channelsSelectors.nonActiveFilters = createSelector(
(filters, filter) => filters.filter(f => f.key !== filter.key) (filters, filter) => filters.filter(f => f.key !== filter.key)
) )
const FILTERS = { export const currentChannels = createSelector(
ALL_CHANNELS: channelsSelectors.allChannels, allChannels,
ACTIVE_CHANNELS: channelsSelector.activeChannels, activeChannels,
OPEN_CHANNELS: channelsSelector, channelsSelector,
OPEN_PENDING_CHANNELS: pendingOpenChannelsSelector, pendingOpenChannelsSelector,
CLOSING_PENDING_CHANNELS: channelsSelector.closingPendingChannels closingPendingChannels,
}
channelsSelectors.currentChannels = createSelector(
filterSelector, filterSelector,
filter => FILTERS[filter.key] channelSearchQuerySelector,
(allChannels, activeChannels, openChannels, pendingOpenChannels, pendingClosedChannels, filter, searchQuery) => {
// Helper function to deliver correct channel array based on filter
const filteredArray = filter => {
switch(filter) {
case 'ALL_CHANNELS':
return allChannels
case 'ACTIVE_CHANNELS':
return activeChannels
case 'OPEN_CHANNELS':
return openChannels
case 'OPEN_PENDING_CHANNELS':
return pendingOpenChannels
case 'CLOSING_PENDING_CHANNELS':
return pendingClosedChannels
}
}
const channelArray = filteredArray(filter.key)
console.log('channelArray: ', channelArray)
return channelArray.filter(channel => {
return Object.prototype.hasOwnProperty.call(channel, 'channel') ?
channel.channel.remote_node_pub.includes(searchQuery) || channel.channel.channel_point.includes(searchQuery)
:
channel.remote_pubkey.includes(searchQuery) || channel.channel_point.includes(searchQuery)
})
}
) )
export { channelsSelectors } export { channelsSelectors }

23
app/routes/channels/components/Channels.js

@ -1,7 +1,7 @@
import React, { Component } from 'react' import React, { Component } from 'react'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import { FaAlignJustify, FaGlobe, FaAngleDown } from 'react-icons/lib/fa' import { FaAlignJustify, FaGlobe, FaAngleDown, FaRepeat } from 'react-icons/lib/fa'
import { MdSearch } from 'react-icons/lib/md' import { MdSearch } from 'react-icons/lib/md'
import OpenPendingChannel from 'components/Channels/OpenPendingChannel' import OpenPendingChannel from 'components/Channels/OpenPendingChannel'
@ -23,6 +23,7 @@ class Channels extends Component {
render() { render() {
const { const {
fetchChannels,
channels: { channels: {
searchQuery, searchQuery,
filterPulldown, filterPulldown,
@ -52,6 +53,20 @@ class Channels extends Component {
setCurrentChannel setCurrentChannel
} = this.props } = this.props
const refreshClicked = (event) => {
// store event in icon so we dont get an error when react clears it
const icon = event.currentTarget
// fetch peers
fetchChannels()
// clear animation after the second so we can reuse it
setTimeout(() => { icon.style.animation = '' }, 1000)
// spin icon for 1 sec
icon.style.animation = 'spin 1000ms linear 1'
}
console.log('currentChannels: ',currentChannels) console.log('currentChannels: ',currentChannels)
return ( return (
@ -102,6 +117,12 @@ class Channels extends Component {
} }
</ul> </ul>
</section> </section>
<section className={`${styles.refreshContainer} hint--left`} data-hint='Refresh your peers list'>
<FaRepeat
style={{ verticalAlign: 'baseline' }}
onClick={refreshClicked}
/>
</section>
</div> </div>
<div className={`${styles.channels} ${filterPulldown && styles.fade}`}> <div className={`${styles.channels} ${filterPulldown && styles.fade}`}>

12
app/routes/channels/components/Channels.scss

@ -43,6 +43,9 @@
.filtersContainer { .filtersContainer {
position: relative; position: relative;
display: flex;
flex-direction: row;
justify-content: space-between;
padding: 0 40px; padding: 0 40px;
h2, h2 span { h2, h2 span {
@ -86,6 +89,15 @@
} }
} }
} }
.refreshContainer {
color: $bluegrey;
&:hover {
cursor: pointer;
color: lighten($bluegrey, 10%);
}
}
} }
.layoutsContainer { .layoutsContainer {

4
app/routes/channels/containers/ChannelsContainer.js

@ -6,6 +6,7 @@ import {
openChannel, openChannel,
updateChannelSearchQuery, updateChannelSearchQuery,
setViewType, setViewType,
currentChannels,
toggleFilterPulldown, toggleFilterPulldown,
changeFilter, changeFilter,
@ -61,8 +62,7 @@ const mapStateToProps = state => ({
network: state.network, network: state.network,
identity_pubkey: state.info.data.identity_pubkey, identity_pubkey: state.info.data.identity_pubkey,
allChannels: channelsSelectors.allChannels(state), currentChannels: currentChannels(state),
currentChannels: channelsSelectors.currentChannels(state)(state),
activeChanIds: channelsSelectors.activeChanIds(state), activeChanIds: channelsSelectors.activeChanIds(state),
nonActiveFilters: channelsSelectors.nonActiveFilters(state), nonActiveFilters: channelsSelectors.nonActiveFilters(state),

21
app/routes/wallet/components/Wallet.js

@ -1,6 +1,5 @@
import React, { Component } from 'react' import React, { Component } from 'react'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import Channels from 'components/Channels'
import Peers from 'components/Peers' import Peers from 'components/Peers'
import styles from './Wallet.scss' import styles from './Wallet.scss'
@ -27,7 +26,6 @@ class Wallet extends Component {
setChannelForm, setChannelForm,
connectRequest, connectRequest,
disconnectRequest, disconnectRequest,
allChannels,
openChannel, openChannel,
closeChannel, closeChannel,
currentTicker, currentTicker,
@ -49,24 +47,6 @@ class Wallet extends Component {
connect={connectRequest} connect={connectRequest}
disconnect={disconnectRequest} disconnect={disconnectRequest}
/> />
<Channels
fetchChannels={fetchChannels}
ticker={ticker}
peers={peers}
channelsLoading={channelsLoading}
allChannels={allChannels}
channels={channels}
pendingChannels={pendingChannels}
modalChannel={channel}
setChannel={setChannel}
channelModalOpen={channelModalOpen}
channelForm={channelForm}
setChannelForm={setChannelForm}
openChannel={openChannel}
closeChannel={closeChannel}
currentTicker={currentTicker}
explorerLinkBase={explorerLinkBase}
/>
</section> </section>
</div> </div>
) )
@ -87,7 +67,6 @@ Wallet.propTypes = {
setChannelForm: PropTypes.func.isRequired, setChannelForm: PropTypes.func.isRequired,
connectRequest: PropTypes.func.isRequired, connectRequest: PropTypes.func.isRequired,
disconnectRequest: PropTypes.func.isRequired, disconnectRequest: PropTypes.func.isRequired,
allChannels: PropTypes.array.isRequired,
openChannel: PropTypes.func.isRequired, openChannel: PropTypes.func.isRequired,
closeChannel: PropTypes.func.isRequired, closeChannel: PropTypes.func.isRequired,
currentTicker: PropTypes.object.isRequired, currentTicker: PropTypes.object.isRequired,

2
app/routes/wallet/containers/WalletContainer.js

@ -45,8 +45,6 @@ const mapStateToProps = state => ({
peers: state.peers, peers: state.peers,
channels: state.channels, channels: state.channels,
allChannels: channelsSelectors.allChannels(state),
peerModalOpen: peersSelectors.peerModalOpen(state), peerModalOpen: peersSelectors.peerModalOpen(state),
channelModalOpen: channelsSelectors.channelModalOpen(state), channelModalOpen: channelsSelectors.channelModalOpen(state),

Loading…
Cancel
Save