mirror of
https://github.com/block/buzz.git
synced 2026-11-28 20:22:39 +00:00
feat(desktop): Projects v3 — overview redesign, activity feed, agent access & sync controls (#1851)
This commit is contained in:
@@ -1,4 +1,13 @@
|
||||
import { ChevronDown, GitBranch, UploadCloud } from "lucide-react";
|
||||
import {
|
||||
ChevronDown,
|
||||
Cloud,
|
||||
DownloadCloud,
|
||||
GitBranch,
|
||||
HardDrive,
|
||||
Loader2,
|
||||
RefreshCw,
|
||||
UploadCloud,
|
||||
} from "lucide-react";
|
||||
|
||||
import { Button } from "@/shared/ui/button";
|
||||
import {
|
||||
@@ -72,60 +81,143 @@ export type RepoSourceHeaderControls = {
|
||||
localDisabled: boolean;
|
||||
localLabel: string;
|
||||
remoteLabel: string;
|
||||
/** Push of local commits, shown only when the local source can push. */
|
||||
/** Push of local commits, available when the local checkout is ahead. */
|
||||
canPush?: boolean;
|
||||
onPush?: () => void;
|
||||
pushDisabled?: boolean;
|
||||
pushPending?: boolean;
|
||||
pushTitle?: string;
|
||||
/** Fast-forward pull, available when the local checkout is behind. */
|
||||
canPull?: boolean;
|
||||
onPull?: () => void;
|
||||
pullDisabled?: boolean;
|
||||
pullPending?: boolean;
|
||||
pullTitle?: string;
|
||||
/** Commits the local checkout is ahead/behind the remote branch. */
|
||||
aheadCount?: number | null;
|
||||
behindCount?: number | null;
|
||||
/** Manual sync-status refresh (runs a git fetch under the hood). */
|
||||
onFetch?: () => void;
|
||||
fetchPending?: boolean;
|
||||
fetchTitle?: string;
|
||||
};
|
||||
|
||||
/** Small pill toggle between the remote and local repository source. */
|
||||
export function RepoSourceToggle({
|
||||
/** Compact dropdown picking the repository source (remote or local). */
|
||||
export function RepoSourceDropdown({
|
||||
controls,
|
||||
}: {
|
||||
controls: RepoSourceHeaderControls;
|
||||
}) {
|
||||
const showPush =
|
||||
controls.source === "local" && controls.canPush && controls.onPush;
|
||||
const isLocal = controls.source === "local";
|
||||
const SourceIcon = isLocal ? HardDrive : Cloud;
|
||||
return (
|
||||
<div className="flex shrink-0 items-center gap-1">
|
||||
{showPush ? (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button
|
||||
aria-label={
|
||||
controls.pushPending
|
||||
? "Pushing local commits"
|
||||
: "Push local commits"
|
||||
className="h-6 max-w-full shrink-0 gap-1 px-1.5 text-xs font-medium"
|
||||
size="sm"
|
||||
type="button"
|
||||
variant="ghost"
|
||||
>
|
||||
<SourceIcon className="h-3 w-3 shrink-0 text-muted-foreground" />
|
||||
<span className="truncate">
|
||||
{isLocal ? controls.localLabel : controls.remoteLabel}
|
||||
</span>
|
||||
<ChevronDown className="h-3.5 w-3.5 shrink-0 text-muted-foreground" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="start" className="min-w-40">
|
||||
<DropdownMenuRadioGroup
|
||||
onValueChange={(value) =>
|
||||
controls.onSourceChange(value === "local" ? "local" : "remote")
|
||||
}
|
||||
className="h-6 w-6 shrink-0 rounded-full"
|
||||
disabled={controls.pushDisabled}
|
||||
onClick={controls.onPush}
|
||||
size="icon"
|
||||
title={controls.pushTitle ?? "Push local commits"}
|
||||
variant="default"
|
||||
value={controls.source}
|
||||
>
|
||||
<UploadCloud className="h-3.5 w-3.5" />
|
||||
</Button>
|
||||
) : null}
|
||||
<div className="flex shrink-0 items-center gap-0.5 border border-border/60 bg-muted/40 p-0.5">
|
||||
<Button
|
||||
className="h-6 px-2.5 text-xs"
|
||||
onClick={() => controls.onSourceChange("remote")}
|
||||
size="sm"
|
||||
variant={controls.source === "remote" ? "secondary" : "ghost"}
|
||||
>
|
||||
{controls.remoteLabel}
|
||||
</Button>
|
||||
<Button
|
||||
className="h-6 px-2.5 text-xs"
|
||||
disabled={controls.localDisabled}
|
||||
onClick={() => controls.onSourceChange("local")}
|
||||
size="sm"
|
||||
variant={controls.source === "local" ? "secondary" : "ghost"}
|
||||
>
|
||||
{controls.localLabel}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<DropdownMenuRadioItem value="remote">
|
||||
<Cloud className="mr-1.5 h-3.5 w-3.5 text-muted-foreground" />
|
||||
{controls.remoteLabel}
|
||||
</DropdownMenuRadioItem>
|
||||
<DropdownMenuRadioItem
|
||||
disabled={controls.localDisabled}
|
||||
value="local"
|
||||
>
|
||||
<HardDrive className="mr-1.5 h-3.5 w-3.5 text-muted-foreground" />
|
||||
{controls.localLabel}
|
||||
</DropdownMenuRadioItem>
|
||||
</DropdownMenuRadioGroup>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
);
|
||||
}
|
||||
|
||||
/** Always-visible contextual sync button: Pull when the local checkout is
|
||||
* behind, Push when ahead, otherwise Fetch to refresh the status. */
|
||||
export function RepoSyncActionButton({
|
||||
controls,
|
||||
}: {
|
||||
controls: RepoSourceHeaderControls;
|
||||
}) {
|
||||
const pull = controls.canPull && controls.onPull;
|
||||
const push = controls.canPush && controls.onPush;
|
||||
|
||||
if (pull) {
|
||||
const count = controls.behindCount ?? 0;
|
||||
return (
|
||||
<Button
|
||||
className="h-6 shrink-0 gap-1 rounded-full px-2.5 text-xs"
|
||||
disabled={controls.pullDisabled}
|
||||
onClick={controls.onPull}
|
||||
size="sm"
|
||||
title={controls.pullTitle ?? "Pull remote commits"}
|
||||
variant="ghost"
|
||||
>
|
||||
{controls.pullPending ? (
|
||||
<Loader2 className="h-3 w-3 animate-spin" />
|
||||
) : (
|
||||
<DownloadCloud className="h-3 w-3" />
|
||||
)}
|
||||
Pull{count > 0 ? ` ${count}` : ""}
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
||||
if (push) {
|
||||
const count = controls.aheadCount ?? 0;
|
||||
return (
|
||||
<Button
|
||||
className="h-6 shrink-0 gap-1 rounded-full px-2.5 text-xs"
|
||||
disabled={controls.pushDisabled}
|
||||
onClick={controls.onPush}
|
||||
size="sm"
|
||||
title={controls.pushTitle ?? "Push local commits"}
|
||||
variant="ghost"
|
||||
>
|
||||
{controls.pushPending ? (
|
||||
<Loader2 className="h-3 w-3 animate-spin" />
|
||||
) : (
|
||||
<UploadCloud className="h-3 w-3" />
|
||||
)}
|
||||
Push{count > 0 ? ` ${count}` : ""}
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
||||
if (!controls.onFetch) return null;
|
||||
return (
|
||||
<Button
|
||||
className="h-6 shrink-0 gap-1 rounded-full px-2.5 text-xs"
|
||||
disabled={controls.fetchPending}
|
||||
onClick={controls.onFetch}
|
||||
size="sm"
|
||||
title={controls.fetchTitle ?? "Check for remote changes"}
|
||||
variant="ghost"
|
||||
>
|
||||
{controls.fetchPending ? (
|
||||
<Loader2 className="h-3 w-3 animate-spin" />
|
||||
) : (
|
||||
<RefreshCw className="h-3 w-3" />
|
||||
)}
|
||||
Fetch
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user