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
5 changes: 5 additions & 0 deletions .changeset/web-toolbar-one-row.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"hunkdiff": patch
---

The browser review page's toolbar is now one compact row of icon controls that stays on one line in narrow windows, with wrapping, line numbers, agent notes, hidden viewed files, and the theme moved into a new View menu and a Commands button that opens the command palette.
109 changes: 72 additions & 37 deletions packages/hunk/src/web/app/ReviewApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ import { NotesTab } from "../notesPanel/NotesTab";
import { OverviewTab } from "../overview/OverviewTab";
import { selectWebReviewOverview } from "../panel/overviewInput";
import { webLocalKeyCommands, withWebLocalChords } from "../panel/panelCommands";
import type { WebLocalCommandId } from "../commands/webLocalCommands";
import {
WEB_LOCAL_COMMANDS,
webModChordLabel,
type WebLocalCommandId,
} from "../commands/webLocalCommands";
import {
readSidePanelPreferences,
resolveSidePanelOpen,
Expand All @@ -108,13 +112,14 @@ import { SidePanel, type SidePanelTool } from "../panel/SidePanel";
import type { ThemeMenuOption } from "./ThemeMenu";
import { ToastRegion } from "../actions/toasts";
import { reviewLinkWithCapability, watchReviewCapability } from "../session/capability";
import { ReviewControls } from "./ReviewControls";
import { FilterField, ReviewActions } from "./ReviewControls";
import { Toolbar } from "./Toolbar";
import { useReviewInteraction } from "./useReviewInteraction";
import { useReviewTools } from "./useReviewTools";
import { useViewedFiles, type ViewedFiles } from "../viewed/useViewedFiles";
import type { ReviewViewedControls } from "../stream/FileSection";
import { ViewedControls } from "./ViewedControls";
import { ViewedProgress } from "./ViewedProgress";
import { ViewMenu } from "./ViewMenu";

/** Width of one monospace column on this page, measured once the fonts are in place. */
function useColumnWidth() {
Expand Down Expand Up @@ -791,9 +796,25 @@ export function ReviewApp({ session }: { session: ReviewSession }) {
});
const toolsRef = useRef<typeof tools | undefined>(undefined);
toolsRef.current = tools;
const panelHint = webCommandChords(pageKeymap, "hunk.web.toggleSidePanel")
.map(formatKeyChord)
.join(" / ");
const pageHint = (commandId: WebLocalCommandId) =>
webCommandChords(pageKeymap, commandId).map(formatKeyChord).join(" / ") || undefined;
const panelHint = pageHint("hunk.web.toggleSidePanel");
// The palette's chord is a page-only Ctrl/Cmd chord, so it is read from the page's command
// table rather than the keymap; the Commands button never names a key of its own.
const paletteCommand = WEB_LOCAL_COMMANDS.find(
(command) => command.id === "hunk.web.commandPalette",
);
const commandsHint =
paletteCommand && "modKey" in paletteCommand
? webModChordLabel(paletteCommand.modKey)
: undefined;
const viewMenuHints = {
wrap: keyHint("hunk.view.toggleLineWrap"),
lineNumbers: keyHint("hunk.view.toggleLineNumbers"),
agentNotes: keyHint("hunk.view.toggleAgentNotes"),
hideViewed: pageHint("hunk.web.toggleHideViewed"),
theme: keyHint("hunk.view.openThemeSelector"),
};
const panelTools: SidePanelTool[] = overview
? [
{
Expand Down Expand Up @@ -902,42 +923,56 @@ export function ReviewApp({ session }: { session: ReviewSession }) {
? `Loading ${mirror.loadedFiles} of ${mirror.totalFiles}`
: undefined
}
preferences={preferences}
layout={preferences.layout}
onLayout={(next) => updatePreferences({ layout: next })}
sidebarOpen={sidebarOpen}
resolvedLayout={layout}
themes={themeOptions}
themeId={selectedId}
{...(theme ? { themeLabel: theme.label } : {})}
themeMenuOpen={themeMenuOpen}
onThemeMenuOpen={setThemeMenuOpen}
keyHint={keyHint}
onPreferences={updatePreferences}
onToggleSidebar={() => updatePreferences({ sidebarOpen: !sidebarOpen })}
onTheme={choose}
controls={
<>
<ReviewControls
ref={filterRef}
filterText={interactive.filterText}
onFilterChange={interactive.changeFilter}
{...(keyHint("hunk.review.focusFilter")
? { filterKeyHint: keyHint("hunk.review.focusFilter") }
: {})}
refreshing={interactive.refreshing}
onRefresh={() => void interactive.refresh()}
{...(keyHint("hunk.app.refresh")
? { refreshKeyHint: keyHint("hunk.app.refresh") }
: {})}
onCopyLink={copyLink}
sessionEnded={sessionEnded}
/>
<ViewedControls
progress={viewed.progress}
hideViewed={viewed.hideViewed}
onToggleHideViewed={viewed.toggleHideViewed}
/>
</>
filterField={
<FilterField
ref={filterRef}
filterText={interactive.filterText}
onFilterChange={interactive.changeFilter}
{...(keyHint("hunk.review.focusFilter")
? { filterKeyHint: keyHint("hunk.review.focusFilter") }
: {})}
sessionEnded={sessionEnded}
/>
}
viewedProgress={<ViewedProgress progress={viewed.progress} />}
viewMenu={
<ViewMenu
wrapLines={preferences.wrapLines}
showLineNumbers={preferences.showLineNumbers}
onPreferences={updatePreferences}
agentNotesVisible={review.showAgentNotes}
onToggleAgentNotes={() => void interactive.toggleAgentNotes()}
hideViewed={viewed.hideViewed}
onToggleHideViewed={viewed.toggleHideViewed}
sessionEnded={sessionEnded}
themes={themeOptions}
themeId={selectedId}
{...(theme ? { themeLabel: theme.label } : {})}
themeMenuOpen={themeMenuOpen}
onThemeMenuOpen={setThemeMenuOpen}
onTheme={choose}
hints={viewMenuHints}
/>
}
reviewActions={
<ReviewActions
refreshing={interactive.refreshing}
onRefresh={() => void interactive.refresh()}
{...(keyHint("hunk.app.refresh")
? { refreshKeyHint: keyHint("hunk.app.refresh") }
: {})}
onCopyLink={copyLink}
sessionEnded={sessionEnded}
/>
}
onOpenCommands={tools.openPalette}
{...(commandsHint ? { commandsHint } : {})}
panelOpen={panelOpen}
{...(panelHint ? { panelHint } : {})}
onTogglePanel={() => updatePanel({ open: !panelOpen })}
Expand Down
168 changes: 101 additions & 67 deletions packages/hunk/src/web/app/ReviewControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,84 +2,118 @@
/**
* The toolbar's review controls: the shared file filter, refresh, and "Copy review link".
*
* The filter and agent-note visibility are shared with every surface of the review, the
* terminal included, so the filter says so beside itself. Refresh reopens the session's input
* (`POST /refresh`), paced by the session. Copying the review link is the one deliberate way the
* capability leaves the page.
* The filter is shared with every surface of the review, the terminal included, so the field
* says so beside itself and in its tooltip. Refresh reopens the session's input
* (`POST /refresh`), paced by the session. Copying the review link is the one deliberate way
* the capability leaves the page. Refresh and copy are icon buttons whose accessible names
* carry their state ("Refreshing…", "Copied", "Copy failed"), and the copy result also shows
* as a brief visible label.
*/
import { forwardRef, useState } from "react";
import { Icon } from "../icons/Icon";

export interface ReviewControlsProps {
export interface FilterFieldProps {
filterText: string;
onFilterChange: (text: string) => void;
/** The shortcut that focuses the filter, for its tooltip. */
/** The shortcut that focuses the filter, shown in the field and its tooltip. */
filterKeyHint?: string;
refreshing: boolean;
onRefresh: () => void;
refreshKeyHint?: string;
onCopyLink: () => Promise<boolean>;
/** The session has ended: the filter and refresh need it, so both are disabled. */
/** The session has ended: the filter needs it, so it is disabled. */
sessionEnded?: boolean;
}

/** The filter field, refresh button, and copy-link button. */
export const ReviewControls = forwardRef<HTMLInputElement, ReviewControlsProps>(
function ReviewControls(props, filterRef) {
const [copied, setCopied] = useState<"idle" | "copied" | "failed">("idle");
/** The shared file filter field. */
export const FilterField = forwardRef<HTMLInputElement, FilterFieldProps>(
function FilterField(props, filterRef) {
return (
<div className="review-controls">
<label
className="filter-field"
title="The filter is shared with the terminal and every other window on this review."
>
<span className="visually-hidden">Filter files</span>
<input
ref={filterRef}
type="search"
data-testid="filter-input"
placeholder={`Filter files${props.filterKeyHint ? ` (${props.filterKeyHint})` : ""}`}
value={props.filterText}
disabled={props.sessionEnded}
onChange={(event) => props.onFilterChange(event.target.value)}
onKeyDown={(event) => {
if (event.key === "Escape") {
event.preventDefault();
(event.target as HTMLInputElement).blur();
}
}}
/>
<span className="shared-hint" aria-hidden="true">
shared
</span>
</label>
<button
type="button"
className="tool-button"
data-testid="refresh"
aria-busy={props.refreshing}
disabled={props.refreshing || props.sessionEnded}
title={
props.refreshKeyHint
? `Reload the review's input (${props.refreshKeyHint})`
: "Reload the review's input"
}
onClick={props.onRefresh}
>
{props.refreshing ? "Refreshing…" : "Refresh"}
</button>
<button
type="button"
className="tool-button"
data-testid="copy-link"
title="Copy a link that opens this review, including its access key"
onClick={async () => {
setCopied((await props.onCopyLink()) ? "copied" : "failed");
setTimeout(() => setCopied("idle"), 2_000);
<label
className="filter-field"
title={`The filter is shared with the terminal and every other window on this review.${
props.filterKeyHint ? ` Focus it with ${props.filterKeyHint}.` : ""
}`}
>
<Icon name="search" className="filter-icon" />
<span className="visually-hidden">Filter files</span>
<input
ref={filterRef}
type="search"
data-testid="filter-input"
placeholder="Filter files"
value={props.filterText}
disabled={props.sessionEnded}
onChange={(event) => props.onFilterChange(event.target.value)}
onKeyDown={(event) => {
if (event.key === "Escape") {
event.preventDefault();
(event.target as HTMLInputElement).blur();
}
}}
>
{copied === "copied" ? "Copied" : copied === "failed" ? "Copy failed" : "Copy link"}
</button>
</div>
/>
<span className="shared-hint" aria-hidden="true">
shared
</span>
{props.filterKeyHint ? (
<kbd className="key-hint filter-key" aria-hidden="true">
{props.filterKeyHint}
</kbd>
) : null}
</label>
);
},
);

export interface ReviewActionsProps {
refreshing: boolean;
onRefresh: () => void;
refreshKeyHint?: string;
onCopyLink: () => Promise<boolean>;
/** The session has ended: refresh needs it, so it is disabled. */
sessionEnded?: boolean;
}

/** The refresh and copy-link icon buttons. */
export function ReviewActions(props: ReviewActionsProps) {
const [copied, setCopied] = useState<"idle" | "copied" | "failed">("idle");
const copyLabel =
copied === "copied" ? "Copied" : copied === "failed" ? "Copy failed" : "Copy link";

return (
<>
<button
type="button"
className="tool-button icon-button"
data-testid="refresh"
aria-busy={props.refreshing}
disabled={props.refreshing || props.sessionEnded}
title={
props.refreshKeyHint
? `Reload the review's input (${props.refreshKeyHint})`
: "Reload the review's input"
}
onClick={props.onRefresh}
>
<Icon name="refresh" className={props.refreshing ? "spinning" : undefined} />
<span className="visually-hidden">{props.refreshing ? "Refreshing…" : "Refresh"}</span>
</button>
<button
type="button"
className="tool-button icon-button copy-button"
data-testid="copy-link"
data-state={copied}
title="Copy a link that opens this review, including its access key"
onClick={async () => {
setCopied((await props.onCopyLink()) ? "copied" : "failed");
setTimeout(() => setCopied("idle"), 2_000);
}}
>
<Icon name={copied === "copied" ? "check" : copied === "failed" ? "cross" : "link"} />
{/* The name doubles as the result: shown briefly after a copy, announced politely. */}
<span
className={copied === "idle" ? "visually-hidden" : "copy-feedback"}
aria-live="polite"
>
{copyLabel}
</span>
</button>
</>
);
}
Loading
Loading