CHRISDANIEL145 commited on
Commit
47b16cf
·
1 Parent(s): 4aa7201

Fix: Add dashboard reload feedback and absolute DB path

Browse files
Files changed (2) hide show
  1. app.py +6 -3
  2. templates/dashboard.html +26 -0
app.py CHANGED
@@ -188,9 +188,12 @@ class TruthCheckSystem:
188
  # Initialize system
189
  truthcheck_system_instance = TruthCheckSystem()
190
 
 
 
 
191
  def init_db():
192
  """Initialize SQLite database"""
193
- conn = sqlite3.connect('history.db')
194
  c = conn.cursor()
195
  c.execute('''
196
  CREATE TABLE IF NOT EXISTS verifications (
@@ -231,7 +234,7 @@ def create_app():
231
  @app.route('/api/history')
232
  def get_history():
233
  try:
234
- conn = sqlite3.connect('history.db')
235
  conn.row_factory = sqlite3.Row
236
  c = conn.cursor()
237
  c.execute('SELECT * FROM verifications ORDER BY date DESC LIMIT 50')
@@ -264,7 +267,7 @@ def create_app():
264
 
265
  # Save to DB
266
  try:
267
- conn = sqlite3.connect('history.db')
268
  c = conn.cursor()
269
  c.execute('INSERT INTO verifications (claim, label, confidence) VALUES (?, ?, ?)',
270
  (claim_text, label, float(confidence)))
 
188
  # Initialize system
189
  truthcheck_system_instance = TruthCheckSystem()
190
 
191
+
192
+ DB_PATH = os.path.join(os.getcwd(), 'history.db')
193
+
194
  def init_db():
195
  """Initialize SQLite database"""
196
+ conn = sqlite3.connect(DB_PATH)
197
  c = conn.cursor()
198
  c.execute('''
199
  CREATE TABLE IF NOT EXISTS verifications (
 
234
  @app.route('/api/history')
235
  def get_history():
236
  try:
237
+ conn = sqlite3.connect(DB_PATH)
238
  conn.row_factory = sqlite3.Row
239
  c = conn.cursor()
240
  c.execute('SELECT * FROM verifications ORDER BY date DESC LIMIT 50')
 
267
 
268
  # Save to DB
269
  try:
270
+ conn = sqlite3.connect(DB_PATH)
271
  c = conn.cursor()
272
  c.execute('INSERT INTO verifications (claim, label, confidence) VALUES (?, ?, ?)',
273
  (claim_text, label, float(confidence)))
templates/dashboard.html CHANGED
@@ -208,14 +208,40 @@
208
  document.addEventListener('DOMContentLoaded', loadHistory);
209
 
210
  async function loadHistory() {
 
 
 
211
  try {
 
 
 
 
212
  const response = await fetch('/api/history');
213
  const data = await response.json();
214
 
 
 
 
 
215
  updateStats(data);
216
  renderTable(data);
 
 
 
 
 
 
 
 
217
  } catch (error) {
218
  console.error("Failed to load history:", error);
 
 
 
 
 
 
 
219
  }
220
  }
221
 
 
208
  document.addEventListener('DOMContentLoaded', loadHistory);
209
 
210
  async function loadHistory() {
211
+ const btn = document.querySelector('button[onclick="loadHistory()"]');
212
+ const originalContent = btn.innerHTML;
213
+
214
  try {
215
+ // Set loading state
216
+ btn.disabled = true;
217
+ btn.innerHTML = '<i class="fa-solid fa-circle-notch fa-spin mr-2"></i> Loading...';
218
+
219
  const response = await fetch('/api/history');
220
  const data = await response.json();
221
 
222
+ if (data.error) {
223
+ throw new Error(data.error);
224
+ }
225
+
226
  updateStats(data);
227
  renderTable(data);
228
+
229
+ // Show success briefly
230
+ btn.innerHTML = '<i class="fa-solid fa-check mr-2"></i> Updated';
231
+ setTimeout(() => {
232
+ btn.innerHTML = originalContent;
233
+ btn.disabled = false;
234
+ }, 1000);
235
+
236
  } catch (error) {
237
  console.error("Failed to load history:", error);
238
+ btn.innerHTML = '<i class="fa-solid fa-triangle-exclamation mr-2"></i> Error';
239
+ alert("Failed to refresh history: " + error.message);
240
+
241
+ setTimeout(() => {
242
+ btn.innerHTML = originalContent;
243
+ btn.disabled = false;
244
+ }, 2000);
245
  }
246
  }
247