[main] manage redirection from URL if 'gs.get.channel.get()' used in vueJS templates overrides 'gs.get.channel.active' -> now restored after fetching data [+removed blocking same-page navigation]

This commit is contained in:
xdrm-brackets 2018-03-21 23:34:45 +01:00
parent 552c54c78c
commit 5406b38cbd
2 changed files with 49 additions and 11 deletions

View File

@ -21,6 +21,9 @@ gs.get.channel.dump = function(){};
/* (6) Initialize accessor for channel data */ /* (6) Initialize accessor for channel data */
gs.get.channel.get = function(){}; gs.get.channel.get = function(){};
/* (7) Initialize local channel opener */
gs.get.channel.open = function(){};
/* (2) Channel navigation /* (2) Channel navigation
@ -35,9 +38,9 @@ gs.get.channel.nav = function(channel_id=null){
/* (1) Get channel data */ /* (1) Get channel data */
var channel = this.get(channel_id); var channel = this.get(channel_id);
/* (3) Abort if same channel */ /* (2) Abort if same channel */
if( gs.get.router.history.current.params.link === channel.link ) // if( gs.get.router.history.current.params.link === channel.link )
return false; // return false;
/* (3) Navigate vue-router */ /* (3) Navigate vue-router */
gs.get.router.push(`/channel/${channel.link}`); gs.get.router.push(`/channel/${channel.link}`);
@ -152,8 +155,24 @@ gs.get.channel.get = function(channel_id=null){
/* (5) Open a local channel
/* (N) Manage active channel from URL *
* @type<String> Local channel type (text, voice, video)
* @id<int> Local channel id
*
---------------------------------------------------------*/ ---------------------------------------------------------*/
/* (1) Set current active channel item from URL */ gs.get.channel.open = function(type=null, id=null){
// gs.get.channel.nav();
let error = function(type){ this.get().local[type].active = null; }.bind(this, type);
/* (1) Get current channel */
let channel = this.get();
/* (2) Manage invalid @type */
if( typeof type !== 'string' || !channel.local.hasOwnProperty(type) )
return false;
console.log(`open(${type}, ${id})`, channel.id);
};

View File

@ -24,12 +24,31 @@ new Vue({
render(h){ return h(wrapper); } render(h){ return h(wrapper); }
}) })
/* (2) Store route params */
window.initial_link = gs.get.router.history.current.params.link;
console.log(`[channel.URL] ${initial_link}`);
/* (3) Channel data gathering /* (3) Channel data gathering
---------------------------------------------------------*/ ---------------------------------------------------------*/
/* (1) Fetch channel data */ /* (1) Fetch channel data */
gs.get.channel.dump( require('./mockup/channels.json') ); setTimeout(() => {
/* (2) Initialize channel_id guess */ /* (2) Fetch data */
gs.get.channel.nav(); gs.get.channel.dump( require('./mockup/channels.json') );
/* (3) Find if @link matches */
var redirect_id = null;
for( let c of gs.get.channel.list ){
if( c.link === window.initial_link ){
redirect_id = c.id;
break;
}
}
/* (4) Emulate navigatation from URL */
console.log(`[restore.channel] ${redirect_id}`);
gs.get.channel.nav(redirect_id);
}, 500);