Its still busted

This commit is contained in:
Bill 2021-07-27 15:00:10 -04:00
parent 705569a5d1
commit 571b17feb5
4 changed files with 56 additions and 19 deletions

View File

@ -122,8 +122,8 @@ export const CatalogView: FC<CatalogViewProps> = props =>
const tree = buildCatalogPageTree(catalogState.root, pendingPageId); const tree = buildCatalogPageTree(catalogState.root, pendingPageId);
setCurrentTab(tree.shift()); setCurrentTab(tree.shift());
setPendingTree(tree);
setPendingPageId(-1); setPendingPageId(-1);
setPendingTree(tree);
} }
} }
}, [ isVisible, pendingPageId, catalogState.root, buildCatalogPageTree, setCurrentTab ]); }, [ isVisible, pendingPageId, catalogState.root, buildCatalogPageTree, setCurrentTab ]);

View File

@ -1,12 +1,27 @@
import { FC } from 'react'; import { ICatalogPageData } from 'nitro-renderer';
import { FC, useEffect } from 'react';
import { CatalogSearchView } from '../search/CatalogSearchView'; import { CatalogSearchView } from '../search/CatalogSearchView';
import { CatalogNavigationViewProps } from './CatalogNavigationView.types'; import { CatalogNavigationViewProps } from './CatalogNavigationView.types';
import { CatalogNavigationSetView } from './set/CatalogNavigationSetView'; import { CatalogNavigationSetView } from './set/CatalogNavigationSetView';
export const ACTIVE_PAGES: ICatalogPageData[] = [];
export const CatalogNavigationView: FC<CatalogNavigationViewProps> = props => export const CatalogNavigationView: FC<CatalogNavigationViewProps> = props =>
{ {
const { page = null, pendingTree = null, setPendingTree = null } = props; const { page = null, pendingTree = null, setPendingTree = null } = props;
useEffect(() =>
{
if(!page) return;
const index = (ACTIVE_PAGES.push(page) - 1);
return () =>
{
ACTIVE_PAGES.splice(index, 1);
}
}, [ page ]);
return ( return (
<> <>
<CatalogSearchView /> <CatalogSearchView />

View File

@ -2,8 +2,8 @@ import { CatalogPageComposer, ICatalogPageData } from 'nitro-renderer';
import { FC, useCallback, useEffect, useState } from 'react'; import { FC, useCallback, useEffect, useState } from 'react';
import { SendMessageHook } from '../../../../../hooks/messages/message-event'; import { SendMessageHook } from '../../../../../hooks/messages/message-event';
import { CatalogMode } from '../../../CatalogView.types'; import { CatalogMode } from '../../../CatalogView.types';
import { useCatalogContext } from '../../../context/CatalogContext';
import { CatalogIconView } from '../../catalog-icon/CatalogIconView'; import { CatalogIconView } from '../../catalog-icon/CatalogIconView';
import { ACTIVE_PAGES } from '../CatalogNavigationView';
import { CatalogNavigationSetView } from '../set/CatalogNavigationSetView'; import { CatalogNavigationSetView } from '../set/CatalogNavigationSetView';
import { CatalogNavigationItemViewProps } from './CatalogNavigationItemView.types'; import { CatalogNavigationItemViewProps } from './CatalogNavigationItemView.types';
@ -11,9 +11,8 @@ export const CatalogNavigationItemView: FC<CatalogNavigationItemViewProps> = pro
{ {
const { page = null, isActive = false, pendingTree = null, setPendingTree = null, setActiveChild = null } = props; const { page = null, isActive = false, pendingTree = null, setPendingTree = null, setActiveChild = null } = props;
const [ isExpanded, setIsExpanded ] = useState(false); const [ isExpanded, setIsExpanded ] = useState(false);
const { dispatchCatalogState = null } = useCatalogContext();
const select = useCallback((selectPage: ICatalogPageData) => const select = useCallback((selectPage: ICatalogPageData, expand: boolean = false) =>
{ {
if(!selectPage) return; if(!selectPage) return;
@ -21,7 +20,7 @@ export const CatalogNavigationItemView: FC<CatalogNavigationItemViewProps> = pro
{ {
if(prevValue === selectPage) if(prevValue === selectPage)
{ {
SendMessageHook(new CatalogPageComposer(selectPage.pageId, -1, CatalogMode.MODE_NORMAL)); if(selectPage.pageId > -1) SendMessageHook(new CatalogPageComposer(selectPage.pageId, -1, CatalogMode.MODE_NORMAL));
} }
return selectPage; return selectPage;
@ -31,32 +30,50 @@ export const CatalogNavigationItemView: FC<CatalogNavigationItemViewProps> = pro
{ {
setIsExpanded(prevValue => setIsExpanded(prevValue =>
{ {
if(expand) return true;
return !prevValue; return !prevValue;
}); });
} }
}, [ setActiveChild ]); }, [ setActiveChild ]);
useEffect(() =>
{
if(!pendingTree || !pendingTree.length) return;
if(page !== pendingTree[0]) return;
if(pendingTree.length > 1)
{
const newTree = [ ...pendingTree ];
newTree.shift();
setPendingTree(newTree);
}
else
{
setPendingTree(null);
}
select(page, true);
}, [ page, pendingTree, setPendingTree, select ]);
useEffect(() => useEffect(() =>
{ {
if(!isActive || !page) return; if(!isActive || !page) return;
setIsExpanded(true); setIsExpanded(true);
SendMessageHook(new CatalogPageComposer(page.pageId, -1, CatalogMode.MODE_NORMAL)); if(page.pageId > -1) SendMessageHook(new CatalogPageComposer(page.pageId, -1, CatalogMode.MODE_NORMAL));
}, [ isActive, page, select, dispatchCatalogState ]);
useEffect(() => const index = (ACTIVE_PAGES.push(page) - 1);
return () =>
{ {
if(!page || !pendingTree || !pendingTree.length) return; ACTIVE_PAGES.length = index;
}
const index = pendingTree.indexOf(page); }, [ isActive, page ]);
if(index === -1) return;
//if(!pendingTree.length) setPendingTree(null);
select(page);
}, [ pendingTree, page, select, setPendingTree ]);
return ( return (
<div className="col pb-1 catalog-navigation-item-container"> <div className="col pb-1 catalog-navigation-item-container">

View File

@ -16,10 +16,15 @@ export const CatalogNavigationSetView: FC<CatalogNavigationSetViewProps> = props
{ {
const child = page.children[0]; const child = page.children[0];
setActiveChild(child); //if(child) setActiveChild(child);
} }
}, [ page, isFirstSet, pendingTree ]); }, [ page, isFirstSet, pendingTree ]);
useEffect(() =>
{
console.log('activeChild', activeChild, page);
}, [ page, activeChild ]);
return ( return (
<div className="row row-cols-1 g-0 catalog-navigation-set-container w-100"> <div className="row row-cols-1 g-0 catalog-navigation-set-container w-100">
{ page && (page.children.length > 0) && page.children.map((page, index) => { page && (page.children.length > 0) && page.children.map((page, index) =>