File size: 1,524 Bytes
248d96b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const { LitElement, html, css } = require('lit')
const { commonCss } = require('./components/common')

class LoadingScreen extends LitElement {
  static get styles () {
    return css`

      ${commonCss}

      .title {

        top: 30px;

      }



      #cancel-btn {

        position: absolute;

        top: calc(20% + 50px);

        left: 50%;

        transform: translate(-50%);

      }

    `
  }

  static get properties () {
    return {
      status: { type: String },
      loadingText: { type: String },
      hasError: { type: Number }
    }
  }

  constructor () {
    super()
    this.hasError = false
    this.status = 'Waiting for JS load'
  }

  firstUpdated () {
    this.statusRunner()
  }

  async statusRunner () {
    const array = ['.', '..', '...', '']
    const timer = ms => new Promise((resolve) => setTimeout(resolve, ms))

    const load = async () => {
      for (let i = 0; true; i = ((i + 1) % array.length)) {
        this.loadingText = this.status + array[i]
        await timer(500)
      }
    }

    load()
  }

  render () {
    return html`

      <div class="dirt-bg"></div>



      <p class="title">${this.hasError ? this.status : this.loadingText}</p>

 

      ${this.hasError

        ? html`<pmui-button id="cancel-btn" pmui-width="200px" pmui-label="Cancel" @pmui-click=${() => window.location.reload()}></pmui-button>`

        : ''

      }

    `
  }
}

window.customElements.define('pmui-loadingscreen', LoadingScreen)