Skip to content

Commit 6489cac

Browse files
committed
fix:updating the app
1 parent 397a632 commit 6489cac

File tree

3 files changed

+42
-25
lines changed

3 files changed

+42
-25
lines changed

web-src/src/assetDetails.js

+17-15
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,22 @@ let accessToken;
66
// eslint-disable-next-line no-undef
77
const queryParams = new URLSearchParams(window.location.search);
88
const encodedJsonString = queryParams.get('data');
9-
const hlxUrl= queryParams.get('hlxUrl');
10-
let data = {};
11-
if (encodedJsonString) {
12-
const jsonString = decodeURIComponent(encodedJsonString);
13-
data = JSON.parse(jsonString);
14-
}
15-
16-
try {
17-
let state = await getState();
18-
accessToken = state.imsToken;
19-
20-
} catch (error) {
21-
console.log(error);
9+
const hlxUrl= sessionStorage.getItem('hlxUrl');
10+
const urn= queryParams.get('urn');
11+
// console.log(sessionStorage.getItem('assetDetails'));
12+
const data1 = JSON.parse(sessionStorage.getItem('assetDetails'));
13+
14+
let data = data1[urn];
15+
// if (encodedJsonString) {
16+
// const jsonString = decodeURIComponent(encodedJsonString);
17+
// data = JSON.parse(jsonString);
18+
// }
19+
20+
async function connectAndFetchData() {
21+
accessToken = sessionStorage.getItem('accessToken');
22+
// Proceed if we have a valid access token
2223
}
24+
await connectAndFetchData();
2325
init(data);
2426

2527
function init(data) {
@@ -121,11 +123,11 @@ let accessToken;
121123
viewDetail.classList.add('assets-usage');
122124
viewDetail.textContent = "Assets Usage Report";
123125
viewDetail.addEventListener('click', () => {
124-
window.location.href = `/assetsUsageReport.html?hlxUrl=${hlxUrl}&pagePath=${page}`;
126+
window.location.href = `/assetsUsageReport.html?pagePath=${page}`;
125127
});
126128
pageDiv.appendChild(viewDetail);
127129
pagesSection.appendChild(pageDiv);
128-
fetch(`https://288650-edsassettracker-stage.adobeio-static.net/api/v1/web/EDS-Asset-Tracker1/fetchList?hlxUrl=${hlxUrl}`, {
130+
fetch(`https://288650-edsassettracker.adobeio-static.net/api/v1/web/EDS-Asset-Tracker1/fetchList?hlxUrl=${hlxUrl}`, {
129131
method: 'GET', // or 'POST' if you want to send data
130132
headers: {
131133
'Authorization': `Bearer ${accessToken}`, // Send the access token in the Authorization header

web-src/src/assetsData.js

+22-10
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,32 @@ let accessToken;
2121
document.body.appendChild(mask);
2222

2323
const queryParams = new URLSearchParams(window.location.search);
24-
const hlxUrl = queryParams.get('hlxUrl');
2524
const pagePath = queryParams.get('pagePath');
25+
let hlxUrl;
26+
if (pagePath) {
27+
hlxUrl = sessionStorage.getItem('hlxUrl');
28+
} else {
29+
hlxUrl = queryParams.get('hlxUrl');
30+
sessionStorage.setItem('hlxUrl', hlxUrl);
31+
}
32+
2633
let data = {};
2734
async function connectAndFetchData() {
35+
accessToken = sessionStorage.getItem('accessToken');
36+
if (!accessToken) {
37+
try {
38+
let state = await getState();
39+
accessToken = state.imsToken;
2840

29-
try {
30-
let state = await getState();
31-
accessToken = state.imsToken;
32-
33-
} catch (error) {
34-
console.log(error);
41+
} catch (error) {
42+
console.log(error);
43+
}
3544
}
3645

46+
3747
// Proceed if we have a valid access token
3848
if (accessToken) {
49+
sessionStorage.setItem('accessToken', accessToken);
3950
try {
4051
const response = await fetch(
4152
`https://288650-edsassettracker.adobeio-static.net/api/v1/web/EDS-Asset-Tracker1/fetchList?hlxUrl=${hlxUrl}`,
@@ -113,6 +124,7 @@ let accessToken;
113124
pageFilter.appendChild(parentDiv);
114125
}
115126

127+
sessionStorage.setItem('assetDetails', JSON.stringify(response.payload.assetDetails));
116128
Object.entries(response.payload.assetDetails).forEach(([urn, asset]) => {
117129
const assetRow = document.createElement('div');
118130
assetRow.className = 'asset-row';
@@ -202,10 +214,10 @@ let accessToken;
202214
const jsonString = JSON.stringify(asset);
203215
const encodedJsonString = encodeURIComponent(jsonString);
204216
// Use URN in the query string to identify the asset in the details page
205-
detailLink.href = `/assetDetails.html?data=${encodedJsonString}&hlxUrl=${hlxUrl}`;
217+
detailLink.href = `/assetDetails.html?urn=${urn}`;
206218
if (asset.pagePath.length > topUsage) {
207219
topUsage = asset.pagePath.length;
208-
topUsed = `/assetDetails.html?data=${encodedJsonString}&hlxUrl=${hlxUrl}`;
220+
topUsed = `/assetDetails.html?urn=${urn}`;
209221
}
210222
detailLinkDiv.appendChild(detailLink);
211223
assetRow.appendChild(detailLinkDiv);
@@ -254,7 +266,7 @@ let accessToken;
254266
const jsonString = JSON.stringify(asset);
255267
const encodedJsonString = encodeURIComponent(jsonString);
256268
// Use URN in the query string to identify the asset in the details page
257-
const href = `/assetDetails.html?data=${encodedJsonString}&hlxUrl=${hlxUrl}`;
269+
const href = `/assetDetails.html?urn=${urn}`;
258270
const cleanThumbnailUrl = new URL(asset.assetPath);
259271
let thumbnail;
260272
if (!asset.isExpired)

web-src/src/index.js

+3
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,10 @@ async function invokeAction (action, _headers, _params) {
205205
}
206206

207207
export async function getState() {
208+
let attempts = 0;
208209
while (!state.imsToken) {
210+
attempts++;
211+
console.log(`Attempt number: ${attempts}`);
209212
await new Promise(resolve => setTimeout(resolve, 100));
210213
}
211214
return state;

0 commit comments

Comments
 (0)