import React, { useState } from 'react' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import { faHighlighter } from '@fortawesome/free-solid-svg-icons' import { Highlight } from '../types/highlights' import { HighlightItem } from './HighlightItem' import { useFilteredHighlights } from '../hooks/useFilteredHighlights' import { usePullToRefresh } from 'use-pull-to-refresh' import HighlightsPanelCollapsed from './HighlightsPanel/HighlightsPanelCollapsed' import HighlightsPanelHeader from './HighlightsPanel/HighlightsPanelHeader' import RefreshIndicator from './RefreshIndicator' import { RelayPool } from 'applesauce-relay' import { IEventStore } from 'applesauce-core' import { UserSettings } from '../services/settingsService' import { HighlightSkeleton } from './Skeletons' export interface HighlightVisibility { nostrverse: boolean friends: boolean mine: boolean } interface HighlightsPanelProps { highlights: Highlight[] loading: boolean isCollapsed: boolean onToggleCollapse: () => void onSelectUrl?: (url: string) => void selectedUrl?: string onToggleHighlights?: (show: boolean) => void selectedHighlightId?: string onRefresh?: () => void onHighlightClick?: (highlightId: string) => void currentUserPubkey?: string highlightVisibility?: HighlightVisibility onHighlightVisibilityChange?: (visibility: HighlightVisibility) => void followedPubkeys?: Set relayPool?: RelayPool | null eventStore?: IEventStore | null settings?: UserSettings } export const HighlightsPanel: React.FC = ({ highlights, loading, isCollapsed, onToggleCollapse, onSelectUrl, selectedUrl, onToggleHighlights, selectedHighlightId, onRefresh, onHighlightClick, currentUserPubkey, highlightVisibility = { nostrverse: true, friends: true, mine: true }, onHighlightVisibilityChange, followedPubkeys = new Set(), relayPool, eventStore, settings }) => { const [showHighlights, setShowHighlights] = useState(true) const [localHighlights, setLocalHighlights] = useState(highlights) const handleToggleHighlights = () => { const newValue = !showHighlights setShowHighlights(newValue) onToggleHighlights?.(newValue) } // Pull-to-refresh for highlights const { isRefreshing, pullPosition } = usePullToRefresh({ onRefresh: () => { if (onRefresh) { onRefresh() } }, maximumPullLength: 240, refreshThreshold: 80, isDisabled: !onRefresh }) // Keep track of highlight updates React.useEffect(() => { setLocalHighlights(highlights) }, [highlights]) const handleHighlightUpdate = (updatedHighlight: Highlight) => { setLocalHighlights(prev => prev.map(h => h.id === updatedHighlight.id ? updatedHighlight : h) ) } const handleHighlightDelete = (highlightId: string) => { // Remove highlight from local state setLocalHighlights(prev => prev.filter(h => h.id !== highlightId)) } const filteredHighlights = useFilteredHighlights({ highlights: localHighlights, selectedUrl, highlightVisibility, currentUserPubkey, followedPubkeys }) if (isCollapsed) { return ( 0} onToggleCollapse={onToggleCollapse} settings={settings} /> ) } return (
0} showHighlights={showHighlights} highlightVisibility={highlightVisibility} currentUserPubkey={currentUserPubkey} onToggleHighlights={handleToggleHighlights} onRefresh={onRefresh} onToggleCollapse={onToggleCollapse} onHighlightVisibilityChange={onHighlightVisibilityChange} /> {loading && filteredHighlights.length === 0 ? (
{Array.from({ length: 4 }).map((_, i) => ( ))}
) : filteredHighlights.length === 0 ? (

No highlights for this article.

{selectedUrl ? 'Create highlights for this article using a Nostr client that supports NIP-84.' : 'Select an article to view its highlights.'}

) : (
{filteredHighlights.map((highlight) => ( ))}
)}
) }