import { __, _x } from '@wordpress/i18n' import classnames from 'classnames' import React, { useState } from 'react' import { isLicensed, shouldShowUpsell } from '../../utils/screen' import { buildUrl, fetchQueryParam } from '../../utils/urls' import { BlueprintIcon, CommunityIcon, LibraryIcon, SettingsIcon, SnippetsIcon } from './icons/ToolbarIcons' import { UpsellDialog } from './UpsellDialog' import type { ReactNode } from 'react' export const SUBPAGES = ['snippets', 'blueprints', 'cloud-community', 'cloud-library'] as const interface NavLink { name: string url?: string label: string external?: boolean icon?: ReactNode pro?: boolean pageSlug?: string subpage?: typeof SUBPAGES[number] end?: boolean } const UPPER_NAV_LINKS: readonly NavLink[] = [ { name: 'docs', url: 'https://codesnippets.pro/docs', label: __('Docs', 'code-snippets'), external: true }, { name: 'cloud', url: 'https://codesnippets.cloud/', label: __('Cloud Dashboard', 'code-snippets'), external: true }, { name: 'welcome', url: window.CODE_SNIPPETS?.urls.welcome, label: __("What's New", 'code-snippets'), pageSlug: 'code-snippets-welcome' }, { name: 'import-snippets', url: window.CODE_SNIPPETS?.urls.import, label: _x('Import', 'snippets', 'code-snippets'), pageSlug: 'import-code-snippets' } ] const LOWER_NAV_LINKS: readonly NavLink[] = [ { name: 'snippets', url: window.CODE_SNIPPETS?.urls.manage, label: __('Snippets', 'code-snippets'), icon: , pageSlug: 'snippets' }, { name: 'cloud-community', label: __('Community Cloud', 'code-snippets'), icon: , subpage: 'cloud-community' }, { name: 'cloud-library', label: __('My Library', 'code-snippets'), icon: , pro: true, subpage: 'cloud-library' }, { name: 'blueprints', label: __('Blueprints', 'code-snippets'), icon: , pro: true, subpage: 'blueprints' }, { name: 'settings', url: window.CODE_SNIPPETS?.urls.settings, label: __('Settings', 'code-snippets'), icon: , pageSlug: 'snippets-settings', end: true } ] interface UpperNavProps { setIsUpsellDialogOpen: (isOpen: boolean) => void } const UpperNav: React.FC = ({ setIsUpsellDialogOpen }) => {__('Code Snippets', 'code-snippets')} {UPPER_NAV_LINKS.map(link => {link.label} )} {shouldShowUpsell() && ( { event.preventDefault() setIsUpsellDialogOpen(true) }} > {__('Upgrade to Pro', 'code-snippets')} )} const currentPage = fetchQueryParam('page') const currentSubpage = fetchQueryParam('subpage') const isActiveLink = ({ pageSlug, subpage }: Readonly): boolean => { if (subpage) { return currentSubpage === subpage } if (pageSlug) { return !currentSubpage && currentPage === pageSlug } return false } const LowerNav = () => {LOWER_NAV_LINKS.map(link => {link.icon} {link.label} {link.pro && !isLicensed() && {__('Pro', 'code-snippets')}} )} export const Toolbar = () => { const [isUpsellDialogOpen, setIsUpsellDialogOpen] = useState(false) return ( ) }