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 fa77e528f228c0ae211a20e024626ddeb397821e
parent 2431c215ddd5067f93416c26733768363a2ff318
Author: Johan Lindskogen <johan.lindskogen@gmail.com>
Date:   Sun,  1 Apr 2018 18:08:11 +0200

Send message to buffer, dismiss keyboard when menu open

Diffstat:
Msrc/usecase/App.tsx | 24++++++++++++++++++++----
Msrc/usecase/buffers/ui/BufferContainer.tsx | 28++++++++++++++++++++++++++--
2 files changed, 46 insertions(+), 6 deletions(-)

diff --git a/src/usecase/App.tsx b/src/usecase/App.tsx @@ -4,7 +4,8 @@ import { View, Text, TouchableOpacity, - StyleSheet + StyleSheet, + Keyboard } from "react-native"; import { connect } from "react-redux"; import * as _ from "lodash"; @@ -21,14 +22,15 @@ interface Props { buffers: WeechatBuffer[]; currentBufferId: string | null; currentBuffer: WeechatBuffer | null; - fetchLinesForBuffer: (string) => void; + fetchLinesForBuffer: (bufferId: string) => void; + sendMessageToBuffer: (fullBufferName: string, message: string) => void; dispatch: (any) => void; } class App extends React.Component<Props> { drawer: Drawer; - changeCurrentBuffer = buffer => { + changeCurrentBuffer = (buffer: WeechatBuffer) => { const { currentBufferId, fetchLinesForBuffer } = this.props; this.drawer.close(); @@ -40,6 +42,19 @@ class App extends React.Component<Props> { fetchLinesForBuffer(buffer.id); } }; + + openDrawer = () => { + this.drawer.open(); + Keyboard.dismiss(); + }; + + sendMessage = (message: string) => { + const { currentBuffer, sendMessageToBuffer } = this.props; + console.log(this.props); + + sendMessageToBuffer(currentBuffer.full_name, message); + }; + render() { const { buffers, @@ -73,7 +88,7 @@ class App extends React.Component<Props> { <View style={styles.channels}> <TouchableOpacity style={styles.channelsButton} - onPress={() => this.drawer.open()} + onPress={this.openDrawer} > <Text style={styles.channelsButtonText}>#</Text> </TouchableOpacity> @@ -86,6 +101,7 @@ class App extends React.Component<Props> { <View style={styles.channels} /> </View> <BufferContainer + sendMessage={this.sendMessage} fetchLinesForBuffer={fetchLinesForBuffer} bufferId={currentBufferId} /> diff --git a/src/usecase/buffers/ui/BufferContainer.tsx b/src/usecase/buffers/ui/BufferContainer.tsx @@ -24,16 +24,19 @@ import { formatUrl } from "../../../lib/helpers/url-formatter"; interface Props { bufferId: string; - fetchLinesForBuffer: (string) => void; + fetchLinesForBuffer: (bufferId: string) => void; + sendMessage: (message: string) => void; } interface State { inputWidth: Animated.Value; + textValue: string; } export default class BufferContainer extends React.Component<Props, State> { state = { - inputWidth: new Animated.Value(350) + inputWidth: new Animated.Value(350), + textValue: "" }; handleOnFocus() { @@ -68,8 +71,24 @@ export default class BufferContainer extends React.Component<Props, State> { Linking.openURL(formatUrl(type, text)); } } + + handleChangeText = (textValue: string) => { + this.setState({ + textValue + }); + }; + + handleSubmit = () => { + const { textValue } = this.state; + this.props.sendMessage(textValue); + this.setState({ + textValue: "" + }); + }; + render() { const { bufferId } = this.props; + const { textValue } = this.state; if (!bufferId) { return <View style={styles.container} />; @@ -90,8 +109,13 @@ export default class BufferContainer extends React.Component<Props, State> { <Animated.View style={{ width: this.state.inputWidth }}> <TextInput style={styles.inputBox} + value={textValue} + onChangeText={this.handleChangeText} onFocus={() => this.handleOnFocus()} onBlur={() => this.handleOnBlur()} + returnKeyType="send" + blurOnSubmit={false} + onSubmitEditing={this.handleSubmit} /> </Animated.View> </View>