Ziya/app/composables/useRealTimeUpdate.ts
rizary 67fb3a203e
feat: implement CEX analysis cards and real-time token monitoring
- Add TokenCard and CexAnalysisCard components for displaying token data
- Implement real-time Redis event streaming for token updates
- Add environment-based configuration system for dev/prod Redis servers
- Create comprehensive hunting ground dashboard with card management
- Add individual and bulk card removal functionality
- Implement browser integration for token details viewing
- Add timestamp utilities and proper type handling for Redis events
- Create production-ready configuration with 154.38.185.112 Redis server
- Add comprehensive documentation in README.md and CONTRIBUTORS.md
- Restructure project architecture with proper Electron-Vue integration

BREAKING CHANGE: Redis configuration now uses environment-based settings
2025-06-23 09:03:39 +07:00

57 lines
No EOL
1.4 KiB
TypeScript

import { onMounted, onUnmounted, ref } from 'vue';
/**
* Composable for real-time timestamp updates
* Updates every second to show live "time ago" timestamps
*/
export function useRealTimeUpdate() {
const currentTime = ref(Date.now());
let intervalId: NodeJS.Timeout | null = null;
const updateTime = () => {
currentTime.value = Date.now();
};
onMounted(() => {
// Update every second for real-time display
intervalId = setInterval(updateTime, 1000);
});
onUnmounted(() => {
if (intervalId) {
clearInterval(intervalId);
}
});
return {
currentTime
};
}
/**
* Format timestamp to "time ago" string
* @param timestamp - Unix timestamp in seconds
* @param currentTime - Current time for real-time updates
*/
export function formatTimeAgo(timestamp: number, currentTime: number): string {
const now = Math.floor(currentTime / 1000);
const then = Math.floor(timestamp);
const diffSeconds = Math.max(0, now - then); // Prevent negative values
if (diffSeconds < 60) {
return `${diffSeconds}s ago`;
}
const diffMinutes = Math.floor(diffSeconds / 60);
if (diffMinutes < 60) {
return `${diffMinutes}m ago`;
}
const diffHours = Math.floor(diffMinutes / 60);
if (diffHours < 24) {
return `${diffHours}h ago`;
}
const diffDays = Math.floor(diffHours / 24);
return `${diffDays}d ago`;
}