fix: improve mobile chat input controls (#1477)
This commit is contained in:
@@ -9,9 +9,23 @@ import { PR_CI_DESKTOP_POPOVER_SCROLL_CLASS } from "./pr-ci-popover";
|
||||
import type { AppState } from "@/lib/state/store";
|
||||
import type { TaskCIAutomationOptions, TaskPR } from "@/lib/types/github";
|
||||
|
||||
const isMobileMock = vi.fn(() => false);
|
||||
vi.mock("@/hooks/use-mobile", () => ({
|
||||
useIsMobile: () => isMobileMock(),
|
||||
const responsiveMock = vi.hoisted(() => ({
|
||||
breakpoint: "desktop" as "mobile" | "tablet" | "compactDesktop" | "desktop",
|
||||
isFinePointer: true,
|
||||
}));
|
||||
vi.mock("@/hooks/use-responsive-breakpoint", () => ({
|
||||
useResponsiveBreakpoint: () => ({
|
||||
breakpoint: responsiveMock.breakpoint,
|
||||
isMobile: responsiveMock.breakpoint === "mobile",
|
||||
isTablet: responsiveMock.breakpoint === "tablet",
|
||||
isDesktop:
|
||||
responsiveMock.breakpoint === "compactDesktop" || responsiveMock.breakpoint === "desktop",
|
||||
isCompactDesktop: responsiveMock.breakpoint === "compactDesktop",
|
||||
isFullDesktop: responsiveMock.breakpoint === "desktop",
|
||||
isFinePointer: responsiveMock.isFinePointer,
|
||||
usesDesktopWorkbench:
|
||||
responsiveMock.breakpoint === "compactDesktop" || responsiveMock.breakpoint === "desktop",
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock("@/lib/api/domains/github-api", async (importOriginal) => {
|
||||
@@ -95,12 +109,12 @@ function makeCIOptions(overrides: Partial<TaskCIAutomationOptions> = {}): TaskCI
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
isMobileMock.mockReturnValue(false);
|
||||
responsiveMock.breakpoint = "desktop";
|
||||
responsiveMock.isFinePointer = true;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
isMobileMock.mockReset();
|
||||
});
|
||||
|
||||
const CHIP_TESTID = "pr-status-chip";
|
||||
@@ -156,7 +170,10 @@ describe("PRStatusChip", () => {
|
||||
});
|
||||
|
||||
describe("PRStatusChip desktop branch", () => {
|
||||
beforeEach(() => isMobileMock.mockReturnValue(false));
|
||||
beforeEach(() => {
|
||||
responsiveMock.breakpoint = "desktop";
|
||||
responsiveMock.isFinePointer = true;
|
||||
});
|
||||
|
||||
it("renders the chip button without a Drawer", () => {
|
||||
renderWithStore(seededState, <PRStatusChip taskId="task-1" />);
|
||||
@@ -170,6 +187,18 @@ describe("PRStatusChip desktop branch", () => {
|
||||
expect(document.querySelector(DRAWER_SELECTOR)).toBeNull();
|
||||
});
|
||||
|
||||
it("keeps the hovercard path on fine-pointer tablets", () => {
|
||||
responsiveMock.breakpoint = "tablet";
|
||||
responsiveMock.isFinePointer = true;
|
||||
|
||||
renderWithStore(seededState, <PRStatusChip taskId="task-1" />);
|
||||
const chip = screen.getByTestId(CHIP_TESTID);
|
||||
act(() => {
|
||||
fireEvent.click(chip);
|
||||
});
|
||||
expect(document.querySelector(DRAWER_SELECTOR)).toBeNull();
|
||||
});
|
||||
|
||||
it("constrains the hover popover to the available viewport height", async () => {
|
||||
renderWithStore(seededState, <PRStatusChip taskId="task-1" />);
|
||||
await expectDesktopHoverPopoverConstrained();
|
||||
@@ -208,7 +237,10 @@ describe("PRStatusChip desktop branch", () => {
|
||||
});
|
||||
|
||||
describe("PRStatusChip mobile branch", () => {
|
||||
beforeEach(() => isMobileMock.mockReturnValue(true));
|
||||
beforeEach(() => {
|
||||
responsiveMock.breakpoint = "mobile";
|
||||
responsiveMock.isFinePointer = false;
|
||||
});
|
||||
|
||||
it("renders the chip closed and opens the drawer on click", () => {
|
||||
renderWithStore(seededState, <PRStatusChip taskId="task-1" />);
|
||||
@@ -298,6 +330,26 @@ describe("PRStatusChip mobile branch", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("PRStatusChip touch tablet branch", () => {
|
||||
beforeEach(() => {
|
||||
responsiveMock.breakpoint = "tablet";
|
||||
responsiveMock.isFinePointer = false;
|
||||
});
|
||||
|
||||
it("opens the drawer instead of the hovercard on coarse-pointer tablets", () => {
|
||||
renderWithStore(seededState, <PRStatusChip taskId="task-1" />);
|
||||
expect(document.querySelector(DRAWER_SELECTOR)).toBeNull();
|
||||
|
||||
act(() => {
|
||||
fireEvent.click(screen.getByTestId(CHIP_TESTID));
|
||||
});
|
||||
|
||||
expect(document.querySelector(DRAWER_SELECTOR)).not.toBeNull();
|
||||
expect(document.querySelector("[data-testid='pr-topbar-popover-inner']")).not.toBeNull();
|
||||
expect(screen.getByTestId("pr-popover-title").textContent).toBe("#42 Test PR");
|
||||
});
|
||||
});
|
||||
|
||||
describe("PRStatusChip — mergeability", () => {
|
||||
it("is 'conflict' (not 'passed') for a dirty PR even with green checks + approval", () => {
|
||||
// Regression: the chip read mergeable_state-blind and showed the green
|
||||
@@ -379,7 +431,10 @@ describe("PRStatusChip — mergeability", () => {
|
||||
});
|
||||
|
||||
describe("PRStatusChip CI automation mobile parity", () => {
|
||||
beforeEach(() => isMobileMock.mockReturnValue(true));
|
||||
beforeEach(() => {
|
||||
responsiveMock.breakpoint = "mobile";
|
||||
responsiveMock.isFinePointer = false;
|
||||
});
|
||||
|
||||
it("renders controls and prompt editing inside the drawer", async () => {
|
||||
renderWithStore(seededState, <PRStatusChip taskId="task-1" />);
|
||||
@@ -477,7 +532,10 @@ describe("PRStatusChip — multiple PRs", () => {
|
||||
});
|
||||
|
||||
describe("mobile drawer", () => {
|
||||
beforeEach(() => isMobileMock.mockReturnValue(true));
|
||||
beforeEach(() => {
|
||||
responsiveMock.breakpoint = "mobile";
|
||||
responsiveMock.isFinePointer = false;
|
||||
});
|
||||
|
||||
it("opens a drawer with the tabbed multi-PR popover", () => {
|
||||
renderWithStore(multiState(TWO_OPEN), <PRStatusChip taskId="task-1" />);
|
||||
|
||||
@@ -34,7 +34,7 @@ import {
|
||||
isPRWaitingOnBranchProtection,
|
||||
pickDefaultPR,
|
||||
} from "@/components/github/pr-task-icon";
|
||||
import { useIsMobile } from "@/hooks/use-mobile";
|
||||
import { useTouchDrawer } from "@/hooks/use-compact-task-chrome";
|
||||
import type { TaskPR } from "@/lib/types/github";
|
||||
|
||||
const HOVER_OPEN_DELAY_MS = 150;
|
||||
@@ -248,8 +248,8 @@ function AutomationFlagBadges({ automation }: { automation: AutomationFlags }) {
|
||||
}
|
||||
|
||||
function PRStatusChipInner({ pr, automation }: { pr: TaskPR; automation: AutomationFlags }) {
|
||||
const isMobile = useIsMobile();
|
||||
if (isMobile) return <PRStatusChipDrawer pr={pr} automation={automation} />;
|
||||
const usesMobileDrawer = useTouchDrawer();
|
||||
if (usesMobileDrawer) return <PRStatusChipDrawer pr={pr} automation={automation} />;
|
||||
return <PRStatusChipHoverCard pr={pr} automation={automation} />;
|
||||
}
|
||||
|
||||
@@ -305,8 +305,8 @@ function PRStatusChipMultiInner({
|
||||
prs: TaskPR[];
|
||||
automation: AutomationFlags;
|
||||
}) {
|
||||
const isMobile = useIsMobile();
|
||||
if (isMobile) return <PRStatusChipMultiDrawer prs={prs} automation={automation} />;
|
||||
const usesMobileDrawer = useTouchDrawer();
|
||||
if (usesMobileDrawer) return <PRStatusChipMultiDrawer prs={prs} automation={automation} />;
|
||||
return <PRStatusChipMultiHoverCard prs={prs} automation={automation} />;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ import {
|
||||
import { useDockviewStore } from "@/lib/state/dockview-store";
|
||||
import { useTaskPR } from "@/hooks/domains/github/use-task-pr";
|
||||
import { useHoverPopover } from "@/hooks/domains/github/use-hover-popover";
|
||||
import { useIsMobile } from "@/hooks/use-mobile";
|
||||
import { useTouchDrawer } from "@/hooks/use-compact-task-chrome";
|
||||
import {
|
||||
aggregatePRStatusColor,
|
||||
getPRStatusColor,
|
||||
@@ -113,13 +113,13 @@ export const PRTopbarButton = memo(function PRTopbarButton() {
|
||||
* {@link useHoverPopover} hook so the chip and this button stay in sync.
|
||||
*/
|
||||
function usePopoverInteractions() {
|
||||
const isMobile = useIsMobile();
|
||||
const usesTouchDrawer = useTouchDrawer();
|
||||
const hover = useHoverPopover({
|
||||
openDelayMs: POPOVER_OPEN_DELAY_MS,
|
||||
closeDelayMs: POPOVER_CLOSE_DELAY_MS,
|
||||
disabled: isMobile,
|
||||
disabled: usesTouchDrawer,
|
||||
});
|
||||
return { isMobile, ...hover };
|
||||
return { usesTouchDrawer, ...hover };
|
||||
}
|
||||
|
||||
function PRSingleButton({ pr }: { pr: TaskPR }) {
|
||||
@@ -127,7 +127,7 @@ function PRSingleButton({ pr }: { pr: TaskPR }) {
|
||||
const activeSessionId = useAppStore((s) => s.tasks.activeSessionId);
|
||||
const tooltip = `${pr.owner}/${pr.repo} #${pr.pr_number} — ${pr.pr_title}`;
|
||||
const {
|
||||
isMobile,
|
||||
usesTouchDrawer,
|
||||
open,
|
||||
onOpenChange,
|
||||
onTriggerEnter,
|
||||
@@ -169,7 +169,7 @@ function PRSingleButton({ pr }: { pr: TaskPR }) {
|
||||
</Button>
|
||||
);
|
||||
|
||||
if (isMobile) {
|
||||
if (usesTouchDrawer) {
|
||||
return (
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>{button}</TooltipTrigger>
|
||||
@@ -205,7 +205,7 @@ function PRMultiButton({ prs }: { prs: TaskPR[] }) {
|
||||
const addPRPanel = useDockviewStore((s) => s.addPRPanel);
|
||||
const activeSessionId = useAppStore((s) => s.tasks.activeSessionId);
|
||||
const {
|
||||
isMobile,
|
||||
usesTouchDrawer,
|
||||
open,
|
||||
onOpenChange,
|
||||
onTriggerEnter,
|
||||
@@ -257,7 +257,7 @@ function PRMultiButton({ prs }: { prs: TaskPR[] }) {
|
||||
>
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
{isMobile ? triggerButton : <PopoverAnchor asChild>{triggerButton}</PopoverAnchor>}
|
||||
{usesTouchDrawer ? triggerButton : <PopoverAnchor asChild>{triggerButton}</PopoverAnchor>}
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>{prs.length} pull requests linked to this task — open one</TooltipContent>
|
||||
</Tooltip>
|
||||
@@ -265,7 +265,7 @@ function PRMultiButton({ prs }: { prs: TaskPR[] }) {
|
||||
</DropdownMenu>
|
||||
);
|
||||
|
||||
if (isMobile) return dropdown;
|
||||
if (usesTouchDrawer) return dropdown;
|
||||
|
||||
return (
|
||||
<Popover open={open} onOpenChange={onOpenChange}>
|
||||
|
||||
Reference in New Issue
Block a user