- Fixed info page not receiving live updates by implementing callsign-specific PubSub topics - Added automatic time counter for "Last Position" and other timestamps using JavaScript hook - Optimized map updates to only move marker instead of reloading entire map - Fixed APRS parser to properly handle [000/000/A=altitude format in comments - Removed packet caching on info page for real-time updates The info page now properly subscribes to updates for the specific callsign being viewed, timestamps automatically count up without page refresh, and the map smoothly animates marker position changes instead of flickering with full reloads. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
69 lines
No EOL
1.9 KiB
JavaScript
69 lines
No EOL
1.9 KiB
JavaScript
// Hook to automatically update time ago displays
|
|
export default {
|
|
mounted() {
|
|
this.startTimer();
|
|
},
|
|
|
|
destroyed() {
|
|
this.stopTimer();
|
|
},
|
|
|
|
updated() {
|
|
// Restart timer when the element updates
|
|
this.stopTimer();
|
|
this.startTimer();
|
|
},
|
|
|
|
startTimer() {
|
|
const updateTimeAgo = () => {
|
|
const timestampStr = this.el.dataset.timestamp;
|
|
if (!timestampStr) return;
|
|
|
|
const timestamp = new Date(timestampStr);
|
|
const now = new Date();
|
|
const diffMs = now - timestamp;
|
|
const diffSeconds = Math.floor(diffMs / 1000);
|
|
|
|
if (diffSeconds < 60) {
|
|
this.el.textContent = `${diffSeconds} second${diffSeconds !== 1 ? 's' : ''} ago`;
|
|
} else if (diffSeconds < 3600) {
|
|
const minutes = Math.floor(diffSeconds / 60);
|
|
this.el.textContent = `${minutes} minute${minutes !== 1 ? 's' : ''} ago`;
|
|
} else if (diffSeconds < 86400) {
|
|
const hours = Math.floor(diffSeconds / 3600);
|
|
this.el.textContent = `${hours} hour${hours !== 1 ? 's' : ''} ago`;
|
|
} else {
|
|
const days = Math.floor(diffSeconds / 86400);
|
|
this.el.textContent = `${days} day${days !== 1 ? 's' : ''} ago`;
|
|
}
|
|
};
|
|
|
|
// Update immediately
|
|
updateTimeAgo();
|
|
|
|
// Update every second for recent timestamps, less frequently for older ones
|
|
const timestampStr = this.el.dataset.timestamp;
|
|
if (timestampStr) {
|
|
const timestamp = new Date(timestampStr);
|
|
const age = Date.now() - timestamp;
|
|
|
|
let interval;
|
|
if (age < 60000) { // Less than 1 minute old
|
|
interval = 1000; // Update every second
|
|
} else if (age < 3600000) { // Less than 1 hour old
|
|
interval = 60000; // Update every minute
|
|
} else {
|
|
interval = 300000; // Update every 5 minutes
|
|
}
|
|
|
|
this.timer = setInterval(updateTimeAgo, interval);
|
|
}
|
|
},
|
|
|
|
stopTimer() {
|
|
if (this.timer) {
|
|
clearInterval(this.timer);
|
|
this.timer = null;
|
|
}
|
|
}
|
|
}; |