mirror of
https://github.com/billsonnn/nitro-react.git
synced 2024-11-23 14: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);
|
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 ]);
|
||||||
|
@ -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 />
|
||||||
|
@ -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">
|
||||||
|
@ -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) =>
|
||||||
|
Loading…
Reference in New Issue
Block a user