commit 9207f469c411ef1a84c696a905470b5cab0942d6
parent a522a41e410bb9790df93640fd8bf205a5eabba0
Author: Johan Lindskogen <johan.lindskogen@gmail.com>
Date:   Wed,  4 Apr 2018 23:09:09 +0200
Show topic under header
Diffstat:
2 files changed, 37 insertions(+), 4 deletions(-)
diff --git a/src/usecase/App.tsx b/src/usecase/App.tsx
@@ -17,6 +17,7 @@ import { changeCurrentBuffer } from "./buffers/actions/BufferActions";
 import BufferContainer from "./buffers/ui/BufferContainer";
 import BufferList from "./buffers/ui/BufferList";
 import { StoreState } from "../store";
+import { renderWeechatFormat } from "../lib/weechat/color-formatter";
 
 interface Props {
   buffers: { [key: string]: WeechatBuffer };
@@ -28,9 +29,17 @@ interface Props {
   dispatch: (any) => void;
 }
 
-class App extends React.Component<Props> {
+interface State {
+  showTopic: boolean;
+}
+
+class App extends React.Component<Props, State> {
   drawer: Drawer;
 
+  state: State = {
+    showTopic: false
+  };
+
   changeCurrentBuffer = (buffer: WeechatBuffer) => {
     const { currentBufferId, fetchLinesForBuffer } = this.props;
 
@@ -45,6 +54,12 @@ class App extends React.Component<Props> {
     }
   };
 
+  toggleShowTopic = () => {
+    this.setState(state => ({
+      showTopic: !state.showTopic
+    }));
+  };
+
   openDrawer = () => {
     this.drawer.open();
     Keyboard.dismiss();
@@ -64,6 +79,8 @@ class App extends React.Component<Props> {
       fetchLinesForBuffer
     } = this.props;
 
+    const { showTopic } = this.state;
+
     const sidebar = (
       <BufferList
         buffers={_.orderBy(_.values(buffers), ["number"])}
@@ -94,14 +111,16 @@ class App extends React.Component<Props> {
                   <Text style={styles.channelsButtonText}>#</Text>
                 </TouchableOpacity>
               </View>
-              <View>
+              <TouchableOpacity onPress={this.toggleShowTopic}>
                 <Text style={styles.topbarText}>
                   {currentBuffer && currentBuffer.short_name}
                 </Text>
-              </View>
+              </TouchableOpacity>
               <View style={styles.channels} />
             </View>
             <BufferContainer
+              showTopic={showTopic}
+              buffer={currentBuffer}
               sendMessage={this.sendMessage}
               fetchLinesForBuffer={fetchLinesForBuffer}
               bufferId={currentBufferId}
diff --git a/src/usecase/buffers/ui/BufferContainer.tsx b/src/usecase/buffers/ui/BufferContainer.tsx
@@ -10,10 +10,12 @@ import {
   TextInput,
   Easing,
   View,
+  Text,
   EmitterSubscription
 } from "react-native";
 
 import { connect } from "react-redux";
+import ParsedText from "react-native-parsed-text";
 
 import { changeCurrentBuffer } from "../actions/BufferActions";
 
@@ -21,9 +23,12 @@ import BufferLine from "./BufferLine";
 import Buffer from "./Buffer";
 import { getParseArgs } from "../../../lib/helpers/parse-text-args";
 import { formatUrl } from "../../../lib/helpers/url-formatter";
+import { renderWeechatFormat } from "../../../lib/weechat/color-formatter";
 
 interface Props {
+  buffer: WeechatBuffer | null;
   bufferId: string;
+  showTopic: boolean;
   fetchLinesForBuffer: (bufferId: string) => void;
   sendMessage: (message: string) => void;
 }
@@ -95,7 +100,7 @@ export default class BufferContainer extends React.Component<Props, State> {
   onLongPress = (line: WeechatLine) => {};
 
   render() {
-    const { bufferId } = this.props;
+    const { bufferId, buffer, showTopic } = this.props;
     const { textValue } = this.state;
 
     if (!bufferId) {
@@ -104,6 +109,15 @@ export default class BufferContainer extends React.Component<Props, State> {
 
     return (
       <KeyboardAvoidingView style={styles.container} behavior="padding">
+        {showTopic && (
+          <View>
+            <Text>
+              {renderWeechatFormat(buffer.title).map((props, index) => (
+                <ParsedText {...props} key={index} parse={this.parseArgs} />
+              ))}
+            </Text>
+          </View>
+        )}
         <Buffer
           bufferId={bufferId}
           onLongPress={this.onLongPress}