LoadingManager.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import i18n from '../i18n'
  2. // Control the editor loading screen. We want to show the loading screen until
  3. // both the websocket connection has been established (so that the editor is in
  4. // the correct state) and the translations have been loaded (so we don't see a
  5. // flash of untranslated text).
  6. class LoadingManager {
  7. constructor($scope) {
  8. this.$scope = $scope
  9. const socketPromise = new Promise(resolve => {
  10. this.resolveSocketPromise = resolve
  11. })
  12. Promise.all([socketPromise, i18n])
  13. .then(() => {
  14. this.$scope.$apply(() => {
  15. this.$scope.state.load_progress = 100
  16. this.$scope.state.loading = false
  17. this.$scope.$emit('editor:loaded')
  18. })
  19. })
  20. // Note: this will only catch errors in from i18n setup. ConnectionManager
  21. // handles errors for the socket connection
  22. .catch(() => {
  23. this.$scope.$apply(() => {
  24. this.$scope.state.error = 'Could not load translations.'
  25. })
  26. })
  27. }
  28. socketLoaded() {
  29. this.resolveSocketPromise()
  30. }
  31. }
  32. export default LoadingManager