Skip to content

Commit

Permalink
fix selected tree changed show old content
Browse files Browse the repository at this point in the history
  • Loading branch information
jrmyb committed Jul 20, 2023
1 parent e6e8bb3 commit 837c891
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {Pagination} from 'antd';
import {treeNavigationPageSize} from 'constants/constants';
import {treeNodeChildrenQuery} from 'graphQL/queries/trees/getTreeNodeChildren';
import {getTreeEvents} from 'graphQL/subscribes/trees/getTreeEvents';
import {useActiveTree} from 'hooks/ActiveTreeHook/ActiveTreeHook';
import {createRef, useEffect, useState} from 'react';
import {setNavigationPath} from 'reduxStore/navigation';
import {INavigationElement} from 'reduxStore/stateType';
Expand Down Expand Up @@ -44,13 +43,13 @@ const ColumnPagination = styled(Pagination)`
`;

interface IColumnProps {
treeId: string;
treeElement?: INavigationElement;
depth: number;
isActive: boolean;
}

const Column = ({treeElement, depth, isActive: columnActive}: IColumnProps) => {
const [activeTree] = useActiveTree();
const Column = ({treeId, treeElement, depth, isActive: columnActive}: IColumnProps) => {
const [currentPage, setCurrentPage] = useState<number>(1);
const [totalCount, setTotalCount] = useState<number>(0);

Expand All @@ -60,27 +59,27 @@ const Column = ({treeElement, depth, isActive: columnActive}: IColumnProps) => {
}));

const queryVariables = {
treeId: activeTree?.id,
treeId,
node: treeElement?.id ?? null,
pagination: {
limit: treeNavigationPageSize,
offset: (currentPage - 1) * treeNavigationPageSize
}
};

const {loading, error, data, refetch, called} = useQuery<TREE_NODE_CHILDREN, TREE_NODE_CHILDRENVariables>(
treeNodeChildrenQuery,
{
variables: queryVariables,
onCompleted: res => {
setTotalCount(res.treeNodeChildren.totalCount);
},
skip: !activeTree
}
}
);

useSubscription<TREE_EVENTS, TREE_EVENTSVariables>(getTreeEvents, {
variables: {filters: {ignoreOwnEvents: true, treeId: activeTree?.id, nodes: [treeElement?.id ?? null]}},
skip: !activeTree?.id || loading,
variables: {filters: {ignoreOwnEvents: true, treeId, nodes: [treeElement?.id ?? null]}},
skip: loading,
onSubscriptionData() {
// We known something happened concerning this node.
// To make sure everything is clean and up to date, we just refetch data
Expand All @@ -100,7 +99,7 @@ const Column = ({treeElement, depth, isActive: columnActive}: IColumnProps) => {
}, [ref, columnActive]);

useEffect(() => {
if (!activeTree || !called) {
if (!called) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ function NavigationView({tree: treeId}: INavigationViewProps): JSX.Element {

return (
<Page>
<Column treeElement={null} depth={0} isActive={currentColumnActive} key="__root__" />
<Column treeId={treeId} treeElement={null} depth={0} isActive={currentColumnActive} key="__root__" />
{navigation.path.map((pathPart, index) => (
<Column
treeId={treeId}
key={`${pathPart.record.id}`}
treeElement={pathPart}
depth={index + 1}
Expand Down

0 comments on commit 837c891

Please sign in to comment.