mirror of
https://github.com/billsonnn/nitro-react.git
synced 2024-11-23 06:40:50 +01:00
Its still busted
This commit is contained in:
parent
705569a5d1
commit
571b17feb5
@ -122,8 +122,8 @@ export const CatalogView: FC<CatalogViewProps> = props =>
|
||||
const tree = buildCatalogPageTree(catalogState.root, pendingPageId);
|
||||
|
||||
setCurrentTab(tree.shift());
|
||||
setPendingTree(tree);
|
||||
setPendingPageId(-1);
|
||||
setPendingTree(tree);
|
||||
}
|
||||
}
|
||||
}, [ isVisible, pendingPageId, catalogState.root, buildCatalogPageTree, setCurrentTab ]);
|
||||
|
@ -1,12 +1,27 @@
|
||||
import { FC } from 'react';
|
||||
import { ICatalogPageData } from 'nitro-renderer';
|
||||
import { FC, useEffect } from 'react';
|
||||
import { CatalogSearchView } from '../search/CatalogSearchView';
|
||||
import { CatalogNavigationViewProps } from './CatalogNavigationView.types';
|
||||
import { CatalogNavigationSetView } from './set/CatalogNavigationSetView';
|
||||
|
||||
export const ACTIVE_PAGES: ICatalogPageData[] = [];
|
||||
|
||||
export const CatalogNavigationView: FC<CatalogNavigationViewProps> = 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 (
|
||||
<>
|
||||
<CatalogSearchView />
|
||||
|
@ -2,8 +2,8 @@ import { CatalogPageComposer, ICatalogPageData } from 'nitro-renderer';
|
||||
import { FC, useCallback, useEffect, useState } from 'react';
|
||||
import { SendMessageHook } from '../../../../../hooks/messages/message-event';
|
||||
import { CatalogMode } from '../../../CatalogView.types';
|
||||
import { useCatalogContext } from '../../../context/CatalogContext';
|
||||
import { CatalogIconView } from '../../catalog-icon/CatalogIconView';
|
||||
import { ACTIVE_PAGES } from '../CatalogNavigationView';
|
||||
import { CatalogNavigationSetView } from '../set/CatalogNavigationSetView';
|
||||
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 [ isExpanded, setIsExpanded ] = useState(false);
|
||||
const { dispatchCatalogState = null } = useCatalogContext();
|
||||
|
||||
const select = useCallback((selectPage: ICatalogPageData) =>
|
||||
const select = useCallback((selectPage: ICatalogPageData, expand: boolean = false) =>
|
||||
{
|
||||
if(!selectPage) return;
|
||||
|
||||
@ -21,7 +20,7 @@ export const CatalogNavigationItemView: FC<CatalogNavigationItemViewProps> = pro
|
||||
{
|
||||
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;
|
||||
@ -31,32 +30,50 @@ export const CatalogNavigationItemView: FC<CatalogNavigationItemViewProps> = pro
|
||||
{
|
||||
setIsExpanded(prevValue =>
|
||||
{
|
||||
if(expand) return true;
|
||||
|
||||
return !prevValue;
|
||||
});
|
||||
}
|
||||
}, [ 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(() =>
|
||||
{
|
||||
if(!isActive || !page) return;
|
||||
|
||||
setIsExpanded(true);
|
||||
|
||||
SendMessageHook(new CatalogPageComposer(page.pageId, -1, CatalogMode.MODE_NORMAL));
|
||||
}, [ isActive, page, select, dispatchCatalogState ]);
|
||||
if(page.pageId > -1) SendMessageHook(new CatalogPageComposer(page.pageId, -1, CatalogMode.MODE_NORMAL));
|
||||
|
||||
useEffect(() =>
|
||||
const index = (ACTIVE_PAGES.push(page) - 1);
|
||||
|
||||
return () =>
|
||||
{
|
||||
if(!page || !pendingTree || !pendingTree.length) return;
|
||||
|
||||
const index = pendingTree.indexOf(page);
|
||||
|
||||
if(index === -1) return;
|
||||
|
||||
//if(!pendingTree.length) setPendingTree(null);
|
||||
|
||||
select(page);
|
||||
}, [ pendingTree, page, select, setPendingTree ]);
|
||||
ACTIVE_PAGES.length = index;
|
||||
}
|
||||
}, [ isActive, page ]);
|
||||
|
||||
return (
|
||||
<div className="col pb-1 catalog-navigation-item-container">
|
||||
|
@ -16,10 +16,15 @@ export const CatalogNavigationSetView: FC<CatalogNavigationSetViewProps> = props
|
||||
{
|
||||
const child = page.children[0];
|
||||
|
||||
setActiveChild(child);
|
||||
//if(child) setActiveChild(child);
|
||||
}
|
||||
}, [ page, isFirstSet, pendingTree ]);
|
||||
|
||||
useEffect(() =>
|
||||
{
|
||||
console.log('activeChild', activeChild, page);
|
||||
}, [ page, activeChild ]);
|
||||
|
||||
return (
|
||||
<div className="row row-cols-1 g-0 catalog-navigation-set-container w-100">
|
||||
{ page && (page.children.length > 0) && page.children.map((page, index) =>
|
||||
|
Loading…
Reference in New Issue
Block a user