({
error,
setError,
result: _result,
setResult,
setViewState: setParentViewState,
onInstallComplete,
onSearchModeChange,
targetPlugin
}: Props)
| 46 | pluginId: string; |
| 47 | }; |
| 48 | export function DiscoverPlugins({ |
| 49 | error, |
| 50 | setError, |
| 51 | result: _result, |
| 52 | setResult, |
| 53 | setViewState: setParentViewState, |
| 54 | onInstallComplete, |
| 55 | onSearchModeChange, |
| 56 | targetPlugin |
| 57 | }: Props): React.ReactNode { |
| 58 | // View state |
| 59 | const [viewState, setViewState] = useState<ViewState>('plugin-list'); |
| 60 | const [selectedPlugin, setSelectedPlugin] = useState<InstallablePlugin | null>(null); |
| 61 | |
| 62 | // Data state |
| 63 | const [availablePlugins, setAvailablePlugins] = useState<InstallablePlugin[]>([]); |
| 64 | const [loading, setLoading] = useState(true); |
| 65 | const [installCounts, setInstallCounts] = useState<Map<string, number> | null>(null); |
| 66 | |
| 67 | // Search state |
| 68 | const [isSearchMode, setIsSearchModeRaw] = useState(false); |
| 69 | const setIsSearchMode = useCallback((active: boolean) => { |
| 70 | setIsSearchModeRaw(active); |
| 71 | onSearchModeChange?.(active); |
| 72 | }, [onSearchModeChange]); |
| 73 | const { |
| 74 | query: searchQuery, |
| 75 | setQuery: setSearchQuery, |
| 76 | cursorOffset: searchCursorOffset |
| 77 | } = useSearchInput({ |
| 78 | isActive: viewState === 'plugin-list' && isSearchMode && !loading, |
| 79 | onExit: () => { |
| 80 | setIsSearchMode(false); |
| 81 | } |
| 82 | }); |
| 83 | const isTerminalFocused = useTerminalFocus(); |
| 84 | const { |
| 85 | columns: terminalWidth |
| 86 | } = useTerminalSize(); |
| 87 | |
| 88 | // Filter plugins based on search query |
| 89 | const filteredPlugins = useMemo(() => { |
| 90 | if (!searchQuery) return availablePlugins; |
| 91 | const lowerQuery = searchQuery.toLowerCase(); |
| 92 | return availablePlugins.filter(plugin => plugin.entry.name.toLowerCase().includes(lowerQuery) || plugin.entry.description?.toLowerCase().includes(lowerQuery) || plugin.marketplaceName.toLowerCase().includes(lowerQuery)); |
| 93 | }, [availablePlugins, searchQuery]); |
| 94 | |
| 95 | // Selection state |
| 96 | const [selectedIndex, setSelectedIndex] = useState(0); |
| 97 | const [selectedForInstall, setSelectedForInstall] = useState<Set<string>>(new Set()); |
| 98 | const [installingPlugins, setInstallingPlugins] = useState<Set<string>>(new Set()); |
| 99 | |
| 100 | // Pagination for plugin list (continuous scrolling) |
| 101 | const pagination = usePagination<InstallablePlugin>({ |
| 102 | totalItems: filteredPlugins.length, |
| 103 | selectedIndex |
| 104 | }); |
| 105 |
nothing calls this directly
no test coverage detected