broadfield-dev commited on
Commit
dda464b
·
verified ·
1 Parent(s): 9383dc3

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +20 -3
templates/index.html CHANGED
@@ -36,9 +36,9 @@
36
  {% for category, articles in categorized_articles.items() %}
37
  <div class="category-section">
38
  <div class="category-title">{{ category }}</div>
39
- <div class="tiles">
40
  {% for article in articles %}
41
- <div class="article-tile">
42
  {% if article.image != "svg" %}
43
  <img src="{{ article.image }}" alt="Article Image">
44
  {% else %}
@@ -66,7 +66,23 @@
66
  .then(response => response.json())
67
  .then(data => {
68
  if (data.status === "complete") {
69
- location.reload(); // Refresh page when loading is done
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
  } else {
71
  setTimeout(checkLoadingStatus, 2000); // Check every 2 seconds
72
  }
@@ -76,6 +92,7 @@
76
  setTimeout(checkLoadingStatus, 2000); // Retry on error
77
  });
78
  }
 
79
  document.addEventListener('DOMContentLoaded', () => {
80
  checkLoadingStatus();
81
  });
 
36
  {% for category, articles in categorized_articles.items() %}
37
  <div class="category-section">
38
  <div class="category-title">{{ category }}</div>
39
+ <div class="tiles" id="category-{{ category }}">
40
  {% for article in articles %}
41
+ <div class="article-tile" data-published="{{ article.published }}">
42
  {% if article.image != "svg" %}
43
  <img src="{{ article.image }}" alt="Article Image">
44
  {% else %}
 
66
  .then(response => response.json())
67
  .then(data => {
68
  if (data.status === "complete") {
69
+ // Soft refresh: fetch updated articles without full reload
70
+ fetch('/')
71
+ .then(response => response.text())
72
+ .then(html => {
73
+ const parser = new DOMParser();
74
+ const doc = parser.parseFromString(html, 'text/html');
75
+ const newCategories = doc.querySelectorAll('.category-section');
76
+ newCategories.forEach(newCat => {
77
+ const catId = newCat.querySelector('.tiles').id;
78
+ const existingCat = document.getElementById(catId);
79
+ if (existingCat) {
80
+ existingCat.innerHTML = newCat.querySelector('.tiles').innerHTML;
81
+ }
82
+ });
83
+ document.querySelector('.loading-message').style.display = 'none';
84
+ })
85
+ .catch(error => console.error('Error updating articles:', error));
86
  } else {
87
  setTimeout(checkLoadingStatus, 2000); // Check every 2 seconds
88
  }
 
92
  setTimeout(checkLoadingStatus, 2000); // Retry on error
93
  });
94
  }
95
+
96
  document.addEventListener('DOMContentLoaded', () => {
97
  checkLoadingStatus();
98
  });