navigation by hash works partially

This commit is contained in:
or-else
2018-04-23 19:48:57 -07:00
parent 0f08e63b6e
commit 8148d42ba7
+24 -41
View File
@@ -3799,48 +3799,36 @@
this.setState({displayMobile: mobile}); this.setState({displayMobile: mobile});
} }
}, },
// Handle for hashchange event: display appropriate panels.
handleHashRoute: function(e) { handleHashRoute: function(e) {
var hash = parseUrlHash(window.location.hash); var hash = parseUrlHash(window.location.hash);
// Left-side panel selector.
if (hash.path && hash.path.length >0) { if (hash.path && hash.path.length >0) {
switch (hash.path[0]) { if (['register','settings','edit','cred','newtpk',''].includes(hash.path[0])) {
case 'register': this.setState({sidePanelSelected: hash.path[0]});
console.log("Registration");
break;
case 'settings':
console.log("Connection settings");
break;
case 'edit':
console.log("Edit account");
break;
case 'cred':
console.log("Validate credentials");
break;
case 'newtpk':
console.log("New topic");
break;
case '':
console.log("Login or Contacts.");
break;
default:
console.log("Unknown path", hash.path[0]);
}
}
if (hash.path.length > 1) {
if (hash.path[1]) {
console.log("Set topic to", hash.path[1]);
} else { } else {
console.log("Set topic to dummy view"); console.log("Unknown sidepanel view", hash.path[0]);
} }
} }
// Topic for MessagesView selector.
if (hash.path.length > 1) {
var tp = Tinode.getTopicType(hash.path[1]);
if (tp) {
this.setState({topicSelected: hash.path[1]});
} else {
this.setState({topicSelected: null});
}
}
// Additional parameters of panels.
for (var key in hash.params) { for (var key in hash.params) {
if (hash.params.hasOwnProperty(key)) { if (hash.params.hasOwnProperty(key)) {
switch (key) { switch (key) {
case 'code': case 'code':
console.log("Validation code=", hash.params[key]); console.log("Validation code=", hash.params[key]);
break; break;
case 'meth': case 'cred':
console.log("Validation method=", hash.params[key]); this.setState({validation: hash.params[key]});
break; break;
case 'info': case 'info':
console.log("InfoView open?", hash.params[key]); console.log("InfoView open?", hash.params[key]);
@@ -3854,6 +3842,7 @@
} }
} }
}, },
handleOnline: function(online) { handleOnline: function(online) {
var newState = {liveConnection: online}; var newState = {liveConnection: online};
if (online) { if (online) {
@@ -3926,11 +3915,10 @@
}, },
handleCredentialsRequest: function(params) { handleCredentialsRequest: function(params) {
window.location.hash = composeUrlHash(["cred", this.state.topicSelected], {cred: params.cred}); var parsed = parseUrlHash(window.location.hash);
this.setState({ parsed.path[0] = 'cred';
sidePanelSelected: 'cred', parsed.params['cred'] = params.cred;
validation: params.cred window.location.hash = composeUrlHash(parsed.path, parsed.params);
});
}, },
handleLoginSuccessful: function(instance) { handleLoginSuccessful: function(instance) {
@@ -4042,7 +4030,6 @@
window.location.hash = composeUrlHash(parsed.path, parsed.params); window.location.hash = composeUrlHash(parsed.path, parsed.params);
} }
this.setState({ this.setState({
topicSelected: topicName,
mobilePanel: 'topic-view', mobilePanel: 'topic-view',
showInfoPanel: false, showInfoPanel: false,
topicSelectedOnline: online, topicSelectedOnline: online,
@@ -4058,7 +4045,6 @@
} }
// Currently selected contact deleted // Currently selected contact deleted
this.setState({ this.setState({
topicSelected: null,
mobilePanel: 'sidepanel', mobilePanel: 'sidepanel',
showInfoPanel: false, showInfoPanel: false,
topicSelectedOnline: false, topicSelectedOnline: false,
@@ -4107,7 +4093,6 @@
var parsed = parseUrlHash(window.location.hash); var parsed = parseUrlHash(window.location.hash);
parsed.path[0] = 'register'; parsed.path[0] = 'register';
window.location.hash = composeUrlHash(parsed.path, parsed.params); window.location.hash = composeUrlHash(parsed.path, parsed.params);
this.setState({sidePanelSelected: 'register'});
}, },
// Actual registration of a new account. // Actual registration of a new account.
handleNewAccountRequest: function(login_, password_, public_, cred_, tags_) { handleNewAccountRequest: function(login_, password_, public_, cred_, tags_) {
@@ -4153,7 +4138,6 @@
var parsed = parseUrlHash(window.location.hash); var parsed = parseUrlHash(window.location.hash);
parsed.path[0] = this.state.myUserId ? 'edit' : 'settings'; parsed.path[0] = this.state.myUserId ? 'edit' : 'settings';
window.location.hash = composeUrlHash(parsed.path, parsed.params); window.location.hash = composeUrlHash(parsed.path, parsed.params);
this.setState({sidePanelSelected: this.state.myUserId ? 'edit' : 'settings'});
}, },
// User updated connection parameters - transport and server address // User updated connection parameters - transport and server address
handleConnectionSettings: function(serverAddress, transport) { handleConnectionSettings: function(serverAddress, transport) {
@@ -4170,14 +4154,13 @@
delete parsed.params.tab; delete parsed.params.tab;
} }
window.location.hash = composeUrlHash(parsed.path, parsed.params); window.location.hash = composeUrlHash(parsed.path, parsed.params);
this.setState({sidePanelSelected: '', errorText: '', errorLevel: null}); this.setState({errorText: '', errorLevel: null});
}, },
// User clicked a (+) menu item. // User clicked a (+) menu item.
handleNewTopic: function() { handleNewTopic: function() {
var parsed = parseUrlHash(window.location.hash); var parsed = parseUrlHash(window.location.hash);
parsed.path[0] = 'newtpk'; parsed.path[0] = 'newtpk';
window.location.hash = composeUrlHash(parsed.path, parsed.params); window.location.hash = composeUrlHash(parsed.path, parsed.params);
this.setState({sidePanelSelected: 'newtpk'});
}, },
// Create of a new topic. New P2P topic requires peer's name. // Create of a new topic. New P2P topic requires peer's name.
handleNewTopicRequest: function(peerName, pub, priv, tags) { handleNewTopicRequest: function(peerName, pub, priv, tags) {