diff --git a/web/src/components/browse/namespace-grid.tsx b/web/src/components/browse/namespace-grid.tsx new file mode 100644 index 00000000..33ad4a71 --- /dev/null +++ b/web/src/components/browse/namespace-grid.tsx @@ -0,0 +1,44 @@ +import React, { useRef, useEffect, useCallback } from 'react'; + +import { BiggestNamespaceResults } from '../../../types'; + +type Props = { + namespaces: BiggestNamespaceResults[] | undefined; + selectedNamespace: string | undefined; + handleSelectNamespace: (selectedNamespace: string) => void; +}; + +export const NamespaceGrid = (props: Props) => { + const { + namespaces, + selectedNamespace, + handleSelectNamespace + } = props; + + return ( +
+
+
+ {namespaces && ( + Object.values(namespaces).map((item, index: number) => ( +
+
+ +
+
+ )) + )} +
+
+
+ ); +}; diff --git a/web/src/pages/Browse.tsx b/web/src/pages/Browse.tsx index bd28bdfc..c8edcc1a 100644 --- a/web/src/pages/Browse.tsx +++ b/web/src/pages/Browse.tsx @@ -15,6 +15,8 @@ import { LoadingSpinner } from '../components/spinners/loading-spinner'; import { Markdown } from '../components/markdown/render'; import { ProjectAccordion } from '../components/browse/project-accordion' import { NamespaceLongRow } from '../components/browse/namespace-long-row' +import { NamespaceGrid } from '../components/browse/namespace-grid' + type View = 'peps' | 'schemas'; @@ -113,60 +115,7 @@ export function Browse() { ); } - const renderRow = (startIndex: number, endIndex: number) => ( -
-
- {namespaces?.data?.results ? ( - Object.values(namespaces.data.results) - .slice(startIndex, endIndex) - .map((item, index: number) => ( -
-
-
-

- handleSelectNamespace(item?.namespace)}> - {startIndex + index + 1}. {item?.namespace} - -

-

- {item?.number_of_projects} Projects -

-
-
-
- )) - ) : null} -
-
- ); - - const renderNamespaceGrid = () => ( -
-
-
- {namespaces?.data?.results ? - Object.values(namespaces.data.results).map((item, index: number) => ( -
-
- -
-
- )) - : null} -
-
-
- ); - + return (
@@ -198,7 +147,11 @@ export function Browse() {
{selectedNamespace === undefined ?
- {renderNamespaceGrid()} +
: