Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions src/browser/components/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {
DialogTitle,
} from "../ui/dialog";
import { Button } from "../ui/button";
import { BlockLink } from "../ui/block-link";
import { cn } from "../cn";
import { Skeleton } from "../ui/skeleton";
import { UserHoverCard } from "../ui/user-hover-card";
Expand Down Expand Up @@ -1962,8 +1963,17 @@ function PRListItem({ pr, onSelect }: PRListItemProps) {
return pr.updated_at ? pr.updated_at > baseline : false;
}, [repoInfo, pr.updated_at, pr.viewerLastReviewAt, pr.isReadByViewer]);

const handleClick = () => {
const href = repoInfo
? `/${repoInfo.owner}/${repoInfo.repo}/pull/${pr.number}`
: undefined;

const handleLinkClick = (e: React.MouseEvent<HTMLAnchorElement>) => {
// Let the browser handle modifier clicks natively (new tab/window).
if (e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) {
return;
}
if (repoInfo) {
e.preventDefault();
onSelect(repoInfo.owner, repoInfo.repo, pr.number, pr.title);
}
};
Expand Down Expand Up @@ -2294,10 +2304,7 @@ function PRListItem({ pr, onSelect }: PRListItemProps) {
};

return (
<button
onClick={handleClick}
className="w-full flex items-start gap-2 sm:gap-3 px-2 sm:px-4 py-3 hover:bg-muted/50 transition-colors text-left"
>
<BlockLink.Root className="w-full flex items-start gap-2 sm:gap-3 px-2 sm:px-4 py-3 hover:bg-muted/50 transition-colors text-left cursor-pointer">
{/* PR Icon */}
{isMerged ? (
<GitMerge className="w-4 h-4 mt-0.5 shrink-0 text-purple-500" />
Expand All @@ -2320,9 +2327,13 @@ function PRListItem({ pr, onSelect }: PRListItemProps) {
{/* Content */}
<div className="flex-1 min-w-0">
<div className="flex items-center gap-2 flex-wrap">
<span className="font-medium hover:text-blue-400 break-words">
<BlockLink.Link
href={href}
onClick={handleLinkClick}
className="font-medium hover:text-blue-400 break-words no-underline text-inherit"
>
{pr.title}
</span>
</BlockLink.Link>
<CIStatusBadge />
<ReviewStatusBadge />
{pr.hasNewChanges && (
Expand Down Expand Up @@ -2408,7 +2419,7 @@ function PRListItem({ pr, onSelect }: PRListItemProps) {
)}
</div>
</div>
</button>
</BlockLink.Root>
);
}

Expand Down
80 changes: 80 additions & 0 deletions src/browser/ui/block-link.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import * as React from "react";
import { Slot as SlotPrimitive } from "radix-ui";

// A ref that BlockLink.Root uses to know where its BlockLink.Link is. Root
// clicks are re-dispatched onto this element so the browser handles them as
// native <a> activation.
type BlockLinkContextValue = {
linkRef: React.RefObject<HTMLElement | null>;
};

const BlockLinkContext = React.createContext<BlockLinkContextValue | null>(
null
);

type RootProps = Omit<React.HTMLAttributes<HTMLDivElement>, "onClick"> & {
onClick?: React.MouseEventHandler<HTMLDivElement>;
children: React.ReactNode;
asChild?: boolean;
};

function Root({ onClick, children, asChild, ...props }: RootProps) {
const linkRef = React.useRef<HTMLElement | null>(null);

const handleClick = React.useCallback(
(e: React.MouseEvent<HTMLDivElement>) => {
onClick?.(e);
if (e.defaultPrevented) return;
const link = linkRef.current;
if (link && !link.contains(e.target as Node)) {
link.click();
}
},
[onClick]
);

const Comp = asChild ? SlotPrimitive.Slot : "div";

return (
<BlockLinkContext.Provider value={{ linkRef }}>
<Comp onClick={handleClick} {...props}>
{children}
</Comp>
</BlockLinkContext.Provider>
);
}

type LinkOwnProps = {
asChild?: boolean;
children: React.ReactNode;
};

type LinkProps = LinkOwnProps &
Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, keyof LinkOwnProps>;

function Link({ asChild, children, onClick, ...props }: LinkProps) {
const context = React.useContext(BlockLinkContext);
const localRef = React.useRef<HTMLElement | null>(null);

const setRef = React.useCallback(
(el: HTMLElement | null) => {
localRef.current = el;
if (context) context.linkRef.current = el;
},
[context]
);

const handleClick = (e: React.MouseEvent<HTMLElement>) => {
e.stopPropagation();
onClick?.(e as React.MouseEvent<HTMLAnchorElement>);
};

const Comp = asChild ? SlotPrimitive.Slot : "a";
return (
<Comp ref={setRef} onClick={handleClick} {...props}>
{children}
</Comp>
);
}

export const BlockLink = { Root, Link };
Loading