From b01f73cc74361c11f65e4ebfb19b83bd0647951c Mon Sep 17 00:00:00 2001 From: Gabriel Henriques Date: Fri, 15 May 2020 18:58:56 -0300 Subject: [PATCH 1/2] Fix not redirecting on register --- app/ui-sidenav/client/sideNav.js | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/app/ui-sidenav/client/sideNav.js b/app/ui-sidenav/client/sideNav.js index 2f35e510f3f2..e7fc42159765 100644 --- a/app/ui-sidenav/client/sideNav.js +++ b/app/ui-sidenav/client/sideNav.js @@ -1,4 +1,5 @@ import { Meteor } from 'meteor/meteor'; +import { Tracker } from 'meteor/tracker'; import { ReactiveVar } from 'meteor/reactive-var'; import { FlowRouter } from 'meteor/kadira:flow-router'; import { Template } from 'meteor/templating'; @@ -78,20 +79,32 @@ Template.sideNav.events({ }, }); -const redirectToDefaultChannelIfNeeded = () => { - const currentRouteState = FlowRouter.current(); - const needToBeRedirect = ['/', '/home']; +const redirectToDefaultChannelIfNeeded = (firstChannel) => { + let retryCount = 0; const firstChannelAfterLogin = settings.get('First_Channel_After_Login'); - const room = roomTypes.findRoom('c', firstChannelAfterLogin, Meteor.userId()); - if (room && room._id && needToBeRedirect.includes(currentRouteState.path)) { - FlowRouter.go(`/channel/${ firstChannelAfterLogin }`); - } + const currentRouteState = FlowRouter.current(); + const needToBeRedirect = ['/', '/home'].includes(currentRouteState.path); + + Tracker.autorun((c) => { + if (!firstChannelAfterLogin || !needToBeRedirect) { c.stop(); return; } + + firstChannel.set(roomTypes.findRoom('c', firstChannelAfterLogin, Meteor.userId())); + + if (firstChannel.get() && firstChannel.get()._id && needToBeRedirect) { + c.stop(); + FlowRouter.go(`/channel/${ firstChannelAfterLogin }`); + } + + if (retryCount > 3) { c.stop(); } + retryCount++; + }); }; Template.sideNav.onRendered(function() { SideNav.init(); menu.init(); - redirectToDefaultChannelIfNeeded(); + const firstChannel = new ReactiveVar(); + redirectToDefaultChannelIfNeeded(firstChannel); return Meteor.defer(() => menu.updateUnreadBars()); }); From 7d75b33a29f6cbb9d77753d28323009846706776 Mon Sep 17 00:00:00 2001 From: Guilherme Gazzo Date: Fri, 15 May 2020 22:51:51 -0300 Subject: [PATCH 2/2] Fix review --- app/ui-sidenav/client/sideNav.js | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/app/ui-sidenav/client/sideNav.js b/app/ui-sidenav/client/sideNav.js index e7fc42159765..323895a2f288 100644 --- a/app/ui-sidenav/client/sideNav.js +++ b/app/ui-sidenav/client/sideNav.js @@ -79,32 +79,35 @@ Template.sideNav.events({ }, }); -const redirectToDefaultChannelIfNeeded = (firstChannel) => { - let retryCount = 0; - const firstChannelAfterLogin = settings.get('First_Channel_After_Login'); - const currentRouteState = FlowRouter.current(); - const needToBeRedirect = ['/', '/home'].includes(currentRouteState.path); +const redirectToDefaultChannelIfNeeded = () => { + const needToBeRedirect = () => ['/', '/home'].includes(FlowRouter.current().path); Tracker.autorun((c) => { - if (!firstChannelAfterLogin || !needToBeRedirect) { c.stop(); return; } + const firstChannelAfterLogin = settings.get('First_Channel_After_Login'); - firstChannel.set(roomTypes.findRoom('c', firstChannelAfterLogin, Meteor.userId())); + if (!needToBeRedirect()) { + return c.stop(); + } + + if (!firstChannelAfterLogin) { + return c.stop(); + } + + const room = roomTypes.findRoom('c', firstChannelAfterLogin, Meteor.userId()); - if (firstChannel.get() && firstChannel.get()._id && needToBeRedirect) { - c.stop(); - FlowRouter.go(`/channel/${ firstChannelAfterLogin }`); + if (!room) { + return; } - if (retryCount > 3) { c.stop(); } - retryCount++; + c.stop(); + FlowRouter.go(`/channel/${ firstChannelAfterLogin }`); }); }; Template.sideNav.onRendered(function() { SideNav.init(); menu.init(); - const firstChannel = new ReactiveVar(); - redirectToDefaultChannelIfNeeded(firstChannel); + redirectToDefaultChannelIfNeeded(); return Meteor.defer(() => menu.updateUnreadBars()); });