Skip to content

Commit

Permalink
toggle conversation pane
Browse files Browse the repository at this point in the history
  • Loading branch information
trazyn committed Aug 26, 2017
1 parent 8c59b2b commit 3a91fff
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 3 deletions.
11 changes: 11 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,17 @@ function createMenu() {
mainWindow.webContents.send('show-contacts');
}
},
{
label: 'Toggle Conversation',
accelerator: 'Shift+Cmd+M',
click() {
mainWindow.show();
mainWindow.webContents.send('show-conversation');
}
},
{
type: 'separator',
},
{
role: 'toggledevtools'
},
Expand Down
12 changes: 12 additions & 0 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,23 @@ class App extends Component {
stores.newchat.toggle(true);
});

ipcRenderer.on('show-conversation', () => {
if (this.refs.navigator.state.location.pathname === '/'
&& stores.chat.user) {
stores.chat.toggleConversation();
}
});

ipcRenderer.on('show-search', () => {
this.refs.navigator.router.push('/');
stores.chat.toggleConversation(true);

setTimeout(() => document.querySelector('#search').focus());
});

ipcRenderer.on('show-messages', () => {
this.refs.navigator.router.push('/');
stores.chat.toggleConversation(true);
});

ipcRenderer.on('show-contacts', () => {
Expand All @@ -52,11 +62,13 @@ class App extends Component {

ipcRenderer.on('show-next', () => {
this.refs.navigator.router.push('/');
stores.chat.toggleConversation(true);
setTimeout(stores.chat.chatToNext);
});

ipcRenderer.on('show-previous', () => {
this.refs.navigator.router.push('/');
stores.chat.toggleConversation(true);
setTimeout(stores.chat.chatToPrev);
});

Expand Down
20 changes: 18 additions & 2 deletions src/js/pages/Home/ChatContent/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ import { on, off } from 'utils/event';
showAddFriend: (user) => stores.addfriend.toggle(true, user),
recallMessage: stores.chat.recallMessage,
downloads: stores.settings.downloads,
showConversation: stores.chat.showConversation,
toggleConversation: stores.chat.toggleConversation,
}))
@observer
export default class ChatContent extends Component {
Expand Down Expand Up @@ -452,6 +454,15 @@ export default class ChatContent extends Component {
showMenu() {
var user = this.props.user;
var menu = new remote.Menu.buildFromTemplate([
{
label: 'Toggle the conversation',
click: () => {
this.props.toggleConversation();
}
},
{
type: 'separator',
},
{
label: 'Empty Content',
click: () => {
Expand Down Expand Up @@ -548,14 +559,19 @@ export default class ChatContent extends Component {
}

render() {
var { loading, user, messages } = this.props;
var { loading, showConversation, user, messages } = this.props;
var title = user.RemarkName || user.NickName;
var signature = user.Signature;

if (loading) return false;

return (
<div className={clazz(classes.container, { [classes.notfound]: !user })} onClick={e => this.handleClick(e)}>
<div
className={clazz(classes.container, {
[classes.notfound]: !user,
[classes.hideConversation]: !showConversation,
})}
onClick={e => this.handleClick(e)}>
{
user ? (
<div>
Expand Down
7 changes: 7 additions & 0 deletions src/js/pages/Home/ChatContent/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@
}
}

.container.hideConversation {
& .signature,
& header p {
max-width: calc(100vw - 60px);
}
}

.inner {
display: flex;
justify-content: center;
Expand Down
11 changes: 10 additions & 1 deletion src/js/pages/Home/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

import React, { Component } from 'react';
import { inject, observer } from 'mobx-react';
import clazz from 'classname';

import classes from './style.css';
import Loader from 'components/Loader';
Expand All @@ -10,15 +11,23 @@ import ChatContent from './ChatContent';

@inject(stores => ({
loading: stores.session.loading,
showConversation: stores.chat.showConversation,
toggleConversation: stores.chat.toggleConversation,
newChat: () => stores.newchat.toggle(true),
}))
@observer
export default class Home extends Component {
componentDidMount() {
this.props.toggleConversation(true);
}

render() {
return (
<div className={classes.container}>
<Loader show={this.props.loading} fullscreen={true} />
<div className={classes.inner}>
<div className={clazz(classes.inner, {
[classes.hideConversation]: !this.props.showConversation
})}>
<div className={classes.left}>
<SearchBar />
<Chats />
Expand Down
10 changes: 10 additions & 0 deletions src/js/pages/Home/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@
justify-content: space-between;
}

.inner.hideConversation {
& .left {
display: none;
}

& .right {
width: 100vw;
}
}

.left {
position: relative;
width: 311px;
Expand Down
5 changes: 5 additions & 0 deletions src/js/stores/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ class Chat {
@observable sessions = [];
@observable messages = new Map();
@observable user = false;
@observable showConversation = true;

@action toggleConversation(show = !self.showConversation) {
self.showConversation = show;
}

@action async loadChats(chatSet) {
var list = contacts.memberList;
Expand Down

0 comments on commit 3a91fff

Please sign in to comment.