ccmanager 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/NewWorktree.js +20 -16
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useState,
|
|
1
|
+
import React, { useState, useMemo } from 'react';
|
|
2
2
|
import { Box, Text, useInput } from 'ink';
|
|
3
3
|
import TextInput from 'ink-text-input';
|
|
4
4
|
import SelectInput from 'ink-select-input';
|
|
@@ -13,18 +13,23 @@ const NewWorktree = ({ onComplete, onCancel }) => {
|
|
|
13
13
|
const [step, setStep] = useState(isAutoDirectory ? 'branch' : 'path');
|
|
14
14
|
const [path, setPath] = useState('');
|
|
15
15
|
const [branch, setBranch] = useState('');
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
// Initialize worktree service and load branches (memoized to avoid re-initialization)
|
|
17
|
+
const { branches, defaultBranch } = useMemo(() => {
|
|
18
|
+
const service = new WorktreeService();
|
|
19
|
+
const allBranches = service.getAllBranches();
|
|
20
|
+
const defaultBr = service.getDefaultBranch();
|
|
21
|
+
return {
|
|
22
|
+
branches: allBranches,
|
|
23
|
+
defaultBranch: defaultBr,
|
|
24
|
+
};
|
|
25
|
+
}, []); // Empty deps array - only initialize once
|
|
26
|
+
// Create branch items with default branch first (memoized)
|
|
27
|
+
const branchItems = useMemo(() => [
|
|
23
28
|
{ label: `${defaultBranch} (default)`, value: defaultBranch },
|
|
24
29
|
...branches
|
|
25
30
|
.filter(br => br !== defaultBranch)
|
|
26
31
|
.map(br => ({ label: br, value: br })),
|
|
27
|
-
];
|
|
32
|
+
], [branches, defaultBranch]);
|
|
28
33
|
useInput((input, key) => {
|
|
29
34
|
if (shortcutManager.matchesShortcut('cancel', input, key)) {
|
|
30
35
|
onCancel();
|
|
@@ -52,13 +57,12 @@ const NewWorktree = ({ onComplete, onCancel }) => {
|
|
|
52
57
|
onComplete(path, branch, item.value);
|
|
53
58
|
}
|
|
54
59
|
};
|
|
55
|
-
//
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}, [branch, isAutoDirectory, worktreeConfig.autoDirectoryPattern]);
|
|
60
|
+
// Calculate generated path for preview (memoized to avoid expensive recalculations)
|
|
61
|
+
const generatedPath = useMemo(() => {
|
|
62
|
+
return isAutoDirectory && branch
|
|
63
|
+
? generateWorktreeDirectory(branch, worktreeConfig.autoDirectoryPattern)
|
|
64
|
+
: '';
|
|
65
|
+
}, [isAutoDirectory, branch, worktreeConfig.autoDirectoryPattern]);
|
|
62
66
|
return (React.createElement(Box, { flexDirection: "column" },
|
|
63
67
|
React.createElement(Box, { marginBottom: 1 },
|
|
64
68
|
React.createElement(Text, { bold: true, color: "green" }, "Create New Worktree")),
|