Add automatic Git fetch with change detection and toast notifications

- Implement useGitFetch hook with 60-second polling
- Add toast notifications for remote changes detection
- Update GitDialog to show fetch status and manual refresh
- Add comprehensive tests for useGitFetch
- Update AGENTS.md documentation
- abstract simple time ago data function
This commit is contained in:
DanConwayDev authored and Alex Gleason committed 2025-11-10 09:11:05 -06:00
1 parent 50897e1164
commit 056f2a0b5f
6 files changed
+576 -18

No files matched your search

+53
View File
@@ -16,3 +16,56 @@ export function shuffleArray<T>(array: T[]): T[] {
}
return shuffled;
}
/**
* Formats a timestamp as a relative time string (e.g., "2 hours ago", "just now")
* @param timestamp - Unix timestamp in seconds or milliseconds, or a Date object
* @returns Human-readable relative time string
*/
export function formatRelativeTime(timestamp: number | Date): string {
const now = Date.now();
const time = timestamp instanceof Date ? timestamp.getTime() : timestamp;
// Handle both seconds and milliseconds timestamps
const timestampMs = time < 10000000000 ? time * 1000 : time;
const diffMs = now - timestampMs;
const diffSeconds = Math.floor(diffMs / 1000);
const diffMinutes = Math.floor(diffMs / (1000 * 60));
const diffHours = Math.floor(diffMs / (1000 * 60 * 60));
const diffDays = Math.floor(diffMs / (1000 * 60 * 60 * 24));
const diffWeeks = Math.floor(diffDays / 7);
const diffMonths = Math.floor(diffDays / 30);
const diffYears = Math.floor(diffDays / 365);
if (diffSeconds < 25) {
return 'just now';
} else if (diffSeconds < 35) {
return 'half a minute ago'
} else if (diffSeconds < 55) {
return 'less than a minute ago'
} else if (diffMinutes < 2) {
return 'a minute ago';
} else if (diffMinutes < 60) {
return `${diffMinutes} minutes ago`;
} else if (diffHours === 1) {
return 'an hour ago';
} else if (diffHours < 24) {
return `${diffHours} hours ago`;
} else if (diffDays === 1) {
return '1 day ago';
} else if (diffDays < 7) {
return `${diffDays} days ago`;
} else if (diffWeeks === 1) {
return '1 week ago';
} else if (diffWeeks < 4) {
return `${diffWeeks} weeks ago`;
} else if (diffMonths === 1) {
return '1 month ago';
} else if (diffMonths < 12) {
return `${diffMonths} months ago`;
} else if (diffYears === 1) {
return '1 year ago';
} else {
return `${diffYears} years ago`;
}
}