Skip to content

Commit

Permalink
Test lastFocusedTree
Browse files Browse the repository at this point in the history
  • Loading branch information
CarolineDenis committed Sep 13, 2023
1 parent 578d9b7 commit d1524d4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
8 changes: 7 additions & 1 deletion specifyweb/frontend/js_src/lib/components/TreeView/Row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export function TreeRow({
setFocusedRow,
synonymColor,
treeName,
setLastFocusedTree,
}: {
readonly row: Row;
readonly getRows: (parentId: number | 'null') => Promise<RA<Row>>;
Expand All @@ -53,6 +54,7 @@ export function TreeRow({
readonly setFocusedRow: (row: Row) => void;
readonly synonymColor: string;
readonly treeName: string;
readonly setLastFocusedTree: () => void;
}): JSX.Element {
const [rows, setRows] = React.useState<RA<Row> | undefined>(undefined);
const [childStats, setChildStats] = React.useState<Stats | undefined>(
Expand All @@ -63,7 +65,10 @@ export function TreeRow({
);

React.useEffect(() => {
if (Array.isArray(focusPath) && focusPath.length === 0) setFocusedRow(row);
if (Array.isArray(focusPath) && focusPath.length === 0) {
setFocusedRow(row);
setLastFocusedTree();
}
}, [setFocusedRow, focusPath, row]);

// Fetch children
Expand Down Expand Up @@ -330,6 +335,7 @@ export function TreeRow({
onFocusNode={(newFocusedNode): void =>
handleFocusNode([childRow.nodeId, ...newFocusedNode])
}
setLastFocusedTree={setLastFocusedTree}
/>
))}
</ul>
Expand Down
3 changes: 3 additions & 0 deletions specifyweb/frontend/js_src/lib/components/TreeView/Tree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export function Tree<SCHEMA extends AnyTree>({
focusRef,
searchBoxRef,
baseUrl,
setLastFocusedTree,
}: {
readonly treeDefinitionItems: RA<
SerializedResource<FilterTablesByEndsWith<'TreeDefItem'>>
Expand All @@ -59,6 +60,7 @@ export function Tree<SCHEMA extends AnyTree>({
readonly focusRef: React.MutableRefObject<HTMLAnchorElement | null>;
readonly searchBoxRef: React.RefObject<HTMLInputElement | null>;
readonly baseUrl: string;
readonly setLastFocusedTree: () => void;
}): JSX.Element {
const highContrast = useHighContrast();

Expand Down Expand Up @@ -219,6 +221,7 @@ export function Tree<SCHEMA extends AnyTree>({
onFocusNode={(newFocusPath): void =>
setFocusPath([row.nodeId, ...newFocusPath])
}
setLastFocusedTree={setLastFocusedTree}
/>
))}
</ul>
Expand Down
10 changes: 7 additions & 3 deletions specifyweb/frontend/js_src/lib/components/TreeView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ function TreeView<SCHEMA extends AnyTree>({
'tree',
`focusPath${tableName}`
);

const [focusPath1 = [], setFocusPath1] = React.useState<RA<number>>();
const [focusPath2 = [], setFocusPath2] = React.useState<RA<number>>();

Expand All @@ -122,9 +121,13 @@ function TreeView<SCHEMA extends AnyTree>({
undefined
);

const [lastFocusedTree, setLastFocusedTree] = React.useState<boolean>(true);

React.useEffect(() => {
setFocusedRow(focusedRow1);
// setFocusedRow(focusedRow2);
if (lastFocusedTree === true) setFocusedRow(focusedRow1);
else {
setFocusedRow(focusedRow2);
}
}, [focusedRow1, focusedRow2]);

const [actionRow, setActionRow] = React.useState<Row | undefined>(undefined);
Expand Down Expand Up @@ -153,6 +156,7 @@ function TreeView<SCHEMA extends AnyTree>({
focusRef={toolbarButtonRef}
searchBoxRef={searchBoxRef}
baseUrl={baseUrl}
setLastFocusedTree={() => setLastFocusedTree(isFirst)}
/>
);

Expand Down

0 comments on commit d1524d4

Please sign in to comment.