From d817ecc4264200d72a5676f2b2f6e8807f1914eb Mon Sep 17 00:00:00 2001 From: Jack Mallers Date: Thu, 4 Jan 2018 11:50:55 -0600 Subject: [PATCH] feature(contacts): add filter and refresh to contacts --- app/reducers/channels.js | 17 ++- app/routes/friends/components/Friends.js | 80 ++++++++++- app/routes/friends/components/Friends.scss | 134 +++++++----------- .../friends/containers/FriendsContainer.js | 5 + 4 files changed, 142 insertions(+), 94 deletions(-) diff --git a/app/reducers/channels.js b/app/reducers/channels.js index 30b9a4e9..e67658b5 100644 --- a/app/reducers/channels.js +++ b/app/reducers/channels.js @@ -357,12 +357,13 @@ const allChannels = createSelector( export const currentChannels = createSelector( allChannels, channelsSelectors.activeChannels, + channelsSelectors.nonActiveChannels, channelsSelector, pendingOpenChannelsSelector, channelsSelectors.closingPendingChannels, filterSelector, channelSearchQuerySelector, - (allChannelsArr, activeChannelsArr, openChannels, pendingOpenChannels, pendingClosedChannels, filter, searchQuery) => { + (allChannelsArr, activeChannelsArr, nonActiveChannelsArr, openChannels, pendingOpenChannels, pendingClosedChannels, filter, searchQuery) => { // Helper function to deliver correct channel array based on filter const filteredArray = (filterKey) => { switch (filterKey) { @@ -370,6 +371,8 @@ export const currentChannels = createSelector( return allChannelsArr case 'ACTIVE_CHANNELS': return activeChannelsArr + case 'NON_ACTIVE_CHANNELS': + return nonActiveChannelsArr case 'OPEN_CHANNELS': return openChannels case 'OPEN_PENDING_CHANNELS': @@ -417,13 +420,13 @@ const initialState = { viewType: 0, filterPulldown: false, - filter: { key: 'ALL_CHANNELS', name: 'All Channels' }, + filter: { key: 'ALL_CHANNELS', name: 'All Contacts' }, filters: [ - { key: 'ALL_CHANNELS', name: 'All Channels' }, - { key: 'ACTIVE_CHANNELS', name: 'Active Channels' }, - { key: 'OPEN_CHANNELS', name: 'Open Channels' }, - { key: 'OPEN_PENDING_CHANNELS', name: 'Open Pending Channels' }, - { key: 'CLOSING_PENDING_CHANNELS', name: 'Closing Pending Channels' } + { key: 'ALL_CHANNELS', name: 'All Contacts' }, + { key: 'ACTIVE_CHANNELS', name: 'Online Contacts' }, + { key: 'NON_ACTIVE_CHANNELS', name: 'Offline Contacts' }, + { key: 'OPEN_PENDING_CHANNELS', name: 'Pending Contacts' }, + { key: 'CLOSING_PENDING_CHANNELS', name: 'Closing Contacts' } ] } diff --git a/app/routes/friends/components/Friends.js b/app/routes/friends/components/Friends.js index 4a75b493..e362bbf5 100644 --- a/app/routes/friends/components/Friends.js +++ b/app/routes/friends/components/Friends.js @@ -4,7 +4,7 @@ import PropTypes from 'prop-types' import Isvg from 'react-inlinesvg' import { MdSearch } from 'react-icons/lib/md' -import { FaCircle } from 'react-icons/lib/fa' +import { FaAngleDown, FaRepeat } from 'react-icons/lib/fa' import { btc } from 'utils' @@ -19,6 +19,14 @@ import plus from 'icons/plus.svg' import styles from './Friends.scss' class Friends extends Component { + constructor(props) { + super(props) + + this.state = { + refreshing: false + } + } + componentWillMount() { const { fetchChannels, fetchPeers, fetchDescribeNetwork } = this.props @@ -29,14 +37,24 @@ class Friends extends Component { render() { const { - channels: { searchQuery }, + channels: { + searchQuery, + filterPulldown, + filter, + viewType + }, currentChannels, activeChannels, nonActiveChannels, pendingOpenChannels, closingPendingChannels, - + fetchChannels, updateChannelSearchQuery, + + toggleFilterPulldown, + changeFilter, + nonActiveFilters, + openFriendsForm, friendsFormProps, @@ -44,6 +62,33 @@ class Friends extends Component { peers } = this.props + const refreshClicked = () => { + // turn the spinner on + this.setState({ refreshing: true }) + + // store event in icon so we dont get an error when react clears it + const icon = this.repeat.childNodes + + // fetch channels + fetchChannels() + + // wait for the svg to appear as child + const svgTimeout = setTimeout(() => { + if (icon[0].tagName === 'svg') { + // spin icon for 1 sec + icon[0].style.animation = 'spin 1000ms linear 1' + clearTimeout(svgTimeout) + } + }, 1) + + // clear animation after the second so we can reuse it + const refreshTimeout = setTimeout(() => { + icon[0].style.animation = '' + this.setState({ refreshing: false }) + clearTimeout(refreshTimeout) + }, 1000) + } + return (
@@ -76,7 +121,34 @@ class Friends extends Component { />
-