commit aecd0484341b987d8cfea3246aa348792ee239c3
parent b6b0828c8c6b5401141dcda932c96d2925a59151
Author: Johan Lindskogen <johan.lindskogen@gmail.com>
Date: Fri, 30 Mar 2018 17:57:46 +0200
Fetch and display buffers
Diffstat:
16 files changed, 402 insertions(+), 485 deletions(-)
diff --git a/index.js b/index.js
@@ -8,20 +8,25 @@ import { HOSTNAME, PASSWORD } from "./config";
import store from "./src/store";
import App from "./src/usecase/App";
+import ConnectionGate from "./src/usecase/ConnectionGate";
class WeechatNative extends React.Component {
componentWillMount() {
- let connection = new WeechatConnection(HOSTNAME, PASSWORD);
+ let connection = new WeechatConnection(store.dispatch, HOSTNAME, PASSWORD);
let compressed = false;
connection.connect().then(
conn => {
conn.send(
- `init password=${PASSWORD},compression=${
- compressed ? "zlib" : "off"
- }\n`
+ `init password=${PASSWORD},compression=${compressed ? "zlib" : "off"}`
);
- conn.send("(id) info version\n");
+ conn.send("(version) info version");
+ // conn.send("(hotlist) hdata hotlist:gui_hotlist(*)");
+ conn.send(
+ "(buffers) hdata buffer:gui_buffers(*) local_variables,notify,number,full_name,short_name,title,hidden,type"
+ );
+ // conn.send("(nicklist) nicklist");
+ // conn.send("sync");
},
error => {
console.log(error);
@@ -31,9 +36,9 @@ class WeechatNative extends React.Component {
render() {
return (
<Provider store={store}>
- <StatusBar barStyle="light-content">
+ <ConnectionGate>
<App />
- </StatusBar>
+ </ConnectionGate>
</Provider>
);
}
diff --git a/src/lib/weechat/action_transformer.ts b/src/lib/weechat/action_transformer.ts
@@ -0,0 +1,36 @@
+export type WeechatReduxAction = {
+ type: string;
+ payload: any;
+};
+
+const reduceToObjectByKey = <T>(array: T[], keyFn: (t: T) => string): object =>
+ array.reduce((acc, elem) => ({ ...acc, [keyFn(elem)]: elem }), {});
+
+export const transformToReduxAction = (data: WeechatResponse<any>) => {
+ if (data.id.startsWith("_")) {
+ // weechat builtin actions (resulting from sync)
+ return { type: `WEECHAT${data.id}`, payload: data.objects };
+ } else {
+ switch (data.id) {
+ case "buffers": {
+ const object = data.objects[0] as WeechatObject<WeechatBuffer[]>;
+
+ return {
+ type: "FETCH_BUFFERS",
+ payload: reduceToObjectByKey(
+ object.content,
+ buffer => buffer.pointers[0]
+ )
+ };
+ }
+ case "version": {
+ const infolist = data.objects[0] as WeechatObject<WeechatInfoList>;
+
+ return {
+ type: "FETCH_VERSION",
+ payload: infolist.content.value
+ };
+ }
+ }
+ }
+};
diff --git a/src/lib/weechat/connection.js b/src/lib/weechat/connection.js
@@ -1,31 +0,0 @@
-import { WeeChatProtocol } from "./parser";
-
-const protocol = new WeeChatProtocol();
-
-export default class WeechatConnection {
- constructor(host, password = "") {
- this.host = host;
- this.password = password;
- this.websocket = null;
- }
-
- connect() {
- return new Promise((resolve, reject) => {
- this.websocket = new WebSocket(this.host);
-
- this.websocket.onopen = () => resolve(this);
- this.websocket.onmessage = this.onmessage;
- this.websocket.onerror = reject;
- });
- }
-
- onmessage(event) {
- console.log("Recieved data:", event.data);
- console.log("Parsed data:", protocol.parse(event.data));
- }
-
- send(data) {
- console.log("Sending data:", data);
- this.websocket.send(data);
- }
-}
diff --git a/src/lib/weechat/connection.ts b/src/lib/weechat/connection.ts
@@ -0,0 +1,41 @@
+import { WeeChatProtocol } from "./parser";
+import { transformToReduxAction } from "./action_transformer";
+
+const protocol = new WeeChatProtocol();
+
+export default class WeechatConnection {
+ dispatch: any;
+ host: string;
+ password: string;
+ websocket: WebSocket;
+
+ constructor(dispatch, host, password = "") {
+ this.dispatch = dispatch;
+ this.host = host;
+ this.password = password;
+ this.websocket = null;
+ }
+
+ connect() {
+ return new Promise((resolve, reject) => {
+ this.websocket = new WebSocket(this.host);
+
+ this.websocket.onopen = () => resolve(this);
+ this.websocket.onmessage = event => this.onmessage(event);
+ this.websocket.onerror = reject;
+ });
+ }
+
+ onmessage(event) {
+ const parsed = protocol.parse(event.data) as WeechatResponse<any>;
+
+ console.log("Parsed data:", parsed);
+ const action = transformToReduxAction(parsed);
+ this.dispatch(action);
+ }
+
+ send(data) {
+ console.log("Sending data:", data);
+ this.websocket.send(data + "\n");
+ }
+}
diff --git a/src/lib/weechat/types.ts b/src/lib/weechat/types.ts
@@ -0,0 +1,51 @@
+interface WeechatResponse<T> {
+ header: Header;
+ id: string;
+ objects: WeechatObject<T>[];
+}
+
+type WeechatObjectTypeId = "hda" | "inf";
+
+interface WeechatObject<T> {
+ type: WeechatObjectTypeId;
+ content: T;
+}
+
+interface WeechatInfoList {
+ key: string;
+ value: string;
+}
+
+interface WeechatBuffer {
+ pointers: string[];
+ local_variables: Localvariables;
+ notify: number;
+ number: number;
+ full_name: string;
+ short_name: string;
+ title: string;
+ hidden: number;
+ type: number;
+}
+
+interface Localvariables {
+ plugin: string;
+ name: string;
+ server?: string;
+ type?: string;
+ charset_modifier?: string;
+ channel?: string;
+ nick?: string;
+ script_input_cb?: string;
+ script_name?: string;
+ iset_filter?: string;
+ iset_search_mode?: string;
+ iset_search_value?: string;
+ script_close_cb?: string;
+ no_log?: string;
+}
+
+interface Header {
+ length: number;
+ compression: number;
+}
diff --git a/src/store/buffers.ts b/src/store/buffers.ts
@@ -0,0 +1,12 @@
+type BufferState = { [key: string]: WeechatBuffer };
+
+const initialState: BufferState = {};
+
+export default (state: BufferState = initialState, action): BufferState => {
+ switch (action.type) {
+ case "FETCH_BUFFERS":
+ return action.payload;
+ default:
+ return state;
+ }
+};
diff --git a/src/store/index.js b/src/store/index.js
@@ -1,14 +1,21 @@
import { combineReducers, createStore, applyMiddleware } from "redux";
-import buffer from "../usecase/buffers/reducers/BufferReducer";
+import buffers from "./buffers";
-const app = (state = {}, action) => {
- return state;
+const app = (state = { connected: false }, action) => {
+ switch (action.type) {
+ case "FETCH_VERSION":
+ return {
+ connected: true
+ };
+ default:
+ return state;
+ }
};
const reducer = combineReducers({
app,
- buffer
+ buffers
});
export default createStore(
diff --git a/src/store/nicklists.js b/src/store/nicklists.js
diff --git a/src/usecase/App.js b/src/usecase/App.js
@@ -1,101 +0,0 @@
-import React from "react";
-import { View, Text, TouchableOpacity, StyleSheet } from "react-native";
-import { connect } from "react-redux";
-
-import Drawer from "react-native-drawer";
-
-import { changeCurrentBuffer } from "./buffers/actions/BufferActions";
-
-import BufferView from "./buffers/ui/BufferView";
-import BufferList from "./buffers/ui/BufferList";
-
-class App extends React.Component {
- changeCurrentBuffer(bufferName) {
- this.props.dispatch(changeCurrentBuffer(bufferName));
- this.drawer.close();
- }
- render() {
- const { buffers, currentBufferName } = this.props;
-
- const sidebar = (
- <BufferList
- buffers={buffers}
- currentBufferName={currentBufferName}
- onSelectBuffer={b => this.changeCurrentBuffer(b.name)}
- />
- );
-
- return (
- <View style={styles.container}>
- <Drawer
- type="static"
- content={sidebar}
- panOpenMask={0.03}
- tapToClose={true}
- openDrawerOffset={100}
- captureGestures={true}
- ref={d => (this.drawer = d)}
- tweenHandler={Drawer.tweenPresets.parallax}
- >
- <View style={styles.topbar}>
- <View style={styles.channels}>
- <TouchableOpacity
- style={styles.channelsButton}
- onPress={() => this.drawer.open()}
- >
- <Text style={styles.channelsButtonText}>#</Text>
- </TouchableOpacity>
- </View>
- <View>
- <Text style={styles.topbarText}>{currentBufferName}</Text>
- </View>
- <View style={styles.channels} />
- </View>
- <BufferView bufferName={currentBufferName} />
- </Drawer>
- </View>
- );
- }
-}
-
-export default connect(state => ({
- currentBufferName: state.buffer.currentBufferName,
- buffers: state.buffer.buffers
-}))(App);
-
-const styles = StyleSheet.create({
- topbar: {
- flexDirection: "row",
- paddingTop: 20,
- height: 70,
- backgroundColor: "#333",
- justifyContent: "center",
- alignItems: "center"
- },
- channels: {
- flex: 1,
- paddingHorizontal: 5
- },
- channelsButton: {
- paddingVertical: 5,
- paddingHorizontal: 10,
- width: 40
- },
- channelsButtonText: {
- textAlign: "center",
- fontSize: 20,
- fontFamily: "Gill Sans",
- color: "#eee",
- fontWeight: "bold"
- },
- topbarText: {
- color: "#eee",
- fontFamily: "Thonburi",
- fontWeight: "bold",
- fontSize: 15
- },
- container: {
- flex: 1,
- backgroundColor: "#89a"
- }
-});
diff --git a/src/usecase/App.tsx b/src/usecase/App.tsx
@@ -0,0 +1,110 @@
+import React from "react";
+import { View, Text, TouchableOpacity, StyleSheet } from "react-native";
+import { connect } from "react-redux";
+import * as _ from "lodash";
+
+import Drawer from "react-native-drawer";
+
+import { changeCurrentBuffer } from "./buffers/actions/BufferActions";
+
+import BufferView from "./buffers/ui/BufferView";
+import BufferList from "./buffers/ui/BufferList";
+
+interface Props {
+ buffers: WeechatBuffer[];
+ currentBufferName: string;
+}
+
+class App extends React.Component<Props> {
+ drawer: Drawer;
+
+ changeCurrentBuffer(bufferName) {
+ // this.props.dispatch(changeCurrentBuffer(bufferName));
+ this.drawer.close();
+ }
+ render() {
+ const { buffers, currentBufferName } = this.props;
+
+ console.log(buffers);
+
+ const sidebar = (
+ <BufferList
+ buffers={_.orderBy(buffers, ["number"])}
+ currentBufferName={currentBufferName}
+ onSelectBuffer={b => this.changeCurrentBuffer(b.short_name)}
+ />
+ );
+
+ return (
+ <View style={styles.container}>
+ <Drawer
+ type="static"
+ content={sidebar}
+ panOpenMask={0.03}
+ tapToClose={true}
+ openDrawerOffset={100}
+ captureGestures={true}
+ ref={d => (this.drawer = d)}
+ tweenHandler={Drawer.tweenPresets.parallax}
+ >
+ <View style={styles.topbar}>
+ <View style={styles.channels}>
+ <TouchableOpacity
+ style={styles.channelsButton}
+ onPress={() => this.drawer.open()}
+ >
+ <Text style={styles.channelsButtonText}>#</Text>
+ </TouchableOpacity>
+ </View>
+ <View>
+ <Text style={styles.topbarText}>{currentBufferName}</Text>
+ </View>
+ <View style={styles.channels} />
+ </View>
+ <BufferView bufferName={currentBufferName} />
+ </Drawer>
+ </View>
+ );
+ }
+}
+
+export default connect(state => ({
+ buffers: _.values(state.buffers)
+}))(App);
+
+const styles = StyleSheet.create({
+ topbar: {
+ flexDirection: "row",
+ paddingTop: 20,
+ height: 70,
+ backgroundColor: "#333",
+ justifyContent: "center",
+ alignItems: "center"
+ },
+ channels: {
+ flex: 1,
+ paddingHorizontal: 5
+ },
+ channelsButton: {
+ paddingVertical: 5,
+ paddingHorizontal: 10,
+ width: 40
+ },
+ channelsButtonText: {
+ textAlign: "center",
+ fontSize: 20,
+ fontFamily: "Gill Sans",
+ color: "#eee",
+ fontWeight: "bold"
+ },
+ topbarText: {
+ color: "#eee",
+ fontFamily: "Thonburi",
+ fontWeight: "bold",
+ fontSize: 15
+ },
+ container: {
+ flex: 1,
+ backgroundColor: "#89a"
+ }
+});
diff --git a/src/usecase/ConnectionGate.js b/src/usecase/ConnectionGate.js
@@ -0,0 +1,14 @@
+import { connect } from "react-redux";
+
+const ConnectionGate = props => {
+ console.log("connection gate", props.connected);
+ if (props.connected) {
+ return props.children;
+ } else {
+ return null;
+ }
+};
+
+export default connect(state => ({
+ connected: state.app.connected
+}))(ConnectionGate);
diff --git a/src/usecase/buffers/reducers/BufferReducer.js b/src/usecase/buffers/reducers/BufferReducer.js
@@ -1,239 +0,0 @@
-import * as actions from "../actions/BufferActions";
-
-let initialState = {
- currentBufferName: null,
- buffers: {
- "#theonechannel": {
- name: "#theonechannel",
- topic: "A topic for the one channel",
- lines: [
- { time: "09:41", nick: "bashorg", message: "http://bash.org/?244321" },
- {
- time: "09:41",
- nick: "Cthon98",
- message: "hey, if you type in your pw, it will show as stars"
- },
- { time: "09:41", nick: "Cthon98", message: "********* see!" },
- { time: "09:41", nick: "AzureDiamond", message: "hunter2" },
- {
- time: "09:41",
- nick: "AzureDiamond",
- message: "doesnt look like stars to me"
- },
- { time: "09:41", nick: "Cthon98", message: "<AzureDiamond> *******" },
- { time: "09:41", nick: "Cthon98", message: "thats what I see" },
- { time: "09:41", nick: "AzureDiamond", message: "oh, really?" },
- { time: "09:41", nick: "Cthon98", message: "Absolutely" },
- {
- time: "09:41",
- nick: "AzureDiamond",
- message: "you can go hunter2 my hunter2-ing hunter2"
- },
- {
- time: "09:41",
- nick: "AzureDiamond",
- message: "haha, does that look funny to you?"
- },
- {
- time: "09:41",
- nick: "Cthon98",
- message:
- "lol, yes. See, when YOU type hunter2, it shows to us as *******"
- },
- {
- time: "09:41",
- nick: "AzureDiamond",
- message: "thats neat, I didnt know IRC did that"
- },
- {
- time: "09:41",
- nick: "Cthon98",
- message:
- "yep, no matter how many times you type hunter2, it will show to us as *******"
- },
- { time: "09:41", nick: "AzureDiamond", message: "awesome!" },
- {
- time: "09:41",
- nick: "AzureDiamond",
- message: "wait, how do you know my pw?"
- },
- {
- time: "09:41",
- nick: "Cthon98",
- message:
- "er, I just copy pasted YOUR ******'s and it appears to YOU as hunter2 cause its your pw"
- },
- { time: "09:41", nick: "AzureDiamond", message: "oh, ok." }
- ]
- },
- "#robe&wizard": {
- name: "#robe&wizard",
- topic: "bash.org",
- lines: [
- { time: "09:41", nick: "bashorg", message: "http://bash.org/?104383" },
- {
- time: "09:41",
- nick: "bloodninja",
- message: "Baby, I been havin a tough night so treat me nice aight?"
- },
- { time: "09:41", nick: "BritneySpears14", message: "Aight." },
- {
- time: "09:41",
- nick: "bloodninja",
- message: "Slip out of those pants baby, yeah."
- },
- {
- time: "09:41",
- nick: "BritneySpears14",
- message: "I slip out of my pants, just for you, bloodninja."
- },
- {
- time: "09:41",
- nick: "bloodninja",
- message: "Oh yeah, aight. Aight, I put on my robe and wizard hat."
- },
- {
- time: "09:41",
- nick: "BritneySpears14",
- message: "Oh, I like to play dress up."
- },
- { time: "09:41", nick: "bloodninja", message: "Me too baby." },
- {
- time: "09:41",
- nick: "BritneySpears14",
- message: "I kiss you softly on your chest."
- },
- {
- time: "09:41",
- nick: "bloodninja",
- message:
- "I cast Lvl. 3 Eroticism. You turn into a real beautiful woman."
- },
- { time: "09:41", nick: "BritneySpears14", message: "Hey..." },
- {
- time: "09:41",
- nick: "bloodninja",
- message:
- "I meditate to regain my mana, before casting Lvl. 8 chicken of the Infinite."
- },
- {
- time: "09:41",
- nick: "BritneySpears14",
- message: "Funny I still don't see it."
- },
- {
- time: "09:41",
- nick: "bloodninja",
- message:
- "I spend my mana reserves to cast Mighty F*ck of the Beyondness."
- },
- {
- time: "09:41",
- nick: "BritneySpears14",
- message: "You are the worst cyber partner ever. This is ridiculous."
- },
- {
- time: "09:41",
- nick: "bloodninja",
- message:
- "Don't f*ck with me bitch, I'm the mightiest sorcerer of the lands."
- },
- {
- time: "09:41",
- nick: "bloodninja",
- message:
- "I steal yo soul and cast Lightning Lvl. 1,000,000 Your body explodes into a fine bloody mist, because you are only a Lvl. 2 Druid."
- },
- {
- time: "09:41",
- nick: "BritneySpears14",
- message: "Don't ever message me again you piece of ****."
- },
- {
- time: "09:41",
- nick: "bloodninja",
- message:
- "Robots are trying to drill my brain but my lightning shield inflicts DOA attack, leaving the robots as flaming piles of metal."
- },
- {
- time: "09:41",
- nick: "bloodninja",
- message:
- "King Arthur congratulates me for destroying Dr. Robotnik's evil army of Robot Socialist Republics. The cold war ends. Reagan steals my accomplishments and makes like it was cause of him."
- },
- {
- time: "09:41",
- nick: "bloodninja",
- message: "You still there baby? I think it's getting hard now."
- },
- { time: "09:41", nick: "bloodninja", message: "Baby?" },
- {
- time: "09:41",
- nick: "BritneySpears14",
- message: "Ok, are you ready?"
- },
- {
- time: "09:41",
- nick: "eminemBNJA",
- message: "Aight, yeah I'm ready."
- },
- {
- time: "09:41",
- nick: "BritneySpears14",
- message: "I like your music Em... Tee hee."
- },
- {
- time: "09:41",
- nick: "eminemBNJA",
- message: "huh huh, yeah, I make it for the ladies."
- },
- {
- time: "09:41",
- nick: "BritneySpears14",
- message: "Mmm, we like it a lot. Let me show you."
- },
- {
- time: "09:41",
- nick: "BritneySpears14",
- message:
- "I take off your pants, slowly, and massage your muscular physique."
- },
- {
- time: "09:41",
- nick: "eminemBNJA",
- message: "Oh I like that Baby. I put on my robe and wizard hat."
- },
- {
- time: "09:41",
- nick: "BritneySpears14",
- message: "What the f*ck, I told you not to message me again."
- },
- { time: "09:41", nick: "eminemBNJA", message: "Oh ****" },
- {
- time: "09:41",
- nick: "BritneySpears14",
- message:
- "I swear if you do it one more time I'm gonna report your ISP and say you were sending me kiddie porn you f*ck up."
- },
- { time: "09:41", nick: "eminemBNJA", message: "Oh ****" },
- {
- time: "09:41",
- nick: "eminemBNJA",
- message: "damn I gotta write down your names or something"
- }
- ]
- }
- }
-};
-
-export default (state = initialState, action) => {
- switch (action.type) {
- case actions.CHANGE_CURRENT_BUFFER:
- return {
- ...state,
- currentBufferName: action.bufferName
- };
- default:
- return state;
- }
-};
diff --git a/src/usecase/buffers/ui/Buffer.js b/src/usecase/buffers/ui/Buffer.js
@@ -1,11 +1,5 @@
import React from "react";
-import {
- StyleSheet,
- Animated,
- DeviceEventEmitter,
- ListView,
- View
-} from "react-native";
+import { StyleSheet, Animated, Keyboard, ListView, View } from "react-native";
import { connect } from "react-redux";
import AppleEasing from "react-apple-easing";
@@ -21,13 +15,11 @@ class Buffer extends React.Component {
};
componentDidMount() {
- this.cancelKeyboardWillShow = DeviceEventEmitter.addListener(
- "keyboardWillShow",
- e => this._keyboardWillShow(e)
+ this.cancelKeyboardWillShow = Keyboard.addListener("keyboardWillShow", e =>
+ this._keyboardWillShow(e)
);
- this.cancelKeyboardWillHide = DeviceEventEmitter.addListener(
- "keyboardWillHide",
- e => this._keyboardWillHide(e)
+ this.cancelKeyboardWillHide = Keyboard.addListener("keyboardWillHide", e =>
+ this._keyboardWillHide(e)
);
}
_keyboardWillShow(e) {
diff --git a/src/usecase/buffers/ui/BufferList.js b/src/usecase/buffers/ui/BufferList.js
@@ -1,82 +0,0 @@
-import React from "react";
-import {
- StyleSheet,
- Dimensions,
- Text,
- TouchableHighlight,
- ScrollView,
- View
-} from "react-native";
-
-export default class BufferList extends React.Component {
- render() {
- const { buffers, onSelectBuffer, currentBufferName } = this.props;
-
- const buffersList = Object.keys(buffers).map(key => buffers[key]);
-
- return (
- <View style={styles.container}>
- <View style={styles.topbar} />
- <ScrollView style={styles.container}>
- {buffersList.map(buffer => (
- <TouchableHighlight
- key={buffer.name}
- onPress={() => onSelectBuffer(buffer)}
- underlayColor="#F2777A"
- style={[
- styles.listItem,
- currentBufferName === buffer.name
- ? { backgroundColor: "#F2777A" }
- : null
- ]}
- >
- <View style={styles.row}>
- <View style={styles.bufferName}>
- <Text
- style={[
- styles.listItemText,
- currentBufferName !== buffer.name
- ? { color: "#888" }
- : null
- ]}
- >
- {buffer.name}
- </Text>
- </View>
- <Text style={styles.listItemText}>1</Text>
- </View>
- </TouchableHighlight>
- ))}
- </ScrollView>
- </View>
- );
- }
-}
-
-const styles = StyleSheet.create({
- container: {
- flex: 1,
- backgroundColor: "#121212"
- },
- topbar: {
- height: 30
- },
- row: {
- flexDirection: "row"
- },
- bufferName: {
- flex: 1
- },
- listItem: {
- flex: 1,
- height: 40,
- paddingHorizontal: 20,
- justifyContent: "center"
- },
- listItemText: {
- color: "#eee",
- fontFamily: "Thonburi",
- fontWeight: "bold",
- fontSize: 15
- }
-});
diff --git a/src/usecase/buffers/ui/BufferList.tsx b/src/usecase/buffers/ui/BufferList.tsx
@@ -0,0 +1,104 @@
+import React from "react";
+import {
+ StyleSheet,
+ Dimensions,
+ Text,
+ TouchableHighlight,
+ FlatList,
+ View
+} from "react-native";
+
+interface BufferListItemProps {
+ buffer: WeechatBuffer;
+ currentBufferName: string;
+ onSelectBuffer: (b: WeechatBuffer) => any;
+}
+
+const BufferListItem = ({
+ buffer,
+ currentBufferName,
+ onSelectBuffer
+}: BufferListItemProps) => (
+ <TouchableHighlight
+ onPress={() => onSelectBuffer(buffer)}
+ underlayColor="#F2777A"
+ style={[
+ styles.listItem,
+ currentBufferName === buffer.short_name
+ ? { backgroundColor: "#F2777A" }
+ : null
+ ]}
+ >
+ <View style={styles.row}>
+ <View style={styles.bufferName}>
+ <Text
+ style={[
+ styles.listItemText,
+ currentBufferName !== buffer.short_name ? { color: "#888" } : null
+ ]}
+ >
+ {buffer.short_name || buffer.full_name}
+ </Text>
+ </View>
+ <Text style={styles.listItemText}>1</Text>
+ </View>
+ </TouchableHighlight>
+);
+
+interface Props {
+ buffers: WeechatBuffer[];
+ currentBufferName: string;
+ onSelectBuffer: (b: WeechatBuffer) => any;
+}
+
+export default class BufferList extends React.Component<Props> {
+ render() {
+ const { buffers, onSelectBuffer, currentBufferName } = this.props;
+
+ return (
+ <View style={styles.container}>
+ <View style={styles.topbar} />
+ <FlatList
+ style={styles.container}
+ data={buffers}
+ keyExtractor={buffer => buffer.pointers[0]}
+ renderItem={({ item }) => (
+ <BufferListItem
+ buffer={item}
+ onSelectBuffer={onSelectBuffer}
+ currentBufferName={currentBufferName}
+ />
+ )}
+ />
+ </View>
+ );
+ }
+}
+
+const styles = StyleSheet.create({
+ container: {
+ flex: 1,
+ backgroundColor: "#121212"
+ },
+ topbar: {
+ height: 30
+ },
+ row: {
+ flexDirection: "row"
+ },
+ bufferName: {
+ flex: 1
+ },
+ listItem: {
+ flex: 1,
+ height: 40,
+ paddingHorizontal: 20,
+ justifyContent: "center"
+ },
+ listItemText: {
+ color: "#eee",
+ fontFamily: "Thonburi",
+ fontWeight: "bold",
+ fontSize: 15
+ }
+});
diff --git a/src/usecase/buffers/ui/BufferView.js b/src/usecase/buffers/ui/BufferView.js
@@ -5,7 +5,7 @@ import {
LinkingIOS,
ActionSheetIOS,
Animated,
- DeviceEventEmitter,
+ Keyboard,
TextInput,
Easing,
View
@@ -72,13 +72,11 @@ class BufferView extends React.Component {
inputWidth: new Animated.Value(350)
};
componentDidMount() {
- this.cancelKeyboardWillShow = DeviceEventEmitter.addListener(
- "keyboardWillShow",
- e => this._keyboardWillShow(e)
+ this.cancelKeyboardWillShow = Keyboard.addListener("keyboardWillShow", e =>
+ this._keyboardWillShow(e)
);
- this.cancelKeyboardWillHide = DeviceEventEmitter.addListener(
- "keyboardWillHide",
- e => this._keyboardWillHide(e)
+ this.cancelKeyboardWillHide = Keyboard.addListener("keyboardWillHide", e =>
+ this._keyboardWillHide(e)
);
}
_keyboardWillShow(e) {
@@ -159,7 +157,7 @@ class BufferView extends React.Component {
}
export default connect((state, props) => ({
- buffer: state.buffer.buffers[props.bufferName]
+ buffer: state.buffers[props.bufferName]
}))(BufferView);
const light = false;