import { CatalogModeComposer, ICatalogPageData } from 'nitro-renderer'; import { FC, useCallback, useEffect, useReducer, useState } from 'react'; import { CatalogEvent } from '../../events'; import { useUiEvent } from '../../hooks/events/ui/ui-event'; import { SendMessageHook } from '../../hooks/messages/message-event'; import { NitroCardContentView, NitroCardHeaderView, NitroCardTabsItemView, NitroCardTabsView, NitroCardView } from '../../layout'; import { LocalizeText } from '../../utils/LocalizeText'; import { CatalogMessageHandler } from './CatalogMessageHandler'; import { CatalogMode, CatalogViewProps } from './CatalogView.types'; import { CatalogContextProvider } from './context/CatalogContext'; import { CatalogReducer, initialCatalog } from './reducers/CatalogReducer'; import { CatalogNavigationView } from './views/navigation/CatalogNavigationView'; import { CatalogPageView } from './views/page/CatalogPageView'; export const CatalogView: FC = props => { const [ isVisible, setIsVisible ] = useState(false); const [ currentTab, setCurrentTab ] = useState(null); const [ catalogState, dispatchCatalogState ] = useReducer(CatalogReducer, initialCatalog); const { root = null } = catalogState; const onCatalogEvent = useCallback((event: CatalogEvent) => { switch(event.type) { case CatalogEvent.SHOW_CATALOG: setIsVisible(true); return; case CatalogEvent.TOGGLE_CATALOG: setIsVisible(value => !value); return; } }, []); useUiEvent(CatalogEvent.SHOW_CATALOG, onCatalogEvent); useUiEvent(CatalogEvent.TOGGLE_CATALOG, onCatalogEvent); useEffect(() => { if(!isVisible) return; if(!catalogState.root) { SendMessageHook(new CatalogModeComposer(CatalogMode.MODE_NORMAL)); } else { setCurrentTab(catalogState.root.children[0]); } }, [ isVisible, catalogState.root ]); return ( { isVisible && setIsVisible(false) } /> { root && root.children.length && root.children.map((page, index) => { return setCurrentTab(page) } /> }) }
}
); }