Store selected tab in the URL

This commit is contained in:
khlieng 2015-02-22 08:57:52 +01:00
parent b83efcbb9e
commit cc743a837a
7 changed files with 44 additions and 15 deletions

View File

@ -6,6 +6,12 @@ var tabActions = Reflux.createActions([
'select'
]);
tabActions.select.preEmit = () => routeActions.navigate('app');
tabActions.select.preEmit = (server, channel) => {
if (channel) {
routeActions.navigate('/' + server + '/' + channel.slice(1))
} else {
routeActions.navigate('/' + server);
}
};
module.exports = tabActions;

View File

@ -26,7 +26,9 @@ var routes = (
<Route name="app" path="/" handler={App}>
<Route name="connect" handler={Connect} />
<Route name="settings" handler={Settings} />
<DefaultRoute handler={Chat} />
<Route name="status" path="/:server" handler={Chat} />
<Route name="chat" path="/:server/:channel" handler={Chat} />
<DefaultRoute handler={Settings} />
</Route>
);

View File

@ -45,7 +45,11 @@ messageActions.command.listen(function(line, channel, server) {
case 'topic':
var topic = channelStore.getTopic(server, channel);
if (topic) {
messageActions.inform(topic, server, channel);
messageActions.add({
server: server,
to: channel,
message: topic
});
} else {
messageActions.inform('No topic set', server, channel);
}

View File

@ -1,11 +1,26 @@
var React = require('react');
var Reflux = require('reflux');
var Router = require('react-router');
var ChatTitle = require('./ChatTitle.jsx');
var MessageBox = require('./MessageBox.jsx');
var MessageInput = require('./MessageInput.jsx');
var UserList = require('./UserList.jsx');
var tabActions = require('../actions/tab');
var Chat = React.createClass({
mixins: [Router.State],
componentWillMount: function() {
var p = this.getParams();
if (p.channel) {
tabActions.select(p.server, '#' + p.channel);
} else if (p.server) {
tabActions.select(p.server);
}
},
render: function() {
return (
<div>

View File

@ -5,6 +5,7 @@ var selectedTabStore = require('./stores/selectedTab');
var channelActions = require('./actions/channel');
var messageActions = require('./actions/message');
var serverActions = require('./actions/server');
var routeActions = require('./actions/route');
socket.on('join', function(data) {
channelActions.addUser(data.user, data.server, data.channels[0]);
@ -70,6 +71,9 @@ socket.on('whois', function(data) {
});
socket.on('servers', function(data) {
if (data === null) {
routeActions.navigate('connect');
}
serverActions.load(data);
});

View File

@ -7,11 +7,6 @@ var channelActions = require('../actions/channel');
var serverActions = require('../actions/server');
var selectedTab = {};
var stored = localStorage.selectedTab;
if (stored) {
selectedTab = JSON.parse(stored);
}
var selectedTabStore = Reflux.createStore({
init: function() {
@ -19,7 +14,7 @@ var selectedTabStore = Reflux.createStore({
this.listenTo(channelActions.part, 'part');
this.listenTo(serverActions.disconnect, 'disconnect');
this.listenTo(channelActions.addUser, 'userAdded');
this.listenTo(channelActions.load, 'loadChannels');
//this.listenTo(channelActions.load, 'loadChannels');
this.listenTo(serverActions.load, 'loadServers');
},
@ -65,17 +60,18 @@ var selectedTabStore = Reflux.createStore({
},
loadChannels: function(channels) {
if (selectedTab.channel && !_.find(channels, { name: selectedTab.channel })) {
selectedTab.channel = null;
selectedTab.name = null;
this.trigger(selectedTab);
}
},
loadServers: function(servers) {
if (selectedTab.server && !_.find(servers, { address: selectedTab.server })) {
var server = _.find(servers, { address: selectedTab.server });
if (!server) {
selectedTab = {};
this.trigger(selectedTab);
} else if (!selectedTab.channel) {
selectedTab.name = server.name;
this.trigger(selectedTab);
}
},

2
irc.go
View File

@ -4,6 +4,7 @@ import (
"bufio"
"crypto/tls"
"fmt"
"log"
"net"
"strings"
"sync"
@ -236,6 +237,7 @@ func (i *IRC) recv() {
for {
line, err := i.reader.ReadString('\n')
if err != nil {
log.Println("IRC connection to", i.Server, "died")
return
}