Sha256: bd26e30260c226f9c19a54c9c78d57640c4b0fa9b4bcca126f81c0fb2a101c80

Contents?: true

Size: 1.61 KB

Versions: 19

Compression:

Stored size: 1.61 KB

Contents

/*
// Custom JS | written by https://github.com/wdzajicek
// © 2020 Kankakee Community College
// =================================================== */
// Module to retrieve our cached Google Sheet response from sessionStorage
// 1. Create an object that replicates an API response where `response.result.values`
//    is an array containing an array representing each row in the sheet.
// 2. Then we pass our mock-sheet response object to the `createAlertsHtml` module to
//    build and inject the alert into the DOM.
import createAlertsHtml from './createAlertsHtml.js';
import checkForAccordionOrTab from './checkForAccordionOrTab.js';

const cache = window.sessionStorage;

function processCachedResponse(response, callback) {
  createAlertsHtml(response);
  return callback();
}

function createCachedResponseObject() {
  let cachedResponse = {  // Reconstructing our own Google Sheet-like response from the sessionStorage items
    result: {
      values: [
        0, // First two rows aren't used by the `createAlertsHtml()` function
        0,
        [
          cache.Visible,
          cache.getItem('All-Pages'),
          cache.getItem('Alert-Content'),
          cache.getItem('Alert-Expiration'),
          cache.Start,
          cache.End
        ]
      ]
    }
  }
  processCachedResponse(cachedResponse, checkForAccordionOrTab);
}

function getCachedResponse() {
  try {
    createCachedResponseObject();
  } catch (error) {
    checkForAccordionOrTab();
    console.error(`Error retrieving cached response in sessionStorage:\nName: ${error.name}\nMessage: ${error.message}\n${error}`);
  }
}

export default getCachedResponse;

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
kcc-gem-theme-2.11.1 assets/js/alerts/getCachedResponse.js
kcc-gem-theme-2.11.0 assets/js/alerts/getCachedResponse.js
kcc-gem-theme-2.10.0 assets/js/alerts/getCachedResponse.js
kcc-gem-theme-2.9.1 assets/js/alerts/getCachedResponse.js
kcc-gem-theme-2.9.0 assets/js/alerts/getCachedResponse.js
kcc-gem-theme-2.8.6 assets/js/alerts/getCachedResponse.js
kcc-gem-theme-2.8.5 assets/js/alerts/getCachedResponse.js
kcc-gem-theme-2.8.4 assets/js/alerts/getCachedResponse.js
kcc-gem-theme-2.8.3 assets/js/alerts/getCachedResponse.js
kcc-gem-theme-2.8.2 assets/js/alerts/getCachedResponse.js
kcc-gem-theme-2.8.1 assets/js/alerts/getCachedResponse.js
kcc-gem-theme-2.8.0 assets/js/alerts/getCachedResponse.js
kcc-gem-theme-2.7.1 assets/js/alerts/getCachedResponse.js
kcc-gem-theme-2.7.0 assets/js/alerts/getCachedResponse.js
kcc-gem-theme-2.6.4 assets/js/alerts/getCachedResponse.js
kcc-gem-theme-2.6.3 assets/js/alerts/getCachedResponse.js
kcc-gem-theme-2.6.2 assets/js/alerts/getCachedResponse.js
kcc-gem-theme-2.6.1 assets/js/alerts/getCachedResponse.js
kcc-gem-theme-2.6.0 assets/js/alerts/getCachedResponse.js