Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open new Room #14

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion web/sidebar/Sidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Immutable from 'immutable';
import Config from '../config';

import SidebarRoomRoom from './SidebarRoom';
import { SidebarRoomHeader } from './SidebarRoomHeader';

import { scrollToRoomNameReset } from '../redux/actions/scroll-actions';
import { getSidebarOpen, getScrollToRoomName } from '../redux/selectors/ui-selectors';
Expand All @@ -28,7 +29,7 @@ class Sidebar extends Component {
return (
<ul id="roomlist" className="nav">
<li key="your-rooms" className="hidden-folded padder m-t m-b-sm text-muted text-xs">
<span style={yourRoomsStyles}>Your Rooms</span>
<SidebarRoomHeader styles={yourRoomsStyles} />
</li>
{
this.props.roomList.toArray().map((room) => {
Expand Down
80 changes: 80 additions & 0 deletions web/sidebar/SidebarRoomHeader.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import React, { Component } from 'react';

export class SidebarRoomHeader extends Component {
constructor() {
super();
this.toggleRoomInput = this.toggleRoomInput.bind(this);
this.mouseOver = this.mouseOver.bind(this);
this.mouseOut = this.mouseOut.bind(this);
this.handleChange = this.handleChange.bind(this);
this.handlePressedEnter = this.handlePressedEnter.bind(this);

this.state = {
value: '',
hover: false,
isInputVisible: false
};
}

getRoomInput() {
const groupStyles = { margin: '5px 0' };

return (
<div className="input-group" style={groupStyles}>
<div className="input-group-addon">#</div>
<input type="text" className="form-control input-sm" placeholder="subreddit"
value={ this.state.value }
onChange={ this.handleChange }
onKeyPress={ this.handlePressedEnter }
/>
</div>
);
}

toggleRoomInput() {
const isVisible = !this.state.isInputVisible;
this.setState({ isInputVisible: isVisible });
if(!isVisible) this.setState({ value: "" });

}

mouseOver() {
this.setState({ hover: true });
}

mouseOut() {
this.setState({ hover: false });
}

handleChange(event) {
this.setState({ value: event.target.value });
}

handlePressedEnter(event) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should trigger chat-actions.handleChangeRoom here instead of doing it manually to make sure we're changing rooms all in one play. Also handleChangeRoom does some other things as well like update the lastMessageTime for the room you change to.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried that, but handleChangeRoomdidn't work with rooms that weren't in the state. I could've changed chat-actions.handleChangeRoom but I thought opening a room over the UI would be the same as using the url. This is also the way I open the room in the 'active rooms' #23 PR. I will take a look at it and update with the concrete issue.

if (event.key === 'Enter') {
const url = `${window.location.origin}/r/${this.state.value.trim()}`;
window.location.href = url;
}
}

render() {
const hovered = (this.state.hover) ? { cursor: 'pointer' } : {};
const addBtnStyle = Object.assign({ float: 'right', fontSize: '1.1em' }, hovered);
const { styles } = this.props;
const iconClasses = (this.state.isInputVisible) ? 'fa fa-close' : 'fa fa-plus';

return (
<div>
<span style={styles}>Your Rooms</span>
<span>
<i style={addBtnStyle} className={iconClasses}
onClick={this.toggleRoomInput}
onMouseOver={this.mouseOver}
onMouseOut={this.mouseOut}
></i>
</span>
{(this.state.isInputVisible) ? this.getRoomInput() : null}
</div>
);
}
}