Store selected tab in the URL
This commit is contained in:
parent
b83efcbb9e
commit
cc743a837a
@ -6,6 +6,12 @@ var tabActions = Reflux.createActions([
|
|||||||
'select'
|
'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;
|
module.exports = tabActions;
|
@ -26,7 +26,9 @@ var routes = (
|
|||||||
<Route name="app" path="/" handler={App}>
|
<Route name="app" path="/" handler={App}>
|
||||||
<Route name="connect" handler={Connect} />
|
<Route name="connect" handler={Connect} />
|
||||||
<Route name="settings" handler={Settings} />
|
<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>
|
</Route>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -45,7 +45,11 @@ messageActions.command.listen(function(line, channel, server) {
|
|||||||
case 'topic':
|
case 'topic':
|
||||||
var topic = channelStore.getTopic(server, channel);
|
var topic = channelStore.getTopic(server, channel);
|
||||||
if (topic) {
|
if (topic) {
|
||||||
messageActions.inform(topic, server, channel);
|
messageActions.add({
|
||||||
|
server: server,
|
||||||
|
to: channel,
|
||||||
|
message: topic
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
messageActions.inform('No topic set', server, channel);
|
messageActions.inform('No topic set', server, channel);
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,26 @@
|
|||||||
var React = require('react');
|
var React = require('react');
|
||||||
|
var Reflux = require('reflux');
|
||||||
|
var Router = require('react-router');
|
||||||
|
|
||||||
var ChatTitle = require('./ChatTitle.jsx');
|
var ChatTitle = require('./ChatTitle.jsx');
|
||||||
var MessageBox = require('./MessageBox.jsx');
|
var MessageBox = require('./MessageBox.jsx');
|
||||||
var MessageInput = require('./MessageInput.jsx');
|
var MessageInput = require('./MessageInput.jsx');
|
||||||
var UserList = require('./UserList.jsx');
|
var UserList = require('./UserList.jsx');
|
||||||
|
var tabActions = require('../actions/tab');
|
||||||
|
|
||||||
var Chat = React.createClass({
|
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() {
|
render: function() {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
|
@ -5,6 +5,7 @@ var selectedTabStore = require('./stores/selectedTab');
|
|||||||
var channelActions = require('./actions/channel');
|
var channelActions = require('./actions/channel');
|
||||||
var messageActions = require('./actions/message');
|
var messageActions = require('./actions/message');
|
||||||
var serverActions = require('./actions/server');
|
var serverActions = require('./actions/server');
|
||||||
|
var routeActions = require('./actions/route');
|
||||||
|
|
||||||
socket.on('join', function(data) {
|
socket.on('join', function(data) {
|
||||||
channelActions.addUser(data.user, data.server, data.channels[0]);
|
channelActions.addUser(data.user, data.server, data.channels[0]);
|
||||||
@ -70,6 +71,9 @@ socket.on('whois', function(data) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
socket.on('servers', function(data) {
|
socket.on('servers', function(data) {
|
||||||
|
if (data === null) {
|
||||||
|
routeActions.navigate('connect');
|
||||||
|
}
|
||||||
serverActions.load(data);
|
serverActions.load(data);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -7,11 +7,6 @@ var channelActions = require('../actions/channel');
|
|||||||
var serverActions = require('../actions/server');
|
var serverActions = require('../actions/server');
|
||||||
|
|
||||||
var selectedTab = {};
|
var selectedTab = {};
|
||||||
var stored = localStorage.selectedTab;
|
|
||||||
|
|
||||||
if (stored) {
|
|
||||||
selectedTab = JSON.parse(stored);
|
|
||||||
}
|
|
||||||
|
|
||||||
var selectedTabStore = Reflux.createStore({
|
var selectedTabStore = Reflux.createStore({
|
||||||
init: function() {
|
init: function() {
|
||||||
@ -19,7 +14,7 @@ var selectedTabStore = Reflux.createStore({
|
|||||||
this.listenTo(channelActions.part, 'part');
|
this.listenTo(channelActions.part, 'part');
|
||||||
this.listenTo(serverActions.disconnect, 'disconnect');
|
this.listenTo(serverActions.disconnect, 'disconnect');
|
||||||
this.listenTo(channelActions.addUser, 'userAdded');
|
this.listenTo(channelActions.addUser, 'userAdded');
|
||||||
this.listenTo(channelActions.load, 'loadChannels');
|
//this.listenTo(channelActions.load, 'loadChannels');
|
||||||
this.listenTo(serverActions.load, 'loadServers');
|
this.listenTo(serverActions.load, 'loadServers');
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -65,17 +60,18 @@ var selectedTabStore = Reflux.createStore({
|
|||||||
},
|
},
|
||||||
|
|
||||||
loadChannels: function(channels) {
|
loadChannels: function(channels) {
|
||||||
if (selectedTab.channel && !_.find(channels, { name: selectedTab.channel })) {
|
|
||||||
selectedTab.channel = null;
|
|
||||||
selectedTab.name = null;
|
|
||||||
this.trigger(selectedTab);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
loadServers: function(servers) {
|
loadServers: function(servers) {
|
||||||
if (selectedTab.server && !_.find(servers, { address: selectedTab.server })) {
|
var server = _.find(servers, { address: selectedTab.server });
|
||||||
|
|
||||||
|
if (!server) {
|
||||||
selectedTab = {};
|
selectedTab = {};
|
||||||
this.trigger(selectedTab);
|
this.trigger(selectedTab);
|
||||||
|
} else if (!selectedTab.channel) {
|
||||||
|
selectedTab.name = server.name;
|
||||||
|
this.trigger(selectedTab);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
2
irc.go
2
irc.go
@ -4,6 +4,7 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@ -236,6 +237,7 @@ func (i *IRC) recv() {
|
|||||||
for {
|
for {
|
||||||
line, err := i.reader.ReadString('\n')
|
line, err := i.reader.ReadString('\n')
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Println("IRC connection to", i.Server, "died")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user