BlueprintCourse.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 { ConnectedCourseSidebar } from '../components/CourseSidebar'
  22. import FlashNotifications from '../flashNotifications'
  23. import createStore from '../store'
  24. import Router from '../router'
  25. export default class BlueprintCourse {
  26. constructor (root, data, debug) {
  27. this.root = root
  28. this.store = createStore(data, debug)
  29. this.router = new Router()
  30. }
  31. routes = [{
  32. path: Router.PATHS.singleMigration,
  33. onEnter: ({ params }) => this.app.showChangeLog(params),
  34. onExit: () => this.app.hideChangeLog(),
  35. }]
  36. setupRouter () {
  37. this.router.registerRoutes(this.routes)
  38. this.router.start()
  39. }
  40. unmount () {
  41. ReactDOM.unmountComponentAtNode(this.root)
  42. }
  43. render () {
  44. ReactDOM.render(
  45. <Provider store={this.store}>
  46. <ConnectedCourseSidebar routeTo={this.router.page} realRef={(c) => { this.app = c }} />
  47. </Provider>,
  48. this.root
  49. )
  50. }
  51. start () {
  52. FlashNotifications.subscribe(this.store)
  53. this.render()
  54. if (window.location.hash.indexOf('#!/blueprint') === 0) {
  55. this.setupRouter()
  56. }
  57. }
  58. }