/******************************************************************************** * Copyright (c) 2026 Contributors to the Eclipse Foundation * * See the NOTICE file(s) distributed with this work for additional * information regarding copyright ownership. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * https://www.eclipse.org/legal/epl-2.0 * * SPDX-License-Identifier: EPL-2.0 ********************************************************************************/ import { FunctionComponent } from 'react'; import { Box, Container, Typography } from '@mui/material'; import { ExtensionCard } from '../../components/extension-card'; import { ExtensionGrid } from '../../components/page-primitives'; import { HomeCuratedSection } from '../../page-settings'; import { useSearch } from '../../hooks/use-search'; import { CURATED_SIZE, DEFAULT_CURATED_SECTIONS, useCuratedRows } from './use-home-data'; export interface CuratedSectionsProps { /** Rows to fetch and render; defaults to "Most downloaded" and "Recently updated". */ sections?: HomeCuratedSection[]; /** "See all" click handler; defaults to opening the search page unfiltered. */ onSeeAll?: () => void; } /** Renders the curated extension rows (e.g. "Most downloaded"), skipping empty/loading ones. */ export const CuratedSections: FunctionComponent = props => { const rows = useCuratedRows(props.sections ?? DEFAULT_CURATED_SECTIONS); const { search } = useSearch(); return ( <> {rows.map(row => { // Hide rows that loaded empty (e.g. a failed request). if (!row.loading && row.extensions.length === 0) { return null; } return ( {row.title} {row.subtitle} search({ query: '', sortBy: row.sortBy }))} sx={{ background: 'none', border: 'none', color: 'secondary.light', fontSize: '0.875rem', fontWeight: 600, cursor: 'pointer' }}> See all → {/* Fixed index-keyed slots so cards stay mounted across the swap and don't re-fade. */} {Array.from({ length: row.loading ? CURATED_SIZE : row.extensions.length }, (_, idx) => ( ))} ); })} ); };