root-context-controller.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import App from '../../../base'
  2. import { react2angular } from 'react2angular'
  3. import { rootContext } from '../root-context'
  4. App.controller('ReactRootContextController', function($scope, ide) {
  5. $scope.editorLoading = !!ide.$scope.state.loading
  6. ide.$scope.$watch('state.loading', editorLoading => {
  7. $scope.editorLoading = editorLoading
  8. })
  9. $scope.setChatIsOpenAngular = value => {
  10. ide.$scope.$applyAsync(() => {
  11. ide.$scope.ui.chatOpen = value
  12. })
  13. }
  14. // we need to pass `$scope.ui.chatOpen` to Angular while both React and Angular
  15. // Navigation Toolbars exist in the codebase. Once the Angular version is removed,
  16. // the React Navigation Toolbar will be the only source of truth for the open/closed state,
  17. // but `setChatIsOpenAngular` will still need to exist since Angular is responsible of the
  18. // global layout
  19. $scope.chatIsOpenAngular = ide.$scope.ui.chatOpen
  20. ide.$scope.$watch('ui.chatOpen', value => {
  21. $scope.chatIsOpenAngular = value
  22. })
  23. // wrapper is required to avoid scope problems with `this` inside `EditorManager`
  24. $scope.openDoc = (doc, args) => ide.editorManager.openDoc(doc, args)
  25. })
  26. App.component(
  27. 'sharedContextReact',
  28. react2angular(rootContext.component, [
  29. 'editorLoading',
  30. 'setChatIsOpenAngular',
  31. 'chatIsOpenAngular',
  32. 'openDoc',
  33. // `$scope.onlineUsersArray` is already populated by `OnlineUsersManager`, which also creates
  34. // a new array instance every time the list of online users change (which should refresh the
  35. // value passed to React as a prop, triggering a re-render)
  36. 'onlineUsersArray'
  37. ])
  38. )