app_store: make widget retry every second if initial fetch fails

This commit is contained in:
dr-frmr 2024-09-18 15:31:40 -04:00
parent 31f73db0b0
commit 85f22776f1
No known key found for this signature in database

View File

@ -139,33 +139,41 @@ fn make_widget() -> String {
<div id="latest-apps"></div> <div id="latest-apps"></div>
<script> <script>
document.addEventListener('DOMContentLoaded', function() { document.addEventListener('DOMContentLoaded', function() {
fetch('/main:app_store:sys/apps', { credentials: 'include' }) function fetchApps() {
.then(response => response.json()) fetch('/main:app_store:sys/apps', { credentials: 'include' })
.then(data => { .then(response => response.json())
const container = document.getElementById('latest-apps'); .then(data => {
data.forEach(app => { const container = document.getElementById('latest-apps');
if (app.metadata) { container.innerHTML = '';
const a = document.createElement('a'); data.forEach(app => {
a.className = 'app'; if (app.metadata) {
a.href = `/main:app_store:sys/app/${app.package_id.package_name}:${app.package_id.publisher_node}` const a = document.createElement('a');
a.target = '_blank'; a.className = 'app';
a.rel = 'noopener noreferrer'; a.href = `/main:app_store:sys/app/${app.package_id.package_name}:${app.package_id.publisher_node}`
const iconLetter = app.metadata_hash.replace('0x', '')[0].toUpperCase(); a.target = '_blank';
a.innerHTML = `<div a.rel = 'noopener noreferrer';
class="app-image" const iconLetter = app.metadata_hash.replace('0x', '')[0].toUpperCase();
style=" a.innerHTML = `<div
background-image: url('${app.metadata.image || `/bird-orange.svg`}'); class="app-image"
" style="
></div> background-image: url('${app.metadata.image || `/bird-orange.svg`}');
<div class="app-info"> "
<h2>${app.metadata.name}</h2> ></div>
<p>${app.metadata.description}</p> <div class="app-info">
</div>`; <h2>${app.metadata.name}</h2>
<p>${app.metadata.description}</p>
</div>`;
container.appendChild(a); container.appendChild(a);
} }
});
})
.catch(error => {
console.error('Error fetching apps:', error);
setTimeout(fetchApps, 1000); // Retry after a second
}); });
}) }
.catch(error => console.error('Error fetching apps:', error));
fetchApps();
}); });
</script> </script>
</body> </body>