Skip to content

Commit

Permalink
import cleanup (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
Opeyem1a authored Oct 20, 2024
1 parent b0a235c commit 4432264
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 34 deletions.
29 changes: 1 addition & 28 deletions src/commands/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,12 @@ import { Box, Text } from 'ink';
import { CommandConfig } from '../types.js';
import { Loading } from '../components/loading.js';
import { SelectRootBranch } from '../components/select-root-branch.js';
import { Tree } from '../services/tree.js';
import { treeToParentChildRecord } from '../utils/tree-helpers.js';
import { useGitHelpers } from '../hooks/use-git-helpers.js';
import { useTree } from '../hooks/use-tree.js';

const colorMap = ['blue', 'red', 'green', 'yellow', 'magenta', 'cyan', 'white'];

/**
* @returns a record mapping every branch name to the names of its child branches in the tree
*/
export const treeToParentChildRecord = (
tree: Tree
): Record<string, string[]> => {
const record: Record<string, string[]> = {};

tree.forEach((node) => {
if (!(node.key in record)) {
record[node.key] = [];
}

if (node.parent === null) return;

if (node.parent in record) {
const existingChildren = record[node.parent] as string[];
record[node.parent] = [...existingChildren, node.key];
}
if (!(node.parent in record)) {
record[node.parent] = [];
}
});

return record;
};

const BranchTreeDisplay = ({
treeParentChildRecord,
displayedBranchName,
Expand Down
4 changes: 1 addition & 3 deletions src/components/select-root-branch.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import GumptionItemComponent from './gumption-item-component.js';
import React, { useCallback, useMemo, useState } from 'react';
import SelectInput from 'ink-select-input';
import { Box, Text, useInput } from 'ink';
import { ConfirmStatement } from './confirm-statement.js';
import { Loading } from './loading.js';
import { SearchSelectInput } from './select-search-input.js';
import { Text, useInput } from 'ink';
import { useAsyncValue } from '../hooks/use-async-value.js';
import { useGit } from '../hooks/use-git.js';
import { useTree } from '../hooks/use-tree.js';
Expand Down
4 changes: 1 addition & 3 deletions src/hooks/use-tree.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { Tree, TreeService, createTreeService } from '../services/tree.js';
import { useAsyncValue } from './use-async-value.js';
import { useCallback, useMemo, useState } from 'react';
import { useGit } from './use-git.js';
import { useGitHelpers } from './use-git-helpers.js';
import { useMemo, useState } from 'react';

interface UseTreeResult extends TreeService {
currentTree: Tree;
Expand Down
28 changes: 28 additions & 0 deletions src/utils/tree-helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Tree } from '../services/tree.js';

/**
* @returns a record mapping every branch name to the names of its child branches in the tree
*/
export const treeToParentChildRecord = (
tree: Tree
): Record<string, string[]> => {
const record: Record<string, string[]> = {};

tree.forEach((node) => {
if (!(node.key in record)) {
record[node.key] = [];
}

if (node.parent === null) return;

if (node.parent in record) {
const existingChildren = record[node.parent] as string[];
record[node.parent] = [...existingChildren, node.key];
}
if (!(node.parent in record)) {
record[node.parent] = [];
}
});

return record;
};

0 comments on commit 4432264

Please sign in to comment.