import { AddLinkEventTracker, ILinkEventTracker, RemoveLinkEventTracker } from '@nitrots/nitro-renderer'; import { FC, useEffect, useState } from 'react'; import { FaBars, FaCog, FaEdit, FaEye, FaEyeSlash, FaPlus, FaTrash } from 'react-icons/fa'; import { CatalogType, GetConfigurationValue, LocalizeShortNumber, LocalizeText } from '../../api'; import { Column, Grid, LayoutCurrencyIcon, NitroCardContentView, NitroCardHeaderView, NitroCardTabsItemView, NitroCardTabsView, NitroCardView } from '../../common'; import { useCatalogActions, useCatalogData, useCatalogUiState, useHasPermission, usePurse } from '../../hooks'; import { CatalogAdminProvider, useCatalogAdmin } from './CatalogAdminContext'; import { CatalogAdminOfferEditView } from './views/admin/CatalogAdminOfferEditView'; import { CatalogAdminPageEditView } from './views/admin/CatalogAdminPageEditView'; import { CatalogBuildersClubStatusView } from './views/catalog-header/CatalogBuildersClubStatusView'; import { CatalogIconView } from './views/catalog-icon/CatalogIconView'; import { CatalogGiftView } from './views/gift/CatalogGiftView'; import { CatalogBreadcrumbView } from './views/navigation/CatalogBreadcrumbView'; import { CatalogNavigationView } from './views/navigation/CatalogNavigationView'; import { CatalogSearchView } from './views/page/common/CatalogSearchView'; import { GetCatalogLayout } from './views/page/layout/GetCatalogLayout'; import { MarketplacePostOfferView } from './views/page/layout/marketplace/MarketplacePostOfferView'; const CatalogClassicViewInner: FC<{}> = () => { const { rootNode = null, currentPage = null, searchResult = null } = useCatalogData(); const { isVisible = false, setIsVisible = null, navigationHidden = false, setNavigationHidden = null, activeNodes = [], setSearchResult = null, currentType = CatalogType.NORMAL } = useCatalogUiState(); const { openPageByName = null, openPageByOfferId = null, activateNode = null, openCatalogByType = null, toggleCatalogByType = null } = useCatalogActions(); const catalogAdmin = useCatalogAdmin(); const adminMode = catalogAdmin?.adminMode ?? false; const setAdminMode = catalogAdmin?.setAdminMode ?? (() => {}); const hasPendingChanges = catalogAdmin?.hasPendingChanges ?? false; const publishCatalog = catalogAdmin?.publishCatalog ?? (() => {}); const loading = catalogAdmin?.loading ?? false; const isMod = useHasPermission('acc_catalogfurni'); const [ mobileMenuOpen, setMobileMenuOpen ] = useState(false); const { purse = null } = usePurse(); const displayedCurrencies = GetConfigurationValue('system.currency.types', []); const buildersClubHeaderStyle = (currentType === CatalogType.BUILDER) ? { borderColor: '#d79d2e', borderBottomColor: '#000', background: 'linear-gradient(180deg, #d89f2d 0%, #c68515 100%)' } : undefined; useEffect(() => { const getCatalogTypeFromLink = (type?: string) => { switch((type || '').toLowerCase()) { case 'bc': case 'builder': case 'buildersclub': case 'builders_club': return CatalogType.BUILDER; default: return CatalogType.NORMAL; } }; const linkTracker: ILinkEventTracker = { linkReceived: (url: string) => { const parts = url.split('/'); if(parts.length < 2) return; switch(parts[1]) { case 'show': if(parts.length > 2) { openCatalogByType(getCatalogTypeFromLink(parts[2])); return; } setIsVisible(true); return; case 'hide': setIsVisible(false); return; case 'toggle': if(parts.length > 2) { toggleCatalogByType(getCatalogTypeFromLink(parts[2])); return; } setIsVisible(prevValue => !prevValue); return; case 'open': if(parts.length > 2) { if(parts.length === 4) { switch(parts[2]) { case 'offerId': openPageByOfferId(parseInt(parts[3])); return; } } else { openPageByName(parts[2]); } } else { setIsVisible(true); } return; } }, eventUrlPrefix: 'catalog/' }; AddLinkEventTracker(linkTracker); return () => RemoveLinkEventTracker(linkTracker); }, [ setIsVisible, openPageByOfferId, openPageByName, openCatalogByType, toggleCatalogByType ]); return ( <> { isVisible && setIsVisible(false) } style={ buildersClubHeaderStyle } />
{ isMod &&
{ mobileMenuOpen &&
{ adminMode && }
}
}
{ LocalizeShortNumber(purse?.credits ?? 0) }
{ displayedCurrencies.map(type => (
{ LocalizeShortNumber(purse?.activityPoints?.get(type) ?? 0) }
)) }
{ adminMode &&
Admin Mode
} { rootNode && (rootNode.children.length > 0) && rootNode.children.map((child, index) => { if(!adminMode && !child.isVisible) return null; const isHidden = !child.isVisible; return ( { if(searchResult) setSearchResult(null); activateNode(child); } }>
{ child.localization } { adminMode && isHidden && } { adminMode &&
e.stopPropagation() }> { catalogAdmin.setEditingPageNode(child); catalogAdmin.setEditingRootPage(false); catalogAdmin.setEditingPageData(true); } } /> catalogAdmin.togglePageVisible(child.pageId) }> { isHidden ? : } { if(confirm(LocalizeText('catalog.admin.delete.category.confirm', [ 'name' ], [ child.localization ]))) catalogAdmin.deletePage(child.pageId); } } />
}
); }) } { isMod && setAdminMode(!adminMode) }> }
{ adminMode && rootNode &&
}
{ !navigationHidden &&
{ activeNodes && (activeNodes.length > 0) && }
}
{ /* info_duckets renders its own logo in the body (BcInfoView) — don't duplicate it in the hero */ } { (currentPage?.layoutCode !== 'info_duckets') && !!currentPage?.localization?.getImage(0) && }
{ adminMode && } { GetCatalogLayout(currentPage, () => setNavigationHidden(true)) }
} ); }; export const CatalogClassicView: FC<{}> = () => { return ( ); };