commit 3e13e736dadcb1bbe19db2e609bc11739c0a892e
parent b6e2cfca92ce4da152e4d2563821a1d05798d9ee
Author: Matthew Horan <matt@matthoran.com>
Date: Sun, 1 Nov 2020 11:14:30 -0500
Extract empty buffer view from BufferContainer
Diffstat:
3 files changed, 27 insertions(+), 13 deletions(-)
diff --git a/src/usecase/App.tsx b/src/usecase/App.tsx
@@ -15,7 +15,7 @@ import * as _ from 'lodash';
import DrawerLayout from 'react-native-drawer-layout-polyfill';
-import BufferContainer from './buffers/ui/BufferContainer';
+import BufferGate from './buffers/ui/BufferGate';
import BufferList from './buffers/ui/BufferList';
import { StoreState } from '../store';
import { registerForPushNotificationsAsync } from '../lib/helpers/push-notifications';
@@ -197,9 +197,8 @@ class App extends React.Component<Props, State> {
</TouchableOpacity>
</View>
</View>
- <BufferContainer
+ <BufferGate
showTopic={showTopic}
- buffer={currentBuffer}
sendMessage={this.sendMessage}
bufferId={currentBufferId}
/>
diff --git a/src/usecase/buffers/ui/BufferContainer.tsx b/src/usecase/buffers/ui/BufferContainer.tsx
@@ -22,17 +22,17 @@ import { StoreState } from '../../../store';
import UndoTextInput from './UndoTextInput';
const connector = connect(
- (state: StoreState, { bufferId }: { bufferId: string | null }) => ({
- lines: (bufferId && state.lines[bufferId]) || [],
- nicklist: (bufferId && state.nicklists[bufferId]) || []
+ (state: StoreState, { bufferId }: { bufferId: string }) => ({
+ lines: state.lines[bufferId] || [],
+ nicklist: state.nicklists[bufferId] || [],
+ buffer: state.buffers[bufferId]
})
);
type PropsFromRedux = ConnectedProps<typeof connector>;
type Props = PropsFromRedux & {
- buffer: WeechatBuffer | null;
- bufferId: string | null;
+ bufferId: string;
showTopic: boolean;
sendMessage: (message: string) => void;
};
@@ -172,10 +172,6 @@ class BufferContainer extends React.Component<Props, State> {
const { bufferId, buffer, showTopic, lines } = this.props;
const { textValue, showTabButton } = this.state;
- if (!bufferId) {
- return <View style={styles.container} />;
- }
-
return (
<KeyboardAvoidingView style={styles.container} behavior="padding">
{showTopic && (
@@ -222,7 +218,7 @@ class BufferContainer extends React.Component<Props, State> {
export default connector(BufferContainer);
-const styles = StyleSheet.create({
+export const styles = StyleSheet.create({
topbar: {
height: 20,
paddingHorizontal: 5,
diff --git a/src/usecase/buffers/ui/BufferGate.tsx b/src/usecase/buffers/ui/BufferGate.tsx
@@ -0,0 +1,19 @@
+import * as React from 'react';
+import { View } from 'react-native';
+import BufferContainer, { styles } from './BufferContainer';
+
+type Props = {
+ bufferId: string | null;
+ showTopic: boolean;
+ sendMessage: (message: string) => void;
+};
+
+const BufferGate = (props: Props): JSX.Element => {
+ if (props.bufferId) {
+ return <BufferContainer {...props} bufferId={props.bufferId} />;
+ } else {
+ return <View style={styles.container} />;
+ }
+};
+
+export default BufferGate;