From c1ec2616dd2fb56524f57ebc67dedc8827433fd9 Mon Sep 17 00:00:00 2001 From: prcdevgitbot Date: Thu, 22 Feb 2024 20:32:57 +0000 Subject: [PATCH] See https://github.com/pewresearch/pewresearch-org/commit/57c5cf5fae3d59a5062981f5ff5d7608e5b2c13d from refs/heads/release/5.0 --- .../build/download-block/view.asset.php | 2 +- .../datasets/build/download-block/view.js | 2 +- .../datasets/build/download-block/view.js.map | 2 +- includes/datasets/src/download-block/view.js | 22 +++++++++---------- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/includes/datasets/build/download-block/view.asset.php b/includes/datasets/build/download-block/view.asset.php index a7b1a9d8..44fc14b0 100644 --- a/includes/datasets/build/download-block/view.asset.php +++ b/includes/datasets/build/download-block/view.asset.php @@ -1 +1 @@ - array('@wordpress/interactivity', 'wp-polyfill'), 'version' => '4b20554576f21acb4ee6', 'type' => 'module'); + array('@wordpress/interactivity', 'wp-polyfill'), 'version' => 'c81c8a673ea2105706fa', 'type' => 'module'); diff --git a/includes/datasets/build/download-block/view.js b/includes/datasets/build/download-block/view.js index 46a774fc..db8b6322 100644 --- a/includes/datasets/build/download-block/view.js +++ b/includes/datasets/build/download-block/view.js @@ -1,2 +1,2 @@ -import*as t from"@wordpress/interactivity";var e={d:(t,o)=>{for(var n in o)e.o(o,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:o[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)};const o=(a={getContext:()=>t.getContext,getElement:()=>t.getElement,store:()=>t.store},r={},e.d(r,a),r),{actions:n}=(0,o.store)("prc-platform/dataset-download",{actions:{downloadDataset:(t,e,o)=>{window?.wp?.apiFetch({path:`/prc-api/v3/datasets/get-download/?datasetId=${t}`,method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({uid:e,userToken:o})}).then((t=>{t?.file_url&&window.open(t.file_url,"_blank")})).catch((t=>{console.error("Error fetching dataset download",t)}))},onButtonClick:t=>{t.preventDefault();const e=(0,o.getContext)(),{datasetId:a,isATP:r}=e,s=(0,o.getContext)("prc-user-accounts/content-gate"),{userToken:i,userId:c}=s;console.log('onButtonClick: "Hit the api with this information..." ->',s,i,c,a),r?(console.log("isATP"),n.checkATP(c,i,a)):n.downloadDataset(a,c,i)},async checkATP(t,e,a){const{ref:r}=(0,o.getElement)(),s=await(window?.wp?.apiFetch({path:"/prc-api/v3/datasets/check-atp/",method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({uid:t,userToken:e})}));if(console.log("CHECK ATP",s),!0===s&&n.downloadDataset(a,t,e),!1===s){const t=r.parentElement.parentElement.parentElement.getAttribute("id"),{actions:e,state:n}=(0,o.store)("prc-block/popup-controller");console.log("POP",n,t),e.open(null,t)}}}});var a,r; +import*as t from"@wordpress/interactivity";var e={d:(t,o)=>{for(var n in o)e.o(o,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:o[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)};const o=(a={getContext:()=>t.getContext,getElement:()=>t.getElement,store:()=>t.store},r={},e.d(r,a),r),{actions:n}=(0,o.store)("prc-platform/dataset-download",{actions:{downloadDataset:(t,e,o)=>{window?.wp?.apiFetch({path:`/prc-api/v3/datasets/get-download/?datasetId=${t}`,method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({uid:e,userToken:o})}).then((t=>{t?.file_url&&window.open(t.file_url,"_blank")})).catch((t=>{console.error("Error fetching dataset download",t)}))},onButtonClick:t=>{t.preventDefault();const e=(0,o.getContext)(),{datasetId:a,isATP:r}=e,{state:s}=(0,o.store)("prc-user-accounts/content-gate"),{token:i,uid:c}=s;console.log('onButtonClick: "Hit the api with this information..." ->',s,i,c,a),r?(console.log("isATP"),n.checkATP(c,i,a)):n.downloadDataset(a,c,i)},async checkATP(t,e,a){const{ref:r}=(0,o.getElement)(),s=await(window?.wp?.apiFetch({path:"/prc-api/v3/datasets/check-atp/",method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({uid:t,userToken:e})}));if(console.log("CHECK ATP",s),!0===s&&n.downloadDataset(a,t,e),!1===s){const t=r.parentElement.parentElement.parentElement.getAttribute("id"),{actions:e,state:n}=(0,o.store)("prc-block/popup-controller");console.log("POP",n,t),e.open(null,t)}}}});var a,r; //# sourceMappingURL=view.js.map \ No newline at end of file diff --git a/includes/datasets/build/download-block/view.js.map b/includes/datasets/build/download-block/view.js.map index 3112343c..7d5d604b 100644 --- a/includes/datasets/build/download-block/view.js.map +++ b/includes/datasets/build/download-block/view.js.map @@ -1 +1 @@ -{"version":3,"file":"download-block/view.js","mappings":"2CACA,IAAIA,EAAsB,CCA1BA,EAAwB,CAACC,EAASC,KACjC,IAAI,IAAIC,KAAOD,EACXF,EAAoBI,EAAEF,EAAYC,KAASH,EAAoBI,EAAEH,EAASE,IAC5EE,OAAOC,eAAeL,EAASE,EAAK,CAAEI,YAAY,EAAMC,IAAKN,EAAWC,IAE1E,ECNDH,EAAwB,CAACS,EAAKC,IAAUL,OAAOM,UAAUC,eAAeC,KAAKJ,EAAKC,ICIlF,MAAM,GAJGI,EAI8B,CAAE,WAAgB,IAAOC,EAAwE,WAAG,WAAgB,IAAOA,EAAwE,WAAG,MAAW,IAAOA,EAAmE,OAH7TC,EAAI,CAAC,EAAGhB,EAAoBiB,EAAED,EAAGF,GAAWE,ICK3C,QAAEE,IAAYC,EAAAA,EAAAA,OAAM,gCAAiC,CAC1DD,QAAS,CACRE,gBAAiBA,CAACC,EAAWC,EAAQC,KACpCC,QAAQC,IACLC,SAAS,CACVC,KAAO,gDAA+CN,IACtDO,OAAQ,OACRC,QAAS,CAER,eAAgB,oBAEjBC,KAAMC,KAAKC,UAAU,CACpBC,IAAKX,EACLC,gBAGDW,MAAMC,IAIFA,GAAUC,UACbZ,OAAOa,KAAKF,EAASC,SAAU,SAChC,IAEAE,OAAOC,IACPC,QAAQD,MAAM,kCAAmCA,EAAM,GACtD,EAEJE,cAAgBC,IACfA,EAAMC,iBACN,MAAMC,GAAUC,EAAAA,EAAAA,eACV,UAAExB,EAAS,MAAEyB,GAAUF,EAEvBG,GAAqBF,EAAAA,EAAAA,YAC1B,mCAEK,UAAEtB,EAAS,OAAED,GAAWyB,EAE9BP,QAAQQ,IACP,2DACAD,EACAxB,EACAD,EACAD,GAGGyB,GACHN,QAAQQ,IAAI,SACZ9B,EAAQ+B,SAAS3B,EAAQC,EAAWF,IAEpCH,EAAQE,gBAAgBC,EAAWC,EAAQC,EAC5C,EAED,cAAM0B,CAAS3B,EAAQC,EAAWF,GACjC,MAAM,IAAE6B,IAAQC,EAAAA,EAAAA,cAEVhB,QAAiBX,QAAQC,IAAIC,SAAS,CAC3CC,KAAO,kCACPC,OAAQ,OACRC,QAAS,CACR,eAAgB,oBAEjBC,KAAMC,KAAKC,UAAU,CACpBC,IAAKX,EACLC,iBAQF,GAJAiB,QAAQQ,IAAI,YAAab,IACrB,IAASA,GACZjB,EAAQE,gBAAgBC,EAAWC,EAAQC,IAExC,IAAUY,EAAU,CACvB,MAAMiB,EACLF,EAAIG,cAAcA,cAAcA,cAAcC,aAC7C,OAEMpC,QAASqC,EAAcC,MAAOC,IAAetC,EAAAA,EAAAA,OACpD,8BAEDqB,QAAQQ,IAAI,MAAOS,EAAYL,GAC/BG,EAAalB,KAAK,KAAMe,EACzB,CACD,KDzFM,IAACtC,EACJE","sources":["webpack://@pewresearch/prc-platform-datasets/webpack/bootstrap","webpack://@pewresearch/prc-platform-datasets/webpack/runtime/define property getters","webpack://@pewresearch/prc-platform-datasets/webpack/runtime/hasOwnProperty shorthand","webpack://@pewresearch/prc-platform-datasets/external module \"@wordpress/interactivity\"","webpack://@pewresearch/prc-platform-datasets/./src/download-block/view.js"],"sourcesContent":["// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","var x = (y) => {\n\tvar x = {}; __webpack_require__.d(x, y); return x\n} \nvar y = (x) => (() => (x))\nconst __WEBPACK_NAMESPACE_OBJECT__ = x({ [\"getContext\"]: () => (__WEBPACK_EXTERNAL_MODULE__wordpress_interactivity_8e89b257__.getContext), [\"getElement\"]: () => (__WEBPACK_EXTERNAL_MODULE__wordpress_interactivity_8e89b257__.getElement), [\"store\"]: () => (__WEBPACK_EXTERNAL_MODULE__wordpress_interactivity_8e89b257__.store) });","/**\n * WordPress Dependencies\n */\n\nimport { store, getContext, getElement } from '@wordpress/interactivity';\n\nconst { actions } = store('prc-platform/dataset-download', {\n\tactions: {\n\t\tdownloadDataset: (datasetId, userId, userToken) => {\n\t\t\twindow?.wp\n\t\t\t\t?.apiFetch({\n\t\t\t\t\tpath: `/prc-api/v3/datasets/get-download/?datasetId=${datasetId}`,\n\t\t\t\t\tmethod: 'POST',\n\t\t\t\t\theaders: {\n\t\t\t\t\t\t// 'X-WP-Nonce': window.wpApiSettings.nonce,\n\t\t\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t\t},\n\t\t\t\t\tbody: JSON.stringify({\n\t\t\t\t\t\tuid: userId,\n\t\t\t\t\t\tuserToken,\n\t\t\t\t\t}),\n\t\t\t\t})\n\t\t\t\t.then((response) => {\n\t\t\t\t\t// If there's a file_url in the response, download it...\n\t\t\t\t\t// ooooo that felt... bad to type\n\t\t\t\t\t// should run a file check here? only pdfs and zips? not sure theres an attack vector here\n\t\t\t\t\tif (response?.file_url) {\n\t\t\t\t\t\twindow.open(response.file_url, '_blank');\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t\t.catch((error) => {\n\t\t\t\t\tconsole.error('Error fetching dataset download', error);\n\t\t\t\t});\n\t\t},\n\t\tonButtonClick: (event) => {\n\t\t\tevent.preventDefault();\n\t\t\tconst context = getContext();\n\t\t\tconst { datasetId, isATP } = context;\n\n\t\t\tconst contentGateContext = getContext(\n\t\t\t\t'prc-user-accounts/content-gate'\n\t\t\t);\n\t\t\tconst { userToken, userId } = contentGateContext;\n\n\t\t\tconsole.log(\n\t\t\t\t'onButtonClick: \"Hit the api with this information...\" ->',\n\t\t\t\tcontentGateContext,\n\t\t\t\tuserToken,\n\t\t\t\tuserId,\n\t\t\t\tdatasetId\n\t\t\t);\n\n\t\t\tif (isATP) {\n\t\t\t\tconsole.log('isATP');\n\t\t\t\tactions.checkATP(userId, userToken, datasetId);\n\t\t\t} else {\n\t\t\t\tactions.downloadDataset(datasetId, userId, userToken);\n\t\t\t}\n\t\t},\n\t\tasync checkATP(userId, userToken, datasetId) {\n\t\t\tconst { ref } = getElement();\n\n\t\t\tconst response = await window?.wp?.apiFetch({\n\t\t\t\tpath: `/prc-api/v3/datasets/check-atp/`,\n\t\t\t\tmethod: 'POST',\n\t\t\t\theaders: {\n\t\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t},\n\t\t\t\tbody: JSON.stringify({\n\t\t\t\t\tuid: userId,\n\t\t\t\t\tuserToken,\n\t\t\t\t}),\n\t\t\t});\n\n\t\t\tconsole.log('CHECK ATP', response);\n\t\t\tif (true === response) {\n\t\t\t\tactions.downloadDataset(datasetId, userId, userToken);\n\t\t\t}\n\t\t\tif (false === response) {\n\t\t\t\tconst popupID =\n\t\t\t\t\tref.parentElement.parentElement.parentElement.getAttribute(\n\t\t\t\t\t\t'id'\n\t\t\t\t\t);\n\t\t\t\tconst { actions: popupActions, state: popupState } = store(\n\t\t\t\t\t'prc-block/popup-controller'\n\t\t\t\t);\n\t\t\t\tconsole.log('POP', popupState, popupID);\n\t\t\t\tpopupActions.open(null, popupID);\n\t\t\t}\n\t\t},\n\t},\n});\n"],"names":["__webpack_require__","exports","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","y","__WEBPACK_EXTERNAL_MODULE__wordpress_interactivity_8e89b257__","x","d","actions","store","downloadDataset","datasetId","userId","userToken","window","wp","apiFetch","path","method","headers","body","JSON","stringify","uid","then","response","file_url","open","catch","error","console","onButtonClick","event","preventDefault","context","getContext","isATP","contentGateContext","log","checkATP","ref","getElement","popupID","parentElement","getAttribute","popupActions","state","popupState"],"sourceRoot":""} \ No newline at end of file +{"version":3,"file":"download-block/view.js","mappings":"2CACA,IAAIA,EAAsB,CCA1BA,EAAwB,CAACC,EAASC,KACjC,IAAI,IAAIC,KAAOD,EACXF,EAAoBI,EAAEF,EAAYC,KAASH,EAAoBI,EAAEH,EAASE,IAC5EE,OAAOC,eAAeL,EAASE,EAAK,CAAEI,YAAY,EAAMC,IAAKN,EAAWC,IAE1E,ECNDH,EAAwB,CAACS,EAAKC,IAAUL,OAAOM,UAAUC,eAAeC,KAAKJ,EAAKC,ICIlF,MAAM,GAJGI,EAI8B,CAAE,WAAgB,IAAOC,EAAwE,WAAG,WAAgB,IAAOA,EAAwE,WAAG,MAAW,IAAOA,EAAmE,OAH7TC,EAAI,CAAC,EAAGhB,EAAoBiB,EAAED,EAAGF,GAAWE,ICK3C,QAAEE,IAAYC,EAAAA,EAAAA,OAAM,gCAAiC,CAC1DD,QAAS,CACRE,gBAAiBA,CAACC,EAAWC,EAAKC,KACjCC,QAAQC,IACLC,SAAS,CACVC,KAAO,gDAA+CN,IACtDO,OAAQ,OACRC,QAAS,CAER,eAAgB,oBAEjBC,KAAMC,KAAKC,UAAU,CACpBV,MACAW,UAAWV,MAGZW,MAAMC,IAIFA,GAAUC,UACbZ,OAAOa,KAAKF,EAASC,SAAU,SAChC,IAEAE,OAAOC,IACPC,QAAQD,MAAM,kCAAmCA,EAAM,GACtD,EAEJE,cAAgBC,IACfA,EAAMC,iBACN,MAAMC,GAAUC,EAAAA,EAAAA,eACV,UAAExB,EAAS,MAAEyB,GAAUF,GAEvB,MAAEG,IAAU5B,EAAAA,EAAAA,OAAM,mCAClB,MAAEI,EAAK,IAAED,GAAQyB,EAEvBP,QAAQQ,IACP,2DACAD,EACAxB,EACAD,EACAD,GAGGyB,GACHN,QAAQQ,IAAI,SACZ9B,EAAQ+B,SAAS3B,EAAKC,EAAOF,IAE7BH,EAAQE,gBAAgBC,EAAWC,EAAKC,EACzC,EAED,cAAM0B,CAASC,EAAQjB,EAAWZ,GACjC,MAAM,IAAE8B,IAAQC,EAAAA,EAAAA,cAEVjB,QAAiBX,QAAQC,IAAIC,SAAS,CAC3CC,KAAO,kCACPC,OAAQ,OACRC,QAAS,CACR,eAAgB,oBAEjBC,KAAMC,KAAKC,UAAU,CACpBV,IAAK4B,EACLjB,iBAQF,GAJAO,QAAQQ,IAAI,YAAab,IACrB,IAASA,GACZjB,EAAQE,gBAAgBC,EAAW6B,EAAQjB,IAExC,IAAUE,EAAU,CACvB,MAAMkB,EACLF,EAAIG,cAAcA,cAAcA,cAAcC,aAC7C,OAEMrC,QAASsC,EAAcT,MAAOU,IAAetC,EAAAA,EAAAA,OACpD,8BAEDqB,QAAQQ,IAAI,MAAOS,EAAYJ,GAC/BG,EAAanB,KAAK,KAAMgB,EACzB,CACD,KDvFM,IAACvC,EACJE","sources":["webpack://@pewresearch/prc-platform-datasets/webpack/bootstrap","webpack://@pewresearch/prc-platform-datasets/webpack/runtime/define property getters","webpack://@pewresearch/prc-platform-datasets/webpack/runtime/hasOwnProperty shorthand","webpack://@pewresearch/prc-platform-datasets/external module \"@wordpress/interactivity\"","webpack://@pewresearch/prc-platform-datasets/./src/download-block/view.js"],"sourcesContent":["// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","var x = (y) => {\n\tvar x = {}; __webpack_require__.d(x, y); return x\n} \nvar y = (x) => (() => (x))\nconst __WEBPACK_NAMESPACE_OBJECT__ = x({ [\"getContext\"]: () => (__WEBPACK_EXTERNAL_MODULE__wordpress_interactivity_8e89b257__.getContext), [\"getElement\"]: () => (__WEBPACK_EXTERNAL_MODULE__wordpress_interactivity_8e89b257__.getElement), [\"store\"]: () => (__WEBPACK_EXTERNAL_MODULE__wordpress_interactivity_8e89b257__.store) });","/**\n * WordPress Dependencies\n */\n\nimport { store, getContext, getElement } from '@wordpress/interactivity';\n\nconst { actions } = store('prc-platform/dataset-download', {\n\tactions: {\n\t\tdownloadDataset: (datasetId, uid, token) => {\n\t\t\twindow?.wp\n\t\t\t\t?.apiFetch({\n\t\t\t\t\tpath: `/prc-api/v3/datasets/get-download/?datasetId=${datasetId}`,\n\t\t\t\t\tmethod: 'POST',\n\t\t\t\t\theaders: {\n\t\t\t\t\t\t// 'X-WP-Nonce': window.wpApiSettings.nonce,\n\t\t\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t\t},\n\t\t\t\t\tbody: JSON.stringify({\n\t\t\t\t\t\tuid,\n\t\t\t\t\t\tuserToken: token,\n\t\t\t\t\t}),\n\t\t\t\t})\n\t\t\t\t.then((response) => {\n\t\t\t\t\t// If there's a file_url in the response, download it...\n\t\t\t\t\t// ooooo that felt... bad to type\n\t\t\t\t\t// should run a file check here? only pdfs and zips? not sure theres an attack vector here\n\t\t\t\t\tif (response?.file_url) {\n\t\t\t\t\t\twindow.open(response.file_url, '_blank');\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t\t.catch((error) => {\n\t\t\t\t\tconsole.error('Error fetching dataset download', error);\n\t\t\t\t});\n\t\t},\n\t\tonButtonClick: (event) => {\n\t\t\tevent.preventDefault();\n\t\t\tconst context = getContext();\n\t\t\tconst { datasetId, isATP } = context;\n\n\t\t\tconst { state } = store('prc-user-accounts/content-gate');\n\t\t\tconst { token, uid } = state;\n\n\t\t\tconsole.log(\n\t\t\t\t'onButtonClick: \"Hit the api with this information...\" ->',\n\t\t\t\tstate,\n\t\t\t\ttoken,\n\t\t\t\tuid,\n\t\t\t\tdatasetId\n\t\t\t);\n\n\t\t\tif (isATP) {\n\t\t\t\tconsole.log('isATP');\n\t\t\t\tactions.checkATP(uid, token, datasetId);\n\t\t\t} else {\n\t\t\t\tactions.downloadDataset(datasetId, uid, token);\n\t\t\t}\n\t\t},\n\t\tasync checkATP(userId, userToken, datasetId) {\n\t\t\tconst { ref } = getElement();\n\n\t\t\tconst response = await window?.wp?.apiFetch({\n\t\t\t\tpath: `/prc-api/v3/datasets/check-atp/`,\n\t\t\t\tmethod: 'POST',\n\t\t\t\theaders: {\n\t\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t},\n\t\t\t\tbody: JSON.stringify({\n\t\t\t\t\tuid: userId,\n\t\t\t\t\tuserToken,\n\t\t\t\t}),\n\t\t\t});\n\n\t\t\tconsole.log('CHECK ATP', response);\n\t\t\tif (true === response) {\n\t\t\t\tactions.downloadDataset(datasetId, userId, userToken);\n\t\t\t}\n\t\t\tif (false === response) {\n\t\t\t\tconst popupID =\n\t\t\t\t\tref.parentElement.parentElement.parentElement.getAttribute(\n\t\t\t\t\t\t'id'\n\t\t\t\t\t);\n\t\t\t\tconst { actions: popupActions, state: popupState } = store(\n\t\t\t\t\t'prc-block/popup-controller'\n\t\t\t\t);\n\t\t\t\tconsole.log('POP', popupState, popupID);\n\t\t\t\tpopupActions.open(null, popupID);\n\t\t\t}\n\t\t},\n\t},\n});\n"],"names":["__webpack_require__","exports","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","y","__WEBPACK_EXTERNAL_MODULE__wordpress_interactivity_8e89b257__","x","d","actions","store","downloadDataset","datasetId","uid","token","window","wp","apiFetch","path","method","headers","body","JSON","stringify","userToken","then","response","file_url","open","catch","error","console","onButtonClick","event","preventDefault","context","getContext","isATP","state","log","checkATP","userId","ref","getElement","popupID","parentElement","getAttribute","popupActions","popupState"],"sourceRoot":""} \ No newline at end of file diff --git a/includes/datasets/src/download-block/view.js b/includes/datasets/src/download-block/view.js index 4f918007..ed1e624f 100644 --- a/includes/datasets/src/download-block/view.js +++ b/includes/datasets/src/download-block/view.js @@ -6,7 +6,7 @@ import { store, getContext, getElement } from '@wordpress/interactivity'; const { actions } = store('prc-platform/dataset-download', { actions: { - downloadDataset: (datasetId, userId, userToken) => { + downloadDataset: (datasetId, uid, token) => { window?.wp ?.apiFetch({ path: `/prc-api/v3/datasets/get-download/?datasetId=${datasetId}`, @@ -16,8 +16,8 @@ const { actions } = store('prc-platform/dataset-download', { 'Content-Type': 'application/json', }, body: JSON.stringify({ - uid: userId, - userToken, + uid, + userToken: token, }), }) .then((response) => { @@ -37,24 +37,22 @@ const { actions } = store('prc-platform/dataset-download', { const context = getContext(); const { datasetId, isATP } = context; - const contentGateContext = getContext( - 'prc-user-accounts/content-gate' - ); - const { userToken, userId } = contentGateContext; + const { state } = store('prc-user-accounts/content-gate'); + const { token, uid } = state; console.log( 'onButtonClick: "Hit the api with this information..." ->', - contentGateContext, - userToken, - userId, + state, + token, + uid, datasetId ); if (isATP) { console.log('isATP'); - actions.checkATP(userId, userToken, datasetId); + actions.checkATP(uid, token, datasetId); } else { - actions.downloadDataset(datasetId, userId, userToken); + actions.downloadDataset(datasetId, uid, token); } }, async checkATP(userId, userToken, datasetId) {