-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Moved token and getUserQueues selectors to prevent useless side effects #556
Conversation
const Dispaly = () => | ||
function TokenList() { | ||
const tokens = useSelector(selectTokens); | ||
const ListContent = () => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using this selector in admin page was resulting in an unnecessary admin page code re-render, so moved here since only TokenList should be affected by token slice changes.
dispatch(getUserQueues()); | ||
} | ||
}, [isLoading, isAuthenticated, getUserQueues, dispatch]); | ||
const { isLoading } = useAuth0(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since Layout is used in all pages, the active queues were being fetched and the popup was showing up if we directly load any of the other pages which is not needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we would want to move this to MyQueues instead of LandingPage, since it's only used in the homePage right now, I left it in LandingPage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea here was to move all requests further up in the component tree, so the data is ready no matter what URL the user is coming from. It is a step closer to a single-page app. Currently, the home page will send unnecessary requests to the server on almost every render (as described in #545).
This can be eventually converted into PWA, so everything is loaded only once, and updated as needed.
Since re-render is cheaper than re-fetch, I would put the effort in fixing the behavior (e.g. remove the popup, update store on successful requests).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good strategy, but I'm still wondering if that should apply to requests like this one which only make sense in one route and only for admins. We would definitely have more queue members than admins, so do we really want to make the getUserQueues() request trigger for users who just want to join a queue and keep tabs on the status?
Also since this request is only needed in the homepage, do we have to worry about unnecessary re-fetches? On page refresh, it triggers each time, but we would want that for consistency's sake, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could add MyQueues to the admin panel, so an admin can quickly switch queues from the admin panel without going to the homepage. And if a user is not the admin, there will be nothing to fetch.
Also since this request is only needed in the homepage, do we have to worry about unnecessary re-fetches?
Currently, if the user switches between home and admin, the fetch is triggered every time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, if the user switches between home and admin, the fetch is triggered every time.
Oh yeah, I missed this. Leaving it in the layout is a good idea to prevent this. Good catch. I'll revert this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking of changing the popup behavior by removing the extraReducer in AppSlice and adding a popup trigger inside the MyQueues component. That way, the popup only shows up when needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, if the user switches between home and admin, the fetch is triggered every time.
Is this desirable? I think we should fetch every time home page is rendered. So can we dispatch at root of home page?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this desirable? I think we should fetch every time home page is rendered.
It would be needed for the admin to see his newly created queue in the list. I was initially thinking of leaving the dispatch in the Layout (so fetch only happens once) and manually adding to the queues state variable for all newly created queues after the fetch, but it's simpler and cleaner to re-fetch on every home page render. It isn't too big of a cost in terms of data returned and if it ever looks like that could be an issue, we can limit the number of queues an admin can own at a time.
So can we dispatch at root of home page?
Do you mean change it from the way it's written in this PR? To where?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to fetch every time the page is rendered. You fetch once the app is loaded. Then on successful add or delete, just update the state.
I moved the getUserQueues dispatch back to Layout and changed the popup to only show up from UserQueues. There's still a problem though, whenever I route back to the HompePage, I still see the /queues network call 😕. I couldn't figure out where I was going wrong. I tried removing all the dependencies of the useEffect() in Layout and I still saw the network call. Let me know if you have some ideas @daltonfury42 @mradenovic. |
I think I got the problem. The logo and the Home button work by directly changing the route and don't go through the react-router. I think this causes the whole app to re-render and cause the UseEffect to trigger. If this is really the reason, we'll need to chnage it to go through the router if we want to get rid of that fetch. |
Things should be good now. |
Check #545. I identified couple of causes for reload. |
Understood. |
setTimeout(() => { | ||
element = document.getElementById('target_how_it_works'); | ||
smoothScrollTo(element); | ||
}, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets create a util function onLoadbyId:
/**
* Execute a callback as soon as an element is available on the DOM.
*
* id - element id to wait on
* callback - callback to execute as soon as the element becomes available. The
* element is passed to the callback and it is triggered.
function onLoadById(id, callback) {
var checkAndExecute = setInterval(function() {
const element = document.getElementById(id);
if (element) {
callback(element);
clearInterval(checkAndExecute);
}
}, 100);
}
then just use it here: onLoadById('target_how_it_works', e =>smoothScrollTo(e))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The above was inspired by this, you can check if there are better ways to do this, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think as a follow up PR, we can have a single function in scrollingOperations.js
:
/**
* Smoothly scroll and take the user to a section of the page.
*
* targetElement - id of the element to scroll to
* page - Optional. The page to go to, before scrolling to the section,
* in case user is not currently on the specified page.
* history - react router history object, required if page is specified
**/
smoothScrollToSection(targetElement, page, history) {
...
}
Then we could export wrappers on top of this, smoothScrollToHomePage(id, history)
and smoothScrollWithinCurrentPage(id)
. What do you think?
Sounds good |
* Remove amplify backend (#524) * Async actions for Queue Status and My Queues API calls (#522) * Add gitter chat badge (#530) * Pick api base url from config. (#525) * Remove unused backend env amplify (#532) * Add LoadingStatus Component (#531) * Add LoadingStatus Component Upgrade storybook to 6.1.17 Fix LoadingIndicator stories Add new Loading component Use Loading wrapper in Join page Separate Loading container from presentation Add Loading stories * Pass async action to LoadingStatus * Add PropTypes to LoadingStatus * Move auth0 out of async actions. (#535) Since an async action is called whithin a hook, it is guaranteed that it will be called within a component. It doesn't need to know anything about auth0. * Use storybook for components development (#533) * Add storybook esentials addon Use essential addons to develop components in isolation. See https://storybook.js.org/docs/react/essentials/introduction. * Add redux decorator to storybook All components will be wraped in store provider. Store state can be passed to container components thru components/story parameters. * Pass string instead of function to LoadingStatus Passing function just to avoid passing string, unnecessarily complicates the component and testing. * Add LoadingStatus stories * Fix bug in Loading component Loading component was returning children as a default option. * Add PropTypes to Loading component (#536) * Update CODEOWNERS (#538) * Cleaned up lots of ugly import statements (#541) * started cleaning up imports * Cleaned up more imprts * Final import cleanup * Use async actions for token status page (#526) * Tour guide implementation: Implemented the suggested changes. (#539) * Refactor join page (#542) * Add @storybook/addon-actions back to package.json The package is installed with @storybook/addon-essentials, so it doesn't affect package-lock.json. However, eslint warns that it should be listed as dependency. * Intercept dispatch in redux store decorator In order to develop components in isolation, all async calls should be intercepted and mocked. * Rename Join page file * Update relative paths * Remove history parameter from JoinPage History is no longer dependency of useEffects(), and it is passed to the HeaderSection, but never used. * Pass queueName from url params to HeaderSection Header section is visible while loading spinner. If queue exists, the name will be same as in url params. * Add JoinPage stories * Update QueueStats stories to storybook 6.x style * Reuse sotries data in JoinPage stories * Rename Join scss file * Rename Join form * Destrurcture props in JoinForm * Fix react wornings in JoinForm Callback chained to the promise was attempting to change the form after redirect, which was causing errors in the cosnole. * Add joining case to JoinPage stories This sotry desribes state after the user click Join button, before the request is fulfilled. * added star button (#540) * added star button * added line break at bottom * Refactor home page (#544) * Rename home files * Rename Layout files * Refactor loading handling in Layout * Load user queues when isAuthenticated changes User queues were loaded on every round trip to the home page. This should be done only once when the user state is known, and on every change in user status or queue list (create/delete/pause). This also gives an opportunity to reuse MyQueues component in the Admin page. * Create alias for CreateJoinForm CreateJoinForm sounds like a function that will create JoinForm. QueueForm is a more appropriate name. It implies it's a queue Form, without explaining what form actions are. * Add MyQueues stories * Fix code style issues with Prettier Co-authored-by: Lint Action <[email protected]> * Mock auth0 in storybook (#546) * Mock auth0 in storybook This allows components that depend on auth0 to be in developed in isolation. * Fix code style issues with Prettier Co-authored-by: Lint Action <[email protected]> * Changed createJoinForm to use redux actions (#553) * Changed createJoinForm to use redux actions * Modified LoadingStatus and used in JoinPage and CreateJoinForm * Fixed a bug in fn call and a type * Refactor admin page (#550) * Rename admin page file * Add getQueue() request creator * Add getSelectedQueue async action * Add selectedQueue slice * Add mock data for testing * Add Token stories * Remove token with dispatch * Add notifyToken() request creator * Add notifyToken() async action * Notify token with dispatch * Refactor NotifyButton * Extract CallButton * Redesign RemoveButton * Disable NotifyButton while notifyToken() is pending * Refactored delete queue (#551) * Refactored AddMember to use redux actions (#552) * Refactored AddMember * Fixed some imports * Added popup for adding to queues * Disable RemoveButton while dleteToken is pending * Refactor TaskList component * Extract AdminPage HeaderSection * Refactor AdminPage component * Fix: set timeoutId before clearing it Co-authored-by: Nithin <[email protected]> * Add anonymous UUID to unauthinticated API Calls (#554) * Add anonymous UUID to unauthinticated API Calls * Update jsdoc * Fix security vulnerabilities (#557) * Moved token and getUserQueues selectors to prevent useless side effects (#556) * Moved token selector to tokenlist * Moved getUserQueues dispatch to LandingPage to prevent unneeded popup on other page loads * Removed console.log * Moved getUserQueues back to Layout and changes the popup behaviour * Changed anchor tag redirects to use react router history * Add comments to layout * Fix code style issues with Prettier * Made utility function for delayed scrolling Co-authored-by: daltonfury42 <[email protected]> Co-authored-by: Lint Action <[email protected]> * Fixed broken queue details in admin page, removed unused hooks and components (#558) * Fixed queue details breaking for admin side panel * Made a QueueDetails component for admin * Changed loading condition * Removed LoadingIndicator * Removed useRequest and RequestFactory exports * Refactor status page (#562) * Replace makeAuthedRequest with hook Since no async actions use make authed request, remove it. * Rename Status page * Rename TokenStatusPage components * Add Token stories * Rename folder Status --> TokenStatus * Reuse TokenStatus stories * Fix useDeleteQueue to immediately return expression (#566) * Fix return statement to immediately expression (#564) * Fix return statement to immediately return data (#563) * Remove Stale Comments from ErrorHandler and others (#572) * Delete unused file aws-exports.js (#571) * Revert "Fix async actions to immediately return expression" (#569) * Fix: remove commented out code (#573) * smell issue#21- return authedRequest (#574) * Footer Greeting (#575) * Change: rename files as per sonarqube (#576) * Change: rename files (#565) * Added deployment process, remove Hall of Frame (#578) * Request refresh tokens from client side (#580) * Use Typeform for Contact Us (#581) * Handle token add/remove in selectedQueueSlice (#582) * Centralised request updates and failures (#583) * Prevent failed call with queueId undefined (#584) * Fix for loading component failure breaking user flow + reverting token remove button + package updates (#589) * Updated packages and modified loading component * Removed showing error message * Reverting token remove button * Missed adding this file * Added pointer cursor style * Show spiner on first load in token status page (#591) * Fix Shaky Sidepanel (#592) * Rename QueueStatus/QueueStats to QueueInfo (#593) * CSS Optimisations for small screen: Fix token and header sections (#596) Co-authored-by: Mischa Radenovic <[email protected]> Co-authored-by: Nithin <[email protected]> Co-authored-by: promarcussmith <[email protected]> Co-authored-by: Bhargava Prabu Reddy <[email protected]> Co-authored-by: Lint Action <[email protected]> Co-authored-by: hallelshohat <[email protected]> Co-authored-by: Solomon kabaliisa <[email protected]> Co-authored-by: Tarun Sharma <[email protected]> Co-authored-by: navaneeth-spotnana <[email protected]>
No description provided.