This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

fix

+98 -10
+2 -2
app/next-env.d.ts
··· 1 1 /// <reference types="next" /> 2 - /// <reference types="next/navigation-types/compat/navigation" /> 2 + /// <reference types="next/image-types/global" /> 3 3 4 4 // NOTE: This file should not be edited 5 - // see https://nextjs.org/docs/basic-features/typescript for more information. 5 + // see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information.
+3 -6
app/src/app/feed/page.tsx
··· 3 3 import { useState, useEffect } from 'react'; 4 4 import Link from 'next/link'; 5 5 import styles from './feed.module.css'; 6 + import { formatRelativeTime } from '@/lib/time-utils'; 6 7 7 8 // Types for our feed entries 8 9 interface FlushingEntry { ··· 61 62 } 62 63 }; 63 64 64 - // Format date to a readable string 65 - const formatDate = (dateString: string) => { 66 - const date = new Date(dateString); 67 - return date.toLocaleString(); 68 - }; 65 + // No longer needed - using formatRelativeTime from time-utils 69 66 70 67 return ( 71 68 <div className={styles.container}> ··· 116 113 @{entry.authorHandle} 117 114 </a> 118 115 <span className={styles.timestamp}> 119 - {formatDate(entry.createdAt)} 116 + {formatRelativeTime(entry.createdAt)} 120 117 </span> 121 118 </div> 122 119 <div className={styles.content}>
+1 -1
app/src/app/page.tsx
··· 5 5 import { useRouter } from 'next/navigation'; 6 6 import styles from './page.module.css'; 7 7 import { useAuth } from '@/lib/auth-context'; 8 - import { containsBannedWords, sanitizeText } from '@/lib/content-filter'; 8 + import { containsBannedWords, sanitizeText, formatRelativeTime } from '@/lib/content-filter'; 9 9 10 10 // Types for feed entries 11 11 interface FlushingEntry {
+2 -1
app/src/app/profile/[handle]/page.tsx
··· 5 5 import { useParams } from 'next/navigation'; 6 6 import styles from './profile.module.css'; 7 7 import { sanitizeText } from '@/lib/content-filter'; 8 + import { formatRelativeTime } from '@/lib/time-utils'; 8 9 9 10 // Types for feed entries 10 11 interface FlushingEntry { ··· 229 230 </span> 230 231 </div> 231 232 <span className={styles.timestamp}> 232 - {new Date(entry.created_at).toLocaleString()} 233 + {formatRelativeTime(entry.created_at)} 233 234 </span> 234 235 </div> 235 236 </div>
+53
app/src/lib/content-filter.ts
··· 145 145 if (!text) return false; 146 146 147 147 return EXPLICIT_SLUR_REGEXES.some(regex => regex.test(text)); 148 + } 149 + 150 + /** 151 + * Formats a date into a relative time string (e.g., "5 minutes ago", "2 days ago") 152 + * @param dateString The date string to format 153 + * @returns A relative time string 154 + */ 155 + export function formatRelativeTime(dateString: string): string { 156 + const date = new Date(dateString); 157 + const now = new Date(); 158 + const diffInSeconds = Math.floor((now.getTime() - date.getTime()) / 1000); 159 + 160 + // Less than a minute 161 + if (diffInSeconds < 60) { 162 + return 'just now'; 163 + } 164 + 165 + // Less than an hour 166 + if (diffInSeconds < 3600) { 167 + const minutes = Math.floor(diffInSeconds / 60); 168 + return `${minutes} ${minutes === 1 ? 'minute' : 'minutes'} ago`; 169 + } 170 + 171 + // Less than a day 172 + if (diffInSeconds < 86400) { 173 + const hours = Math.floor(diffInSeconds / 3600); 174 + return `${hours} ${hours === 1 ? 'hour' : 'hours'} ago`; 175 + } 176 + 177 + // Less than a week 178 + if (diffInSeconds < 604800) { 179 + const days = Math.floor(diffInSeconds / 86400); 180 + if (days === 1) { 181 + return 'yesterday'; 182 + } 183 + return `${days} days ago`; 184 + } 185 + 186 + // Less than a month 187 + if (diffInSeconds < 2592000) { 188 + const weeks = Math.floor(diffInSeconds / 604800); 189 + return `${weeks} ${weeks === 1 ? 'week' : 'weeks'} ago`; 190 + } 191 + 192 + // Less than a year 193 + if (diffInSeconds < 31536000) { 194 + const months = Math.floor(diffInSeconds / 2592000); 195 + return `${months} ${months === 1 ? 'month' : 'months'} ago`; 196 + } 197 + 198 + // More than a year 199 + const years = Math.floor(diffInSeconds / 31536000); 200 + return `${years} ${years === 1 ? 'year' : 'years'} ago`; 148 201 }
+37
app/src/lib/time-utils.ts
··· 1 + export function formatRelativeTime(dateString: string): string { 2 + const date = new Date(dateString); 3 + const now = new Date(); 4 + const diffInSeconds = Math.floor((now.getTime() - date.getTime()) / 1000); 5 + 6 + // Less than a minute 7 + if (diffInSeconds < 60) { 8 + return 'just now'; 9 + } 10 + 11 + // Minutes 12 + const minutes = Math.floor(diffInSeconds / 60); 13 + if (minutes < 60) { 14 + return `${minutes}m ago`; 15 + } 16 + 17 + // Hours 18 + const hours = Math.floor(minutes / 60); 19 + if (hours < 24) { 20 + return `${hours}h ago`; 21 + } 22 + 23 + // Days 24 + const days = Math.floor(hours / 24); 25 + if (days < 7) { 26 + return `${days}d ago`; 27 + } 28 + 29 + // Weeks 30 + const weeks = Math.floor(days / 7); 31 + if (weeks < 5) { 32 + return `${weeks}w ago`; 33 + } 34 + 35 + // Fallback to formatted date for older posts 36 + return date.toLocaleDateString(); 37 + }