| 1 |
import { Panel } from '@wordpress/components' |
| 2 |
import { Button } from '@wordpress/components' |
| 3 |
import { memo } from '@wordpress/element' |
| 4 |
import { __ } from '@wordpress/i18n' |
| 5 |
import { Icon, close } from '@wordpress/icons' |
| 6 |
import classNames from 'classnames' |
| 7 |
import { ImportCounter } from '@library/components/ImportCounter' |
| 8 |
import { SiteTypeSelector } from '@library/components/SiteTypeSelector' |
| 9 |
import { TaxonomySection } from '@library/components/TaxonomySection' |
| 10 |
import { TypeSelect } from '@library/components/TypeSelect' |
| 11 |
import { featured } from '@library/components/icons' |
| 12 |
import { brandMark } from '@library/components/icons/' |
| 13 |
import { useGlobalStore } from '@library/state/GlobalState' |
| 14 |
import { useSiteSettingsStore } from '@library/state/SiteSettings' |
| 15 |
import { useTaxonomyStore } from '@library/state/Taxonomies' |
| 16 |
import { useTemplatesStore } from '@library/state/Templates' |
| 17 |
import { useUserStore } from '@library/state/User' |
| 18 |
|
| 19 |
export const Sidebar = memo(function Sidebar() { |
| 20 |
const taxonomies = useTaxonomyStore((state) => state.taxonomies) |
| 21 |
const searchParams = useTemplatesStore((state) => state.searchParams) |
| 22 |
const updateTaxonomies = useTemplatesStore( |
| 23 |
(state) => state.updateTaxonomies, |
| 24 |
) |
| 25 |
const apiKey = useUserStore((state) => state.apiKey) |
| 26 |
const taxonomyType = |
| 27 |
searchParams.type === 'pattern' ? 'patternType' : 'layoutType' |
| 28 |
const isFeatured = !searchParams?.taxonomies[taxonomyType]?.slug?.length |
| 29 |
const setOpen = useGlobalStore((state) => state.setOpen) |
| 30 |
const [siteType, setSiteType] = useSiteSettingsStore((state) => [ |
| 31 |
Object.keys(state?.siteType)?.length > 0 |
| 32 |
? state?.siteType |
| 33 |
: { slug: '', title: 'Not set' }, |
| 34 |
state.setSiteType, |
| 35 |
]) |
| 36 |
|
| 37 |
return ( |
| 38 |
<> |
| 39 |
<div className="-ml-1.5 hidden px-5 text-extendify-black sm:flex"> |
| 40 |
<Icon icon={brandMark} size={40} /> |
| 41 |
</div> |
| 42 |
<div className="flex md:hidden items-center justify-end -mt-5 mx-1"> |
| 43 |
<Button |
| 44 |
onClick={() => setOpen(false)} |
| 45 |
icon={<Icon icon={close} size={24} />} |
| 46 |
label={__('Close library', 'extendify')} |
| 47 |
/> |
| 48 |
</div> |
| 49 |
<div className="px-5 hidden md:block"> |
| 50 |
<button |
| 51 |
onClick={() => |
| 52 |
updateTaxonomies({ |
| 53 |
[taxonomyType]: { slug: '', title: 'Featured' }, |
| 54 |
}) |
| 55 |
} |
| 56 |
className={classNames( |
| 57 |
'm-0 flex w-full cursor-pointer items-center space-x-1 bg-transparent px-0 py-2 text-left text-sm leading-none transition duration-200 hover:text-wp-theme-500', |
| 58 |
{ 'text-wp-theme-500': isFeatured }, |
| 59 |
)}> |
| 60 |
<Icon icon={featured} size={24} /> |
| 61 |
<span className="text-sm"> |
| 62 |
{__('Featured', 'extendify')} |
| 63 |
</span> |
| 64 |
</button> |
| 65 |
</div> |
| 66 |
<div className="mx-6 px-5 pt-0.5 sm:mx-0 sm:mb-8 sm:mt-0"> |
| 67 |
{Object.keys(siteType).length > 0 && ( |
| 68 |
<SiteTypeSelector |
| 69 |
value={siteType} |
| 70 |
setValue={(termData) => { |
| 71 |
setSiteType(termData) |
| 72 |
updateTaxonomies({ siteType: termData }) |
| 73 |
}} |
| 74 |
terms={taxonomies.siteType} |
| 75 |
/> |
| 76 |
)} |
| 77 |
</div> |
| 78 |
<TypeSelect className="mx-6 px-5 pt-0.5 sm:mx-0 sm:mb-8 sm:mt-0" /> |
| 79 |
<div className="mt-px hidden flex-grow overflow-y-auto overflow-x-hidden pb-36 pt-px sm:block space-y-6"> |
| 80 |
<Panel className="bg-transparent"> |
| 81 |
<TaxonomySection |
| 82 |
taxType={taxonomyType} |
| 83 |
taxonomies={taxonomies[taxonomyType]?.filter( |
| 84 |
(term) => !term?.designType, |
| 85 |
)} |
| 86 |
/> |
| 87 |
</Panel> |
| 88 |
<Panel className="bg-transparent"> |
| 89 |
<TaxonomySection |
| 90 |
taxLabel={__('Design', 'extendify')} |
| 91 |
taxType={taxonomyType} |
| 92 |
taxonomies={taxonomies[taxonomyType]?.filter((term) => |
| 93 |
Boolean(term?.designType), |
| 94 |
)} |
| 95 |
/> |
| 96 |
</Panel> |
| 97 |
</div> |
| 98 |
{!apiKey.length && ( |
| 99 |
<div className="px-5"> |
| 100 |
<ImportCounter /> |
| 101 |
</div> |
| 102 |
)} |
| 103 |
</> |
| 104 |
) |
| 105 |
}) |
| 106 |
|