11import { searchBskyPosts } from "@/lib/bsky" ;
22import { currentPosts , loading , error , contentSourceUrl } from "@/lib/signals" ;
3- import { useRef , useEffect } from "react" ;
43
5- export function ManualFetchButton ( ) {
6- const controllerRef = useRef < AbortController | null > ( null ) ;
7-
8- useEffect ( ( ) => {
9- return ( ) => {
10- // Cleanup: abort any pending request when component unmounts
11- if ( controllerRef . current ) {
12- controllerRef . current . abort ( ) ;
13- }
14- } ;
15- } , [ ] ) ;
4+ const handleFetch = ( ) => {
5+ loading . value = true ;
6+ error . value = "" ;
167
17- const handleFetch = async ( ) => {
18- // Abort previous request if it exists
19- if ( controllerRef . current ) {
20- controllerRef . current . abort ( ) ;
21- }
22-
23- loading . value = true ;
24- error . value = '' ;
25-
26- controllerRef . current = new AbortController ( ) ;
27-
28- try {
29- currentPosts . value = await searchBskyPosts ( contentSourceUrl . value , controllerRef . current . signal ) || [ ] ;
30- loading . value = false ;
31- } catch ( err : unknown ) {
32- // Don't set error if it was just aborted
33- if ( err instanceof Error && err . name !== 'AbortError' ) {
34- console . error ( 'Error fetching posts:' , err ) ;
35- error . value = err . message || 'Failed to fetch Bluesky posts' ;
36- }
37- loading . value = false ;
38- }
39- } ;
8+ searchBskyPosts ( contentSourceUrl . value )
9+ . then ( ( fetchedPosts ) => {
10+ if ( fetchedPosts ) {
11+ currentPosts . value = fetchedPosts ;
12+ // console.log(currentPosts.value.slice(0, 3));
13+ }
14+ loading . value = false ;
15+ } )
16+ . catch ( ( err ) => {
17+ error . value = err . message || "Failed to fetch Bluesky posts" ;
18+ loading . value = false ;
19+ } ) ;
20+ } ;
4021
41- return (
42- < button
43- className = "flex items-center justify-center gap-1.5 px-3 py-1.5 bg-green-100 hover:bg-green-200 dark:bg-green-900/30 dark:hover:bg-green-800/40 text-green-700 dark:text-green-300 rounded-md text-sm font-medium transition-colors"
44- onClick = { handleFetch }
45- aria-label = "Search for Bluesky posts"
46- >
47- < Icon name = "magnifying" className = "h-4 w-4" />
48- Search Posts
49- </ button >
50- ) ;
51- }
22+ export function ManualFetchButton ( ) {
23+ return (
24+ < button
25+ className = "flex items-center justify-center gap-1.5 px-3 py-1.5 bg-green-100 hover:bg-green-200 dark:bg-green-900/30 dark:hover:bg-green-800/40 text-green-700 dark:text-green-300 rounded-md text-sm font-medium transition-colors"
26+ onClick = { handleFetch }
27+ aria-label = "Search for Bluesky posts"
28+ >
29+ < Icon name = "magnifying" className = "h-4 w-4" />
30+ Search Posts
31+ </ button >
32+ ) ;
33+ }
0 commit comments