react_todo_sidebar.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Copyright (C) 2017 - present Instructure, Inc.
  3. *
  4. * This file is part of Canvas.
  5. *
  6. * Canvas is free software: you can redistribute it and/or modify it under
  7. * the terms of the GNU Affero General Public License as published by the Free
  8. * Software Foundation, version 3 of the License.
  9. *
  10. * Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
  11. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. * A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  13. * details.
  14. *
  15. * You should have received a copy of the GNU Affero General Public License along
  16. * with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. import React from 'react';
  19. import ReactDOM from 'react-dom';
  20. import { Provider } from 'react-redux';
  21. import ToDoSidebar from 'jsx/dashboard/ToDoSidebar';
  22. import configureStore from 'jsx/dashboard/ToDoSidebar/store';
  23. const store = configureStore({}, window.ENV.DEBUG_PLANNER);
  24. /**
  25. * This handles rendering this properly. Because the sidebar itself is loaded
  26. * via a Rails render without layout, it can't render out the script tag for this
  27. * bundle. So we load this bundle at the main application, but we need to wait for
  28. * the sidebar to render. This makes it so we check every 500ms for the proper
  29. * container to be there, once it is there, we stop.
  30. */
  31. const interval = window.setInterval(() => {
  32. const container = document.querySelector('.Sidebar__TodoListContainer')
  33. if (container) {
  34. ReactDOM.render(
  35. <Provider store={store}>
  36. <ToDoSidebar courses={window.ENV.STUDENT_PLANNER_COURSES} timeZone={window.ENV.TIMEZONE} />
  37. </Provider>
  38. , document.querySelector('.Sidebar__TodoListContainer'));
  39. window.clearInterval(interval);
  40. }
  41. }, 500);