Untitled

From Beige Anoa, 4 Days ago, written in Plain Text, viewed 653 times. This paste will check out in 2 Days.
URL https://paste.scratchbook.ch/view/7378580b Embed
Download Paste or View Raw
  1. function getPageNumber(classId) {
  2.     // classId can be taken from rootscope
  3.     var rawString = window.localStorage.getItem(requestFilterKey)
  4.     var parsed =  JSON.parse(rawString)
  5.     var requestFilter = (parsed || []).filter(payload => payload.classId === classId)
  6.     return requestFilter && requestFilter.length && requestFilter[0].pageNumber ? requestFilter[0].pageNumber : 1;
  7. }
  8.  
  9. function setPageNumber(classId, pageNumber) {
  10.     // classId can be taken from rootscope
  11.     var rawString = window.localStorage.getItem(requestFilterKey)
  12.     var parsed =  JSON.parse(rawString)
  13.  
  14.     if (!parsed) {
  15.         parsed = []
  16.     }
  17.     var indexOfClassId = parsed.findIndex(data => data.classId === classId)
  18.  
  19.     if (indexOfClassId > -1) {
  20.         parsed[indexOfClassId].pageNumber = pageNumber;
  21.     } else {
  22.         parsed.push({ classId, pageNumber })
  23.     }
  24.  
  25.     window.localStorage.setItem(requestFilterKey, JSON.stringify(parsed))
  26. }
  27.  
  28. var requestFilterKey = 'assignment-listing.request.filter'
  29. var payload = function(classId, pageNumber) { return { classId, pageNumber }; }
  30. var payloads = [payload('c1', 1), payload('c2', 2)]
  31. window.localStorage.setItem(requestFilterKey, JSON.stringify(payloads))

Reply to "Untitled"

Here you can reply to the paste above