Skip to content

Commit

Permalink
Merge pull request #1998 from kaloudis/hop-picker-search-filters
Browse files Browse the repository at this point in the history
HopPicker: add search, filters, sort
  • Loading branch information
kaloudis authored Feb 26, 2024
2 parents 03fa9e8 + 915a3f0 commit 2352087
Show file tree
Hide file tree
Showing 3 changed files with 160 additions and 142 deletions.
152 changes: 152 additions & 0 deletions components/Channels/ChannelsFilter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
import { Dimensions, View } from 'react-native';
import { SearchBar } from 'react-native-elements';

import { Row } from '../../components/layout/Row';
import { FilterOptions } from '../../components/Channels/FilterOptions';
import SortButton from '../../components/Channels/SortButton';

import { localeString } from '../../utils/LocaleUtils';
import { themeColor } from '../../utils/ThemeUtils';

import stores from '../../stores/Stores';
import { ChannelsType } from '../../stores/ChannelsStore';

const getChannelsSortKeys = (closed?: boolean) => {
const sortKeys: any = [];

if (closed) {
sortKeys.push(
{
key: `${localeString(
'views.Channel.closeHeight'
)} (${localeString('views.Channel.SortButton.ascending')})`,
value: { param: 'closeHeight', dir: 'ASC', type: 'numeric' }
},
{
key: `${localeString(
'views.Channel.closeHeight'
)} (${localeString('views.Channel.SortButton.descending')})`,
value: {
param: 'closeHeight',
dir: 'DESC',
type: 'numeric'
}
}
);
}

sortKeys.push(
{
key: `${localeString('views.Channel.capacity')} (${localeString(
'views.Channel.SortButton.largestFirst'
)})`,
value: {
param: 'channelCapacity',
dir: 'DESC',
type: 'numeric'
}
},
{
key: `${localeString('views.Channel.capacity')} (${localeString(
'views.Channel.SortButton.smallestFirst'
)})`,
value: { param: 'channelCapacity', dir: 'ASC', type: 'numeric' }
},
{
key: `${localeString(
'views.Channel.inboundCapacity'
)} (${localeString('views.Channel.SortButton.largestFirst')})`,
value: { param: 'remoteBalance', dir: 'DESC', type: 'numeric' }
},
{
key: `${localeString(
'views.Channel.inboundCapacity'
)} (${localeString('views.Channel.SortButton.smallestFirst')})`,
value: { param: 'remoteBalance', dir: 'ASC', type: 'numeric' }
},
{
key: `${localeString(
'views.Channel.outboundCapacity'
)} (${localeString('views.Channel.SortButton.largestFirst')})`,
value: { param: 'localBalance', dir: 'DESC', type: 'numeric' }
},
{
key: `${localeString(
'views.Channel.outboundCapacity'
)} (${localeString('views.Channel.SortButton.smallestFirst')})`,
value: { param: 'localBalance', dir: 'ASC', type: 'numeric' }
},
{
key: `${localeString('views.Channel.displayName')} (${localeString(
'views.Channel.SortButton.ascending'
)})`,
value: {
param: 'displayName',
dir: 'ASC',
type: 'alphanumeric'
}
},
{
key: `${localeString('views.Channel.displayName')} (${localeString(
'views.Channel.SortButton.descending'
)})`,
value: {
param: 'displayName',
dir: 'DESC',
type: 'alphanumeric'
}
}
);

return sortKeys;
};

interface ChannelsFilterProps {
width?: string | number;
}

const ChannelsFilter = (props: ChannelsFilterProps) => {
const { channelsStore } = stores;
const { search, setSort, channelsType } = channelsStore;
const windowWidth = Dimensions.get('window').width;
return (
<View>
<Row>
<SearchBar
placeholder={localeString('general.search')}
onChangeText={(value: string) =>
channelsStore!.setSearch(value)
}
value={search}
inputStyle={{
color: themeColor('text'),
fontFamily: 'PPNeueMontreal-Book'
}}
placeholderTextColor={themeColor('secondaryText')}
containerStyle={{
backgroundColor: null,
borderTopWidth: 0,
borderBottomWidth: 0,
width: props.width || windowWidth - 55
}}
inputContainerStyle={{
borderRadius: 15,
backgroundColor: themeColor('secondary')
}}
autoCapitalize="none"
/>
<SortButton
onValueChange={(value: any) => {
setSort(value);
}}
values={getChannelsSortKeys(
channelsType === ChannelsType.Closed
)}
/>
</Row>
<FilterOptions ChannelsStore={channelsStore!} />
</View>
);
};

export default ChannelsFilter;
3 changes: 3 additions & 0 deletions components/HopPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { localeString } from '../utils/LocaleUtils';

import Button from '../components/Button';
import { ChannelItem } from './Channels/ChannelItem';
import ChannelsFilter from './Channels/ChannelsFilter';

import Channel from '../models/Channel';

Expand Down Expand Up @@ -148,6 +149,8 @@ export default class ChannelPicker extends React.Component<
)}
</Text>

<ChannelsFilter width="86%" />

<FlatList
data={channels}
renderItem={(item) => this.renderItem(item)}
Expand Down
147 changes: 5 additions & 142 deletions views/Channels/ChannelsPane.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
import * as React from 'react';
import { Dimensions, FlatList, View, TouchableHighlight } from 'react-native';
import { SearchBar } from 'react-native-elements';
import { FlatList, View, TouchableHighlight } from 'react-native';
import { inject, observer } from 'mobx-react';
import { duration } from 'moment';

import { ChannelsHeader } from '../../components/Channels/ChannelsHeader';
import { ChannelItem } from '../../components/Channels/ChannelItem';
import SortButton from '../../components/Channels/SortButton';
import { FilterOptions } from '../../components/Channels/FilterOptions';
import ChannelsFilter from '../../components/Channels/ChannelsFilter';

import LoadingIndicator from '../../components/LoadingIndicator';
import WalletHeader from '../../components/WalletHeader';
import { Row } from '../../components/layout/Row';
import { Spacer } from '../../components/layout/Spacer';

import ChannelsStore, { ChannelsType } from '../../stores/ChannelsStore';
import SettingsStore from '../../stores/SettingsStore';

import BackendUtils from '../../utils/BackendUtils';
import { localeString } from '../../utils/LocaleUtils';
import { themeColor } from '../../utils/ThemeUtils';

import Channel from '../../models/Channel';

Expand All @@ -42,101 +38,9 @@ interface ChannelsProps {
@inject('ChannelsStore', 'SettingsStore')
@observer
export default class ChannelsPane extends React.PureComponent<ChannelsProps> {
private getChannelsSortKeys = (closed?: boolean) => {
const sortKeys = [];

if (closed) {
sortKeys.push(
{
key: `${localeString(
'views.Channel.closeHeight'
)} (${localeString('views.Channel.SortButton.ascending')})`,
value: { param: 'closeHeight', dir: 'ASC', type: 'numeric' }
},
{
key: `${localeString(
'views.Channel.closeHeight'
)} (${localeString(
'views.Channel.SortButton.descending'
)})`,
value: {
param: 'closeHeight',
dir: 'DESC',
type: 'numeric'
}
}
);
}

sortKeys.push(
{
key: `${localeString('views.Channel.capacity')} (${localeString(
'views.Channel.SortButton.largestFirst'
)})`,
value: {
param: 'channelCapacity',
dir: 'DESC',
type: 'numeric'
}
},
{
key: `${localeString('views.Channel.capacity')} (${localeString(
'views.Channel.SortButton.smallestFirst'
)})`,
value: { param: 'channelCapacity', dir: 'ASC', type: 'numeric' }
},
{
key: `${localeString(
'views.Channel.inboundCapacity'
)} (${localeString('views.Channel.SortButton.largestFirst')})`,
value: { param: 'remoteBalance', dir: 'DESC', type: 'numeric' }
},
{
key: `${localeString(
'views.Channel.inboundCapacity'
)} (${localeString('views.Channel.SortButton.smallestFirst')})`,
value: { param: 'remoteBalance', dir: 'ASC', type: 'numeric' }
},
{
key: `${localeString(
'views.Channel.outboundCapacity'
)} (${localeString('views.Channel.SortButton.largestFirst')})`,
value: { param: 'localBalance', dir: 'DESC', type: 'numeric' }
},
{
key: `${localeString(
'views.Channel.outboundCapacity'
)} (${localeString('views.Channel.SortButton.smallestFirst')})`,
value: { param: 'localBalance', dir: 'ASC', type: 'numeric' }
},
{
key: `${localeString(
'views.Channel.displayName'
)} (${localeString('views.Channel.SortButton.ascending')})`,
value: {
param: 'displayName',
dir: 'ASC',
type: 'alphanumeric'
}
},
{
key: `${localeString(
'views.Channel.displayName'
)} (${localeString('views.Channel.SortButton.descending')})`,
value: {
param: 'displayName',
dir: 'DESC',
type: 'alphanumeric'
}
}
);

return sortKeys;
};

renderItem = ({ item }: { item: Channel }) => {
const { ChannelsStore, navigation } = this.props;
const { largestChannelSats, channelsType } = ChannelsStore;
const { largestChannelSats, channelsType } = ChannelsStore!;

const getStatus = () => {
if (item.isActive) {
Expand Down Expand Up @@ -231,10 +135,8 @@ export default class ChannelsPane extends React.PureComponent<ChannelsProps> {
filteredChannels,
filteredPendingChannels,
filteredClosedChannels,
setSort,
showSearch,
channelsType,
search
channelsType
} = ChannelsStore!;

const lurkerMode: boolean =
Expand Down Expand Up @@ -263,8 +165,6 @@ export default class ChannelsPane extends React.PureComponent<ChannelsProps> {
break;
}

const windowWidth = Dimensions.get('window').width;

return (
<View style={{ flex: 1 }}>
<WalletHeader
Expand All @@ -283,44 +183,7 @@ export default class ChannelsPane extends React.PureComponent<ChannelsProps> {
totalOffline={totalOffline}
lurkerMode={lurkerMode}
/>
{showSearch && (
<View>
<Row>
<SearchBar
placeholder={localeString('general.search')}
onChangeText={this.updateSearch}
value={search}
inputStyle={{
color: themeColor('text'),
fontFamily: 'PPNeueMontreal-Book'
}}
placeholderTextColor={themeColor(
'secondaryText'
)}
containerStyle={{
backgroundColor: null,
borderTopWidth: 0,
borderBottomWidth: 0,
width: windowWidth - 55
}}
inputContainerStyle={{
borderRadius: 15,
backgroundColor: themeColor('secondary')
}}
autoCapitalize="none"
/>
<SortButton
onValueChange={(value: any) => {
setSort(value);
}}
values={this.getChannelsSortKeys(
channelsType === ChannelsType.Closed
)}
/>
</Row>
<FilterOptions ChannelsStore={ChannelsStore!} />
</View>
)}
{showSearch && <ChannelsFilter />}
{loading ? (
<View style={{ marginTop: 40 }}>
<LoadingIndicator />
Expand Down

0 comments on commit 2352087

Please sign in to comment.