mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-02 08:33:36 +00:00
refactor: clean up and improve readability in WorktreePanel component
- Simplified the formatting of dropdown open change handlers for better readability. - Updated the label from "Branch:" to "Worktrees:" for clarity. - Enhanced conditional checks for removed worktrees to improve code structure.
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { GitBranch, Plus, RefreshCw } from "lucide-react";
|
import { GitBranch, Plus, RefreshCw } from "lucide-react";
|
||||||
import { cn, pathsEqual } from "@/lib/utils";
|
import { cn, pathsEqual } from "@/lib/utils";
|
||||||
@@ -88,18 +87,20 @@ export function WorktreePanel({
|
|||||||
: pathsEqual(worktree.path, currentWorktreePath);
|
: pathsEqual(worktree.path, currentWorktreePath);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleBranchDropdownOpenChange = (worktree: WorktreeInfo) => (open: boolean) => {
|
const handleBranchDropdownOpenChange =
|
||||||
if (open) {
|
(worktree: WorktreeInfo) => (open: boolean) => {
|
||||||
fetchBranches(worktree.path);
|
if (open) {
|
||||||
resetBranchFilter();
|
fetchBranches(worktree.path);
|
||||||
}
|
resetBranchFilter();
|
||||||
};
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const handleActionsDropdownOpenChange = (worktree: WorktreeInfo) => (open: boolean) => {
|
const handleActionsDropdownOpenChange =
|
||||||
if (open) {
|
(worktree: WorktreeInfo) => (open: boolean) => {
|
||||||
fetchBranches(worktree.path);
|
if (open) {
|
||||||
}
|
fetchBranches(worktree.path);
|
||||||
};
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if (!useWorktreesEnabled) {
|
if (!useWorktreesEnabled) {
|
||||||
return null;
|
return null;
|
||||||
@@ -108,7 +109,7 @@ export function WorktreePanel({
|
|||||||
return (
|
return (
|
||||||
<div className="flex items-center gap-2 px-4 py-2 border-b border-border bg-glass/50 backdrop-blur-sm">
|
<div className="flex items-center gap-2 px-4 py-2 border-b border-border bg-glass/50 backdrop-blur-sm">
|
||||||
<GitBranch className="w-4 h-4 text-muted-foreground" />
|
<GitBranch className="w-4 h-4 text-muted-foreground" />
|
||||||
<span className="text-sm text-muted-foreground mr-2">Branch:</span>
|
<span className="text-sm text-muted-foreground mr-2">Worktrees:</span>
|
||||||
|
|
||||||
<div className="flex items-center gap-2 flex-wrap">
|
<div className="flex items-center gap-2 flex-wrap">
|
||||||
{worktrees.map((worktree) => {
|
{worktrees.map((worktree) => {
|
||||||
@@ -137,8 +138,12 @@ export function WorktreePanel({
|
|||||||
aheadCount={aheadCount}
|
aheadCount={aheadCount}
|
||||||
behindCount={behindCount}
|
behindCount={behindCount}
|
||||||
onSelectWorktree={handleSelectWorktree}
|
onSelectWorktree={handleSelectWorktree}
|
||||||
onBranchDropdownOpenChange={handleBranchDropdownOpenChange(worktree)}
|
onBranchDropdownOpenChange={handleBranchDropdownOpenChange(
|
||||||
onActionsDropdownOpenChange={handleActionsDropdownOpenChange(worktree)}
|
worktree
|
||||||
|
)}
|
||||||
|
onActionsDropdownOpenChange={handleActionsDropdownOpenChange(
|
||||||
|
worktree
|
||||||
|
)}
|
||||||
onBranchFilterChange={setBranchFilter}
|
onBranchFilterChange={setBranchFilter}
|
||||||
onSwitchBranch={handleSwitchBranch}
|
onSwitchBranch={handleSwitchBranch}
|
||||||
onCreateBranch={onCreateBranch}
|
onCreateBranch={onCreateBranch}
|
||||||
@@ -172,7 +177,11 @@ export function WorktreePanel({
|
|||||||
className="h-7 w-7 p-0 text-muted-foreground hover:text-foreground"
|
className="h-7 w-7 p-0 text-muted-foreground hover:text-foreground"
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
const removedWorktrees = await fetchWorktrees();
|
const removedWorktrees = await fetchWorktrees();
|
||||||
if (removedWorktrees && removedWorktrees.length > 0 && onRemovedWorktrees) {
|
if (
|
||||||
|
removedWorktrees &&
|
||||||
|
removedWorktrees.length > 0 &&
|
||||||
|
onRemovedWorktrees
|
||||||
|
) {
|
||||||
onRemovedWorktrees(removedWorktrees);
|
onRemovedWorktrees(removedWorktrees);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
|||||||
Reference in New Issue
Block a user