'use client'; import { useState, useEffect } from 'react'; import { TwitterBookmark } from '../lib/bookmark-models'; import { BookmarkStorageService } from '../lib/bookmark-storage'; import { BookmarkList } from './bookmark-list'; export function BookmarkFetcher() { const [bookmarks, setBookmarks] = useState([]); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const [username, setUsername] = useState(''); const [authToken, setAuthToken] = useState(''); // Load existing bookmarks on mount useEffect(() => { const existingBookmarks = BookmarkStorageService.getBookmarks(); setBookmarks(existingBookmarks); }, []); const handleFetchBookmarks = async () => { if (!username || !authToken) { setError('Please enter your Twitter username and auth token'); return; } setLoading(true); setError(null); try { // Simple fetch to our API endpoint const response = await fetch('/api/sync-bookmarks', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ username, authToken }), }); const result = await response.json(); if (!result.success) { throw new Error(result.error || 'Failed to fetch bookmarks'); } // Load the newly saved bookmarks const updatedBookmarks = BookmarkStorageService.getBookmarks(); setBookmarks(updatedBookmarks); } catch (err) { setError(err instanceof Error ? err.message : 'Failed to fetch bookmarks'); } finally { setLoading(false); } }; const handleClearBookmarks = () => { BookmarkStorageService.clearAll(); setBookmarks([]); }; return (
{/* Input fields */}

Twitter Credentials

setUsername(e.target.value)} placeholder="your_twitter_username" className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" />
setAuthToken(e.target.value)} placeholder="your_auth_token" className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" />
{/* Action buttons */}
{bookmarks.length > 0 && ( )}
{/* Error message */} {error && (
{error}
)} {/* Bookmark list */}

Your Bookmarks

); }