Sha256: d0612f708797f0aea338d886f5ea08187a07ce1b15457820dcef6d691069317c

Contents?: true

Size: 1.52 KB

Versions: 56

Compression:

Stored size: 1.52 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 contentHashLink from './contentHashLink.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, contentHashLink);
}

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

export default getCachedResponse;

Version data entries

56 entries across 56 versions & 2 rubygems

Version Path
kcc-gem-theme-1.96.1 assets/js/src/getCachedResponse.js
kcc-gem-theme-1.96.0 assets/js/src/getCachedResponse.js
kcc-gem-theme-1.95.0 assets/js/src/getCachedResponse.js
kcc-gem-theme-1.94.1 assets/js/src/getCachedResponse.js
kcc-gem-theme-1.94.0 assets/js/src/getCachedResponse.js
kcc-gem-theme-1.93.0 assets/js/src/getCachedResponse.js
kcc-gem-theme-1.92.0 assets/js/src/getCachedResponse.js
kcc-gem-theme-1.91.0 assets/js/src/getCachedResponse.js
kcc-gem-theme-1.90.0 assets/js/src/getCachedResponse.js
kcc-gem-theme-1.89.0 assets/js/src/getCachedResponse.js
kcc-gem-theme-1.88.0 assets/js/src/getCachedResponse.js
kcc-gem-theme-1.87.0 assets/js/src/getCachedResponse.js
kcc-gem-theme-1.86.1 assets/js/src/getCachedResponse.js
kcc-gem-theme-1.86.0 assets/js/src/getCachedResponse.js
kcc-gem-theme-2.5.3 assets/js/alerts/getCachedResponse.js
kcc-gem-theme-2.5.2 assets/js/alerts/getCachedResponse.js
kcc-gem-theme-2.5.1 assets/js/alerts/getCachedResponse.js
kcc-gem-theme-2.5.0 assets/js/alerts/getCachedResponse.js
kcc-gem-theme-2.4.1 assets/js/alerts/getCachedResponse.js
kcc-gem-theme-2.4.0 assets/js/alerts/getCachedResponse.js