blob: a96c05d2afad91b9ebafb66d3134aebdc27f365d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
// Personal Dashboard JavaScript
// Auto-refresh every 5 minutes
const AUTO_REFRESH_INTERVAL = 5 * 60 * 1000; // 5 minutes in milliseconds
// Initialize auto-refresh on page load
document.addEventListener('DOMContentLoaded', function() {
// Set up auto-refresh
setInterval(autoRefresh, AUTO_REFRESH_INTERVAL);
});
// Auto-refresh function
async function autoRefresh() {
console.log('Auto-refreshing data...');
try {
const response = await fetch('/api/refresh', {
method: 'POST'
});
if (response.ok) {
// Reload the page to show updated data
window.location.reload();
}
} catch (error) {
console.error('Auto-refresh failed:', error);
}
}
// Manual refresh function
async function refreshData() {
const button = event.target;
const originalText = button.textContent;
// Show loading state
button.disabled = true;
button.innerHTML = 'Refreshing...<span class="spinner"></span>';
try {
const response = await fetch('/api/refresh', {
method: 'POST'
});
if (response.ok) {
// Update last updated time
const now = new Date();
const timeString = now.toLocaleTimeString('en-US', {
hour: 'numeric',
minute: '2-digit'
});
document.getElementById('last-updated').textContent = timeString;
// Reload the page to show updated data
setTimeout(() => {
window.location.reload();
}, 500);
} else {
throw new Error('Refresh failed');
}
} catch (error) {
console.error('Refresh failed:', error);
alert('Failed to refresh data. Please try again.');
button.disabled = false;
button.textContent = originalText;
}
}
// Filter tasks by status
function filterTasks(status) {
// This will be implemented in Phase 2
console.log('Filter tasks:', status);
}
// Toggle task completion
function toggleTask(taskId) {
// This will be implemented in Phase 2
console.log('Toggle task:', taskId);
}
|