LoadingManager.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  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. })
  18. })
  19. // Note: this will only catch errors in from i18n setup. ConnectionManager
  20. // handles errors for the socket connection
  21. .catch(() => {
  22. this.$scope.$apply(() => {
  23. this.$scope.state.error = 'Could not load translations.'
  24. })
  25. })
  26. }
  27. socketLoaded() {
  28. this.resolveSocketPromise()
  29. }
  30. }
  31. export default LoadingManager