Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

suggestion tweaks #658

Merged
merged 2 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 30 additions & 22 deletions tools/oversight/elements/url-selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ function getPersistentToken() {
return localStorage.getItem('rum-bundler-token');
}

function isIncognitoMode() {
return new URL(window.location.href).searchParams.get('domainkey') === 'incognito';
}

export default class URLSelector extends HTMLElement {
constructor() {
super();
Expand Down Expand Up @@ -41,8 +45,7 @@ export default class URLSelector extends HTMLElement {
const img = this.querySelector('img');
img.src = `https://www.google.com/s2/favicons?domain=${input.value.split(':')[0]}&sz=64`;

const token = getPersistentToken();
if (!token) {
if (!getPersistentToken()) {
input.disabled = true;
datalist.remove();

Expand All @@ -55,28 +58,33 @@ export default class URLSelector extends HTMLElement {
window.location.href = targetlocation.href;
}
});
} else {
fetch('https://rum.fastly-aem.page/domains?suggested=true', {
headers: {
accept: 'application/json',
authorization: `Bearer ${token}`,
},
}).then(async (resp) => {
if (!resp.ok) {
datalist.remove();
} else {
const { domains } = await resp.json();
domains.forEach((domain) => {
const option = document.createElement('option');
option.value = domain;
datalist.appendChild(option);
});
}
}).catch(() => {
datalist.remove();
});
}

input.addEventListener('mouseover', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this is not expected to work on mobile.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah it seemed like the url-selector already wasn't working on mobile.. is that unexpected?

const token = getPersistentToken();
if (token && !isIncognitoMode()) {
fetch('https://rum.fastly-aem.page/domains?suggested=true', {
headers: {
accept: 'application/json',
authorization: `Bearer ${token}`,
},
}).then(async (resp) => {
if (!resp.ok) {
datalist.remove();
} else {
const { domains } = await resp.json();
domains.forEach((domain) => {
const option = document.createElement('option');
option.value = domain;
datalist.appendChild(option);
});
}
}).catch(() => {
datalist.remove();
});
}
}, { once: true });

input.addEventListener('focus', () => {
input.select();
});
Expand Down
52 changes: 30 additions & 22 deletions tools/rum/elements/url-selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ function getPersistentToken() {
return localStorage.getItem('rum-bundler-token');
}

function isIncognitoMode() {
return new URL(window.location.href).searchParams.get('domainkey') === 'incognito';
}

export default class URLSelector extends HTMLElement {
constructor() {
super();
Expand Down Expand Up @@ -41,32 +45,36 @@ export default class URLSelector extends HTMLElement {
const img = this.querySelector('img');
img.src = `https://www.google.com/s2/favicons?domain=${input.value.split(':')[0]}&sz=64`;

const token = getPersistentToken();
if (!token) {
if (!getPersistentToken()) {
input.disabled = true;
datalist.remove();
} else {
fetch('https://rum.fastly-aem.page/domains?suggested=true', {
headers: {
accept: 'application/json',
authorization: `Bearer ${token}`,
},
}).then(async (resp) => {
if (!resp.ok) {
datalist.remove();
} else {
const { domains } = await resp.json();
domains.forEach((domain) => {
const option = document.createElement('option');
option.value = domain;
datalist.appendChild(option);
});
}
}).catch(() => {
datalist.remove();
});
}

input.addEventListener('mouseover', () => {
const token = getPersistentToken();
if (token && !isIncognitoMode()) {
fetch('https://rum.fastly-aem.page/domains?suggested=true', {
headers: {
accept: 'application/json',
authorization: `Bearer ${token}`,
},
}).then(async (resp) => {
if (!resp.ok) {
datalist.remove();
} else {
const { domains } = await resp.json();
domains.forEach((domain) => {
const option = document.createElement('option');
option.value = domain;
datalist.appendChild(option);
});
}
}).catch(() => {
datalist.remove();
});
}
}, { once: true });

input.addEventListener('focus', () => {
input.select();
});
Expand Down
Loading