@@ -26,14 +26,16 @@ interface UseRecentActivityOptions {
2626 limit ?: number ;
2727 /** Polling cadence override. Pass 0 to disable. */
2828 pollIntervalMs ?: number ;
29+ /** When false, no request is made and the feed stays empty. */
30+ enabled ?: boolean ;
2931}
3032
3133function isMockEnabled ( ) : boolean {
3234 return import . meta. env . VITE_USE_MOCK_ACTIVITY === "true" ;
3335}
3436
3537export function useRecentActivity ( options : UseRecentActivityOptions = { } ) : UseRecentActivityResult {
36- const { limit = 10 , pollIntervalMs = RECENT_ACTIVITY_POLL_INTERVAL_MS } = options ;
38+ const { limit = 10 , pollIntervalMs = RECENT_ACTIVITY_POLL_INTERVAL_MS , enabled = true } = options ;
3739 const mock = isMockEnabled ( ) ;
3840
3941 const [ items , setItems ] = useState < ActivityItem [ ] > ( [ ] ) ;
@@ -68,6 +70,13 @@ export function useRecentActivity(options: UseRecentActivityOptions = {}): UseRe
6870 ) ;
6971
7072 useEffect ( ( ) => {
73+ if ( ! enabled ) {
74+ setItems ( [ ] ) ;
75+ setError ( null ) ;
76+ setIsLoading ( false ) ;
77+ return ;
78+ }
79+
7180 const controller = new AbortController ( ) ;
7281 void fetchOnce ( controller . signal ) ;
7382
@@ -83,12 +92,13 @@ export function useRecentActivity(options: UseRecentActivityOptions = {}): UseRe
8392 controller . abort ( ) ;
8493 window . clearInterval ( intervalId ) ;
8594 } ;
86- } , [ fetchOnce , mock , pollIntervalMs ] ) ;
95+ } , [ fetchOnce , mock , pollIntervalMs , enabled ] ) ;
8796
8897 const refetch = useCallback ( async ( ) : Promise < void > => {
98+ if ( ! enabled ) return ;
8999 setIsLoading ( true ) ;
90100 await fetchOnce ( ) ;
91- } , [ fetchOnce ] ) ;
101+ } , [ fetchOnce , enabled ] ) ;
92102
93103 return { items, isLoading, error, refetch } ;
94104}
0 commit comments