weechatRN

Weechat relay client for iOS using websockets https://github.com/mhoran/weechatRN
git clone http://git.hanabi.in/repos/weechatRN.git
Log | Files | Refs | README | LICENSE

commit 67ac8aab3fe3baea695c15768a3765f229b41453
parent bdf45f88ea03a897420273400c567bda07dfe755
Author: Matthew Horan <matt@matthoran.com>
Date:   Mon, 21 Jan 2019 12:12:44 -0500

Add option to filter server buffers

Just like weechat-android, it's now possible to exclude server buffers
from the buffer list.

Server buffers with activity will be shown, until opened.

Diffstat:
Msrc/store/connection-info.ts | 7+++++--
Msrc/usecase/buffers/ui/BufferList.tsx | 19+++++++++++++++++--
Msrc/usecase/login/LoginForm.tsx | 30+++++++++++++++++++++++++-----
3 files changed, 47 insertions(+), 9 deletions(-)

diff --git a/src/store/connection-info.ts b/src/store/connection-info.ts @@ -2,12 +2,14 @@ export type ConnectionInfo = { hostname: string | null; password: string | null; ssl: boolean; + filterBuffers: boolean; }; const initialState: ConnectionInfo = { hostname: null, password: null, - ssl: true + ssl: true, + filterBuffers: true }; export default (state: ConnectionInfo = initialState, action) => { @@ -16,7 +18,8 @@ export default (state: ConnectionInfo = initialState, action) => { return { hostname: action.hostname, password: action.password, - ssl: action.ssl + ssl: action.ssl, + filterBuffers: action.filterBuffers }; case "CLEAR_CONNECTION_INFO": return initialState; diff --git a/src/usecase/buffers/ui/BufferList.tsx b/src/usecase/buffers/ui/BufferList.tsx @@ -16,6 +16,7 @@ interface Props { currentBufferId: string | null; onSelectBuffer: (b: WeechatBuffer) => any; hotlists: HotListState; + filterBuffers: boolean; } const keyExtractor = (buffer: WeechatBuffer): string => buffer.id; @@ -33,6 +34,19 @@ class BufferList extends React.Component<Props> { /> ); }; + + visibleBuffer = (buffer: WeechatBuffer) => { + const { filterBuffers, hotlists } = this.props; + + if (filterBuffers) { + return buffer.local_variables.type != "server" && + buffer.local_variables.type != null || + hotlists[buffer.id] && hotlists[buffer.id].sum != 0; + } else { + return true; + } + } + render() { const { buffers } = this.props; @@ -41,7 +55,7 @@ class BufferList extends React.Component<Props> { <View style={styles.topbar} /> <FlatList style={styles.container} - data={buffers} + data={buffers.filter(this.visibleBuffer)} keyExtractor={keyExtractor} renderItem={this.renderListItem} /> @@ -51,7 +65,8 @@ class BufferList extends React.Component<Props> { } export default connect((state: StoreState) => ({ - hotlists: state.hotlists + hotlists: state.hotlists, + filterBuffers: state.connection.filterBuffers }))(BufferList); const styles = StyleSheet.create({ diff --git a/src/usecase/login/LoginForm.tsx b/src/usecase/login/LoginForm.tsx @@ -19,19 +19,22 @@ interface Props { hostname: string; password: string; ssl: boolean; + filterBuffers: boolean; dispatch: (any) => void; } interface State { hostname: string; password: string; ssl: boolean; + filterBuffers: boolean; } class LoginForm extends React.Component<Props, State> { state: State = { hostname: "", password: "", - ssl: true + ssl: true, + filterBuffers: true }; static getDerivedStateFromProps(nextProps: Props, prevState: State) { @@ -40,7 +43,8 @@ class LoginForm extends React.Component<Props, State> { ...prevState, hostname: nextProps.hostname, password: nextProps.password, - ssl: nextProps.ssl + ssl: nextProps.ssl, + filterBuffers: nextProps.filterBuffers }; } else { return null; @@ -52,7 +56,8 @@ class LoginForm extends React.Component<Props, State> { type: "SET_CONNECTION_INFO", hostname: this.state.hostname, password: this.state.password, - ssl: this.state.ssl + ssl: this.state.ssl, + filterBuffers: this.state.filterBuffers }); const { hostname, password, ssl } = this.state; this.props.onConnect(hostname, password, ssl); @@ -70,9 +75,13 @@ class LoginForm extends React.Component<Props, State> { this.setState({ ssl }); }; + setFilterBuffers = (filterBuffers: boolean) => { + this.setState({ filterBuffers }); + }; + render() { const { children, connecting } = this.props; - const { hostname, password, ssl } = this.state; + const { hostname, password, ssl, filterBuffers } = this.state; return ( <View style={styles.container}> @@ -109,6 +118,16 @@ class LoginForm extends React.Component<Props, State> { onValueChange={this.setSSL} /> </View> + <View + style={{ flexDirection: "row", justifyContent: "space-between" }} + > + <Text style={styles.text}>Hide server buffers</Text> + <Switch + style={{ margin: 10 }} + value={filterBuffers} + onValueChange={this.setFilterBuffers} + /> + </View> <View style={styles.centeredButton}> <TouchableOpacity disabled={connecting} @@ -131,7 +150,8 @@ class LoginForm extends React.Component<Props, State> { export default connect((state: StoreState) => ({ hostname: state.connection.hostname, password: state.connection.password, - ssl: state.connection.ssl + ssl: state.connection.ssl, + filterBuffers: state.connection.filterBuffers }))(LoginForm); const styles = StyleSheet.create({