Skip to content

Commit

Permalink
New compose box design
Browse files Browse the repository at this point in the history
  • Loading branch information
kunall17 committed May 31, 2017
1 parent 5b291b1 commit 3b48206
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 26 deletions.
45 changes: 36 additions & 9 deletions src/compose/ComposeBox.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
/* @flow */
import React from 'react';
import { View } from 'react-native';
import { connect } from 'react-redux';

import { getAuth } from '../account/accountSelectors';
import styles from '../styles';
// import ComposeOptions from './ComposeOptions';
import ComposeText from './ComposeText';
import CameraRollView from './CameraRollView';
import ModeView from './ModeView';
import { getLastTopicInActiveNarrow } from '../chat/chatSelectors';


type Props = {
onSend: (content: string) => void,
Expand All @@ -19,8 +23,7 @@ const composeComponents = [
View,
];

export default class ComposeBox extends React.Component {

class ComposeBox extends React.Component {
props: Props;

state: {
Expand All @@ -29,23 +32,47 @@ export default class ComposeBox extends React.Component {

constructor(props: Props) {
super(props);
this.state = {
optionSelected: 0,
};
this.state = { optionSelected: 0, operator: null };
}

setOperator = (operator: string) => this.setState({ operator });

handleOptionSelected = (optionSelected: number) =>
this.setState({ optionSelected });

render() {
const { optionSelected } = this.state;
const { optionSelected, operator } = this.state;
const { auth, narrow, users } = this.props;
const ActiveComposeComponent = composeComponents[optionSelected];

return (
<View style={styles.composeBox}>
<ActiveComposeComponent />
{/* <ComposeOptions selected={optionSelected} onChange={this.handleOptionSelected} /> */}
<View style={styles.wrapper}>
<ModeView
optionSelected={optionSelected}
handleOptionSelected={this.handleOptionSelected}
setOperator={this.setOperator}
operator={operator}
users={users}
narrow={narrow}
/>
</View>
<View style={styles.divider} />
<ActiveComposeComponent
auth={auth}
narrow={narrow}
operator={operator}
/>
</View>
);
}
}

const mapStateToProps = (state) => ({
auth: getAuth(state),
narrow: state.chat.narrow,
users: state.users,
lastTopic: getLastTopicInActiveNarrow(state),
});

export default connect(mapStateToProps)(ComposeBox);
28 changes: 11 additions & 17 deletions src/compose/ComposeText.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
/* @flow */
import React from 'react';
import { StyleSheet, View, ScrollView, TextInput } from 'react-native';
import { connect } from 'react-redux';

import styles from '../styles';
import { MatchResult } from '../types';
import { Input } from '../common';
import { isStreamNarrow, isTopicNarrow, isPrivateOrGroupNarrow } from '../utils/narrow';
import { registerUserInputActivity } from '../utils/activity';
import { getAuth } from '../account/accountSelectors';
import { getLastTopicInActiveNarrow } from '../chat/chatSelectors';
import sendMessage from '../api/sendMessage';
import SendButton from './SendButton';
import getAutocompletedText from '../autocomplete/getAutocompletedText';
Expand Down Expand Up @@ -58,17 +55,23 @@ class ComposeText extends React.Component {
}

handleSend = () => {
const { auth, narrow } = this.props;
const { auth, narrow, operator } = this.props;
const { text } = this.state;

if (isPrivateOrGroupNarrow(narrow)) {
sendMessage(auth, 'private', narrow[0].operand, '', text);
} else if (isStreamNarrow(narrow)) {
sendMessage(auth, 'stream', narrow[0].operand, '(no topic)', text);
} else if (isTopicNarrow(narrow)) {
sendMessage(auth, 'stream', narrow[0].operand, narrow[1].operand, text);
} else if (isTopicNarrow(narrow) || isStreamNarrow(narrow)) {
if (operator !== null) {
sendMessage(auth, 'stream', narrow[0].operand,
(operator === '') ? '(no topic)' : operator, text);
} else if (isTopicNarrow(narrow)) {
sendMessage(auth, 'stream', narrow[0].operand, narrow[1].operand, text);
} else if (isStreamNarrow(narrow)) {
sendMessage(auth, 'stream', narrow[0].operand, '(no topic)', text);
}
}


this.clearInput();
}

Expand Down Expand Up @@ -100,7 +103,6 @@ class ComposeText extends React.Component {
const height = Math.min(Math.max(MIN_HEIGHT, contentHeight), MAX_HEIGHT);
const lastword: MatchResult = text.match(/\b(\w+)$/);
const lastWordPrefix = lastword && lastword.index && text[lastword.index - 1];

return (
<View>
{lastWordPrefix === ':' && lastword &&
Expand Down Expand Up @@ -131,11 +133,3 @@ class ComposeText extends React.Component {
);
}
}

const mapStateToProps = (state) => ({
auth: getAuth(state),
narrow: state.chat.narrow,
lastTopic: getLastTopicInActiveNarrow(state),
});

export default connect(mapStateToProps)(ComposeText);
14 changes: 14 additions & 0 deletions src/compose/ModeIcon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';
import ComposeIcon from './ComposeIcon';

export default (props) => {
switch (props.modeSelected) {
case 0:
return (<ComposeIcon name="ios-chatbubbles" onChange={props.onModeChange} />);
case 1:
return (<ComposeIcon name="ios-chatbubbles" onChange={props.onModeChange} />);
default:
return (<ComposeIcon name="bullhorn" onChange={props.onModeChange} />);

}
};
70 changes: 70 additions & 0 deletions src/compose/ModeView.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import React from 'react';
import { View, StyleSheet } from 'react-native';

import ComposeOptions from './ComposeOptions';
import ModeIcon from './ModeIcon';
import StreamBox from './ModeViews/StreamBox';
import { isTopicNarrow, isStreamNarrow } from '../utils/narrow';

const inlineStyles = StyleSheet.create({
wrapper: {
flexDirection: 'row',
},
divider: {
width: 2,
backgroundColor: '#ecf0f1',
margin: 4
},
});

export default class ModeView extends React.Component {
constructor() {
super();
this.state = {
modeSelected: 0,
};
}

handleModeChanged = () => {
const { setOperator, narrow } = this.props;
if (this.state.modeSelected === 0 && (isTopicNarrow(narrow) || isStreamNarrow(narrow))) {
if (narrow.length === 1) {
setOperator('');
} else {
setOperator(narrow[1].operand);
}
} else {
setOperator(null);
}
this.setState({
modeSelected: (this.state.modeSelected === 1) ? 0 : this.state.modeSelected + 1
});
};

render() {
const { modeSelected } = this.state;
const { setOperator, operator, optionSelected,
handleOptionSelected, narrow } = this.props;

return (
<View style={inlineStyles.wrapper}>
{(isTopicNarrow(narrow) || isStreamNarrow(narrow)) &&
<View style={inlineStyles.wrapper}>
<ModeIcon modeSelected={modeSelected} onModeChange={this.handleModeChanged} />
<View style={inlineStyles.divider} />
</View>
}
{modeSelected === 0 &&
<ComposeOptions selected={optionSelected} onChange={handleOptionSelected} />
}
{modeSelected === 1 &&
<StreamBox
operator={operator}
setOperator={setOperator}
narrow={narrow}
/>
}
</View>
);
}
}
46 changes: 46 additions & 0 deletions src/compose/ModeViews/StreamBox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import React, { Component } from 'react';
import { View, TextInput, StyleSheet } from 'react-native';

import { isTopicNarrow } from '../../utils/narrow';

const styles = StyleSheet.create({
streamInputWrapper: {
flexDirection: 'row', alignItems: 'center', flex: 1
},
topicInput: {
flex: 0.8,
margin: 2
}
});

export default class StreamBox extends Component {
componentWillReceiveProps(nextProps) {
if (this.props.narrow !== nextProps.narrow) {
if (nextProps.narrow[0].operator !== 'pm-with') {
const { setOperator } = this.props;
if (isTopicNarrow(nextProps.narrow)) {
setOperator(nextProps.narrow[1].operand);
} else {
setOperator('');
}
}
}
}

render() {
const { operator, setOperator } = this.props;
return (
<View style={styles.streamInputWrapper}>
<TextInput
ref={component => { this.operandInput = component; }}
style={styles.topicInput}
placeholder={'Topic'}
onChange={(event) => setOperator(
event.nativeEvent.text
)}
value={operator}
/>
</View>
);
}
}
7 changes: 7 additions & 0 deletions src/styles/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,11 @@ export default ({ color, backgroundColor, borderColor }) => ({
fontSize: 16,
lineHeight: 16,
},
composeInput: {
padding: 5,
fontSize: 14,
borderWidth: 0.5,
height: CONTROL_SIZE * 3 / 4,
borderColor: BORDER_COLOR,
},
});

0 comments on commit 3b48206

Please sign in to comment.