sul-dlss/argo

View on GitHub
app/javascript/controllers/workflow_grid_controller.js

Summary

Maintainability
A
0 mins
Test Coverage
import { Controller } from '@hotwired/stimulus'

export default class extends Controller {
  connect () {
    this.load()

    if (this.data.has('refreshInterval')) {
      this.startRefreshing()
    }
  }

  startRefreshing () {
    setInterval(() => {
      this.load()
    }, this.data.get('refreshInterval'))
  }

  load () {
    // We're setting this header so that the controller can check for request.xhr?
    fetch(this.data.get('url'), { headers: { 'X-Requester': 'frontend' } })
      .then(response => response.text())
      .then(html => {
        this.element.innerHTML = html
      })
  }
}