import React, { useState } from 'react' import { __, sprintf } from '@wordpress/i18n' import { WithRestAPIContext } from '../../../hooks/useRestAPI' import { useSnippetView } from '../../../hooks/useSnippetView' import { isLicensed } from '../../../utils/screen' import { updateQueryParams } from '../../../utils/urls' import { ScreenMetaSlot } from '../../common/ScreenMetaSlot' import { SubnavTabs, getTabFromQuery } from '../../common/SubnavTabs' import { WithCloudSnippetDownloadsContext } from '../../common/cloud/WithCloudSnippetDownloadsContext' import { UpsellPage } from '../../common/UpsellDialog' import { WithCloudSearchContext, useCloudSearch } from './WithCloudSearchContext' import { CloudSearch } from './CloudSearch' import type { SubnavTab } from '../../common/SubnavTabs' const TAB_QUERY_PARAM = 'tab' const TABS: SubnavTab<'snippets' | 'bundles'>[] = [ { name: 'snippets', label: __('Snippets', 'code-snippets') }, { name: 'bundles', label: __('Bundles', 'code-snippets'), pro: true } ] const CommunityCloudInner = () => { const [currentTab, setCurrentTab] = useState(() => getTabFromQuery(TABS, TAB_QUERY_PARAM)) const { snippetView, setSnippetView } = useSnippetView() const { searchResults } = useCloudSearch() return ( <> 'snippets' === tab.name ? searchResults?.totalItems : undefined} currentTab={currentTab} setCurrentTab={tab => { updateQueryParams({ [TAB_QUERY_PARAM]: tab.name }) setCurrentTab(tab) }} />