mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +01:00
fix: update settings and skills handling with assistant redirect (#220)
* fix: enable swipe-back suspension on more drawer and remove unused variable * refactor(frontend): improve dialog component and settings navigation * fix: disable route swipe suspension in MoreDrawer to prevent unintended navigation * fix(frontend): enable swipe-back suspension on more drawer route * refactor(frontend): improve mobile navigation drawer and tab bar * feat: add schedules service and workspace hook with navigation updates * chore: add workspace hook, schedules library, and tests * fix: prevent MoreDrawer sentinel from undoing navigation * feat: per-agent model selection and UI refinements (#217) * feat: per-agent model selection and UI refinements - Add agentModels store with setAgentModel/getAgentModel - PromptInput uses session model priority and stores agent model on change - useContextUsage derives model from assistant message instead of global - Migrate sub-agent/subtask badges from purple to blue with refined styling - Fix MoreDrawer sentinel to skip history-back on navigation * refactor: improve per-agent model selection and task tool call status indicators * feat: add repo management skill and internal repos API * fix: improve assistant session launcher and UI components * fix: update atomic-json test assertions * refactor: split Assistant Mode instructions between AGENTS.md and assistant.md * loop: todo-header-mobile completed after 3 iterations (#218) * loop: stt-perf-1 completed after 5 iterations * fix: load audio worklet per recording context * fix: canonicalize assistant navigation routes * fix: adjust scroll-up threshold for header visibility * fix: update settings and skills handling with assistant redirect * refactor: simplify context usage indicator and extract token sum helper * feat: add currently selected model row to popover and fix responsive truncate
This commit is contained in:
1 parent
c7291518c8
commit
74cdeb3926
73 files changed
+4073
-632
No files matched your search
@@ -109,7 +109,7 @@ describe('BottomSheet', () => {
|
||||
|
||||
expect(useSwipeDismiss).toHaveBeenCalledWith(expect.any(Function), {
|
||||
enabled: true,
|
||||
threshold: 80,
|
||||
threshold: 60,
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { describe, it, expect, vi } from "vitest";
|
||||
import { describe, it, expect, vi, beforeEach } from "vitest";
|
||||
import { render, screen } from "@testing-library/react";
|
||||
import {
|
||||
Dialog,
|
||||
@@ -7,7 +7,30 @@ import {
|
||||
DialogTitle,
|
||||
} from "./dialog";
|
||||
|
||||
function withMobileViewport(fn: () => void) {
|
||||
const originalWidth = window.innerWidth
|
||||
Object.defineProperty(window, 'innerWidth', {
|
||||
writable: true,
|
||||
configurable: true,
|
||||
value: 375,
|
||||
})
|
||||
fn()
|
||||
Object.defineProperty(window, 'innerWidth', {
|
||||
writable: true,
|
||||
configurable: true,
|
||||
value: originalWidth,
|
||||
})
|
||||
}
|
||||
|
||||
describe("DialogContent", () => {
|
||||
beforeEach(() => {
|
||||
Object.defineProperty(window, 'innerWidth', {
|
||||
writable: true,
|
||||
configurable: true,
|
||||
value: 375,
|
||||
})
|
||||
})
|
||||
|
||||
it("applies safe-area padding when fullscreen prop is true", () => {
|
||||
render(
|
||||
<Dialog open>
|
||||
@@ -162,64 +185,225 @@ describe("DialogContent", () => {
|
||||
expect(content).toHaveStyle({ paddingTop: "env(safe-area-inset-top, 0px)" });
|
||||
});
|
||||
|
||||
it('renders hidden close trigger when mobileSwipeToClose is enabled', () => {
|
||||
const onOpenChange = vi.fn();
|
||||
render(
|
||||
<Dialog open onOpenChange={onOpenChange}>
|
||||
<DialogContent mobileFullscreen mobileSwipeToClose>
|
||||
<DialogHeader>
|
||||
<DialogTitle>Swipe Dialog</DialogTitle>
|
||||
</DialogHeader>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
const closeTrigger = document.querySelector('[data-swipe-close-trigger]');
|
||||
expect(closeTrigger).toBeInTheDocument();
|
||||
it('renders hidden close trigger by default on mobile', () => {
|
||||
withMobileViewport(() => {
|
||||
const onOpenChange = vi.fn();
|
||||
render(
|
||||
<Dialog open onOpenChange={onOpenChange}>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>Swipe Dialog</DialogTitle>
|
||||
</DialogHeader>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
const closeTrigger = document.querySelector('[data-swipe-close-trigger]');
|
||||
expect(closeTrigger).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
it('does not render hidden close trigger when mobileSwipeToClose is false', () => {
|
||||
withMobileViewport(() => {
|
||||
render(
|
||||
<Dialog open>
|
||||
<DialogContent mobileSwipeToClose={false}>
|
||||
<DialogHeader>
|
||||
<DialogTitle>Swipe Dialog</DialogTitle>
|
||||
</DialogHeader>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
const closeTrigger = document.querySelector('[data-swipe-close-trigger]');
|
||||
expect(closeTrigger).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
it('closes dialog when hidden close trigger is activated', () => {
|
||||
const onOpenChange = vi.fn();
|
||||
render(
|
||||
<Dialog open onOpenChange={onOpenChange}>
|
||||
<DialogContent mobileFullscreen mobileSwipeToClose>
|
||||
<DialogHeader>
|
||||
<DialogTitle>Swipe Dialog</DialogTitle>
|
||||
</DialogHeader>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
|
||||
const closeTrigger = document.querySelector('[data-swipe-close-trigger]') as HTMLButtonElement | null;
|
||||
expect(closeTrigger).toBeInTheDocument();
|
||||
|
||||
if (closeTrigger) {
|
||||
closeTrigger.click();
|
||||
withMobileViewport(() => {
|
||||
const onOpenChange = vi.fn();
|
||||
render(
|
||||
<Dialog open onOpenChange={onOpenChange}>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>Swipe Dialog</DialogTitle>
|
||||
</DialogHeader>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
|
||||
const closeTrigger = document.querySelector('[data-swipe-close-trigger]') as HTMLButtonElement | null;
|
||||
expect(closeTrigger).toBeInTheDocument();
|
||||
|
||||
if (closeTrigger) {
|
||||
closeTrigger.click();
|
||||
expect(onOpenChange).toHaveBeenCalledWith(false);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('calls onSwipeBack when canSwipeBack is true and swipe completes', () => {
|
||||
withMobileViewport(() => {
|
||||
const mockOnSwipeBack = vi.fn();
|
||||
const onOpenChange = vi.fn();
|
||||
render(
|
||||
<Dialog open onOpenChange={onOpenChange}>
|
||||
<DialogContent
|
||||
canSwipeBack={() => true}
|
||||
onSwipeBack={mockOnSwipeBack}
|
||||
data-testid="swipe-dialog"
|
||||
>
|
||||
Content
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
|
||||
const content = screen.getByTestId('swipe-dialog');
|
||||
|
||||
content.dispatchEvent(new TouchEvent('touchstart', {
|
||||
touches: [{ clientX: 10, clientY: 100 }] as any,
|
||||
}));
|
||||
content.dispatchEvent(new TouchEvent('touchmove', {
|
||||
touches: [{ clientX: 100, clientY: 100 }] as any,
|
||||
}));
|
||||
content.dispatchEvent(new TouchEvent('touchend', {
|
||||
changedTouches: [{ clientX: 100, clientY: 100 }] as any,
|
||||
}));
|
||||
|
||||
expect(mockOnSwipeBack).toHaveBeenCalled();
|
||||
expect(onOpenChange).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
it('attempts close when canSwipeBack is false and swipe completes', () => {
|
||||
withMobileViewport(() => {
|
||||
const mockOnSwipeBack = vi.fn();
|
||||
const onOpenChange = vi.fn();
|
||||
render(
|
||||
<Dialog open onOpenChange={onOpenChange}>
|
||||
<DialogContent
|
||||
canSwipeBack={() => false}
|
||||
onSwipeBack={mockOnSwipeBack}
|
||||
data-testid="swipe-dialog"
|
||||
>
|
||||
Content
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
|
||||
const content = screen.getByTestId('swipe-dialog');
|
||||
content.dispatchEvent(new TouchEvent('touchstart', {
|
||||
touches: [{ clientX: 10, clientY: 100 }] as any,
|
||||
}));
|
||||
content.dispatchEvent(new TouchEvent('touchmove', {
|
||||
touches: [{ clientX: 100, clientY: 100 }] as any,
|
||||
}));
|
||||
content.dispatchEvent(new TouchEvent('touchend', {
|
||||
changedTouches: [{ clientX: 100, clientY: 100 }] as any,
|
||||
}));
|
||||
|
||||
expect(mockOnSwipeBack).not.toHaveBeenCalled();
|
||||
expect(onOpenChange).toHaveBeenCalledWith(false);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('applies safe-area style and hidden trigger for mobileFullscreen', () => {
|
||||
withMobileViewport(() => {
|
||||
render(
|
||||
<Dialog open>
|
||||
<DialogContent mobileFullscreen data-testid="dialog-content">
|
||||
Content
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
const content = screen.getByTestId("dialog-content");
|
||||
expect(content).toHaveStyle({ paddingTop: "env(safe-area-inset-top, 0px)" });
|
||||
expect(document.querySelector('[data-swipe-close-trigger]')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
it('does not apply transform styles to non-fullscreen dialogs', () => {
|
||||
withMobileViewport(() => {
|
||||
render(
|
||||
<Dialog open>
|
||||
<DialogContent data-testid="dialog-content">
|
||||
Content
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
const content = screen.getByTestId("dialog-content");
|
||||
const style = content.getAttribute("style") || "";
|
||||
expect(style).not.toMatch(/transform/);
|
||||
});
|
||||
});
|
||||
|
||||
it('applies swipe transform to fullscreen dialogs during touchmove', () => {
|
||||
withMobileViewport(() => {
|
||||
render(
|
||||
<Dialog open>
|
||||
<DialogContent fullscreen data-testid="dialog-content">
|
||||
Content
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
const content = screen.getByTestId("dialog-content");
|
||||
content.dispatchEvent(new TouchEvent('touchstart', {
|
||||
touches: [{ clientX: 10, clientY: 100 }] as any,
|
||||
}));
|
||||
content.dispatchEvent(new TouchEvent('touchmove', {
|
||||
touches: [{ clientX: 50, clientY: 100 }] as any,
|
||||
}));
|
||||
|
||||
const style = content.getAttribute("style") || "";
|
||||
expect(style).toMatch(/transform/);
|
||||
});
|
||||
});
|
||||
|
||||
it('does not apply swipe transform to non-fullscreen dialogs during touchmove', () => {
|
||||
withMobileViewport(() => {
|
||||
render(
|
||||
<Dialog open>
|
||||
<DialogContent data-testid="dialog-content">
|
||||
Content
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
const content = screen.getByTestId("dialog-content");
|
||||
content.dispatchEvent(new TouchEvent('touchstart', {
|
||||
touches: [{ clientX: 10, clientY: 100 }] as any,
|
||||
}));
|
||||
content.dispatchEvent(new TouchEvent('touchmove', {
|
||||
touches: [{ clientX: 50, clientY: 100 }] as any,
|
||||
}));
|
||||
|
||||
const style = content.getAttribute("style") || "";
|
||||
expect(style).not.toMatch(/transform/);
|
||||
});
|
||||
});
|
||||
|
||||
it('binds swipe handler when mobileSwipeToClose and mobileFullscreen are enabled', () => {
|
||||
const onOpenChange = vi.fn();
|
||||
render(
|
||||
<Dialog open onOpenChange={onOpenChange}>
|
||||
<DialogContent mobileFullscreen mobileSwipeToClose data-testid="swipe-dialog">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Swipe Dialog</DialogTitle>
|
||||
</DialogHeader>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
|
||||
const content = screen.getByTestId('swipe-dialog');
|
||||
const closeTrigger = document.querySelector('[data-swipe-close-trigger]') as HTMLButtonElement | null;
|
||||
|
||||
expect(content).toBeInTheDocument();
|
||||
expect(closeTrigger).toBeInTheDocument();
|
||||
|
||||
const clickSpy = vi.spyOn(closeTrigger as HTMLButtonElement, 'click');
|
||||
closeTrigger?.click();
|
||||
|
||||
expect(clickSpy).toHaveBeenCalled();
|
||||
expect(onOpenChange).toHaveBeenCalledWith(false);
|
||||
withMobileViewport(() => {
|
||||
const onOpenChange = vi.fn();
|
||||
render(
|
||||
<Dialog open onOpenChange={onOpenChange}>
|
||||
<DialogContent mobileFullscreen mobileSwipeToClose data-testid="swipe-dialog">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Swipe Dialog</DialogTitle>
|
||||
</DialogHeader>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
|
||||
const content = screen.getByTestId('swipe-dialog');
|
||||
const closeTrigger = document.querySelector('[data-swipe-close-trigger]') as HTMLButtonElement | null;
|
||||
|
||||
expect(content).toBeInTheDocument();
|
||||
expect(closeTrigger).toBeInTheDocument();
|
||||
|
||||
const clickSpy = vi.spyOn(closeTrigger as HTMLButtonElement, 'click');
|
||||
closeTrigger?.click();
|
||||
|
||||
expect(clickSpy).toHaveBeenCalled();
|
||||
expect(onOpenChange).toHaveBeenCalledWith(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -34,6 +34,8 @@ interface DialogContentProps
|
||||
fullscreen?: boolean
|
||||
mobileFullscreen?: boolean
|
||||
mobileSwipeToClose?: boolean
|
||||
canSwipeBack?: () => boolean
|
||||
onSwipeBack?: () => void
|
||||
onOpenChange?: (open: boolean) => void
|
||||
overlayClassName?: string
|
||||
}
|
||||
@@ -41,14 +43,15 @@ interface DialogContentProps
|
||||
const DialogContent = React.forwardRef<
|
||||
React.ElementRef<typeof DialogPrimitive.Content>,
|
||||
DialogContentProps
|
||||
>(({ className, children, hideCloseButton, fullscreen, mobileFullscreen, mobileSwipeToClose, overlayClassName, ...props }, ref) => {
|
||||
>(({ className, children, hideCloseButton, fullscreen, mobileFullscreen, mobileSwipeToClose, canSwipeBack, onSwipeBack, overlayClassName, style, ...props }, ref) => {
|
||||
const isMobileFullscreenMode = fullscreen || mobileFullscreen
|
||||
const [isMobile, setIsMobile] = React.useState(() => typeof window !== 'undefined' ? window.innerWidth < 768 : false)
|
||||
const shouldEnableMobileSwipe = mobileSwipeToClose !== false && isMobile
|
||||
const shouldAnimateSwipe = shouldEnableMobileSwipe && isMobileFullscreenMode
|
||||
const swipeContainerRef = React.useRef<HTMLDivElement>(null)
|
||||
const contentRef = React.useRef<HTMLDivElement>(null)
|
||||
const closeTriggerRef = React.useRef<HTMLButtonElement>(null)
|
||||
|
||||
const combinedRef = React.useCallback((node: HTMLDivElement | null) => {
|
||||
contentRef.current = node
|
||||
swipeContainerRef.current = node
|
||||
if (typeof ref === 'function') {
|
||||
ref(node)
|
||||
@@ -57,25 +60,33 @@ const DialogContent = React.forwardRef<
|
||||
}
|
||||
}, [ref])
|
||||
|
||||
const [isMobile, setIsMobile] = React.useState(() => typeof window !== 'undefined' ? window.innerWidth < 768 : false)
|
||||
|
||||
React.useEffect(() => {
|
||||
const check = () => setIsMobile(window.innerWidth < 768)
|
||||
window.addEventListener('resize', check)
|
||||
return () => window.removeEventListener('resize', check)
|
||||
}, [])
|
||||
const { bind: swipeBind } = useSwipeBack(
|
||||
const { bind: swipeBind, swipeStyles } = useSwipeBack(
|
||||
() => closeTriggerRef.current?.click(),
|
||||
{ enabled: isMobileFullscreenMode && mobileSwipeToClose === true && isMobile }
|
||||
{ enabled: shouldEnableMobileSwipe, canBack: canSwipeBack, onBack: onSwipeBack }
|
||||
)
|
||||
|
||||
React.useEffect(() => {
|
||||
if (isMobileFullscreenMode && mobileSwipeToClose && isMobile) {
|
||||
if (shouldEnableMobileSwipe) {
|
||||
return swipeBind(swipeContainerRef.current)
|
||||
}
|
||||
return undefined
|
||||
}, [isMobileFullscreenMode, mobileSwipeToClose, isMobile, swipeBind])
|
||||
|
||||
}, [shouldEnableMobileSwipe, swipeBind])
|
||||
|
||||
const baseStyle = isMobileFullscreenMode
|
||||
? { paddingTop: 'env(safe-area-inset-top, 0px)' }
|
||||
: undefined
|
||||
|
||||
const mergedStyle = {
|
||||
...baseStyle,
|
||||
...style,
|
||||
...(shouldAnimateSwipe ? swipeStyles : undefined),
|
||||
}
|
||||
|
||||
return (
|
||||
<DialogPortal>
|
||||
{!fullscreen && <DialogOverlay className={overlayClassName} />}
|
||||
@@ -92,13 +103,11 @@ const DialogContent = React.forwardRef<
|
||||
: "left-[50%] top-[50%] w-[90%] max-w-lg translate-x-[-50%] translate-y-[-50%] p-6 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",
|
||||
className
|
||||
)}
|
||||
style={isMobileFullscreenMode ? {
|
||||
paddingTop: 'env(safe-area-inset-top, 0px)',
|
||||
} : undefined}
|
||||
style={Object.keys(mergedStyle).length > 0 ? mergedStyle : undefined}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
{mobileSwipeToClose && isMobileFullscreenMode && (
|
||||
{shouldEnableMobileSwipe && (
|
||||
<DialogPrimitive.Close ref={closeTriggerRef} className="sr-only" data-swipe-close-trigger />
|
||||
)}
|
||||
{!hideCloseButton && !fullscreen && (
|
||||
|
||||
@@ -52,16 +52,9 @@ describe("PageHeader", () => {
|
||||
expect(header).toHaveClass("z-10");
|
||||
});
|
||||
|
||||
it("applies background styling", () => {
|
||||
it("applies transparent background", () => {
|
||||
render(<PageHeader data-testid="header">Content</PageHeader>);
|
||||
const header = screen.getByTestId("header");
|
||||
expect(header).toHaveClass("bg-gradient-to-b");
|
||||
expect(header).toHaveClass("from-background");
|
||||
});
|
||||
|
||||
it("applies backdrop-blur-sm for frosted glass effect", () => {
|
||||
render(<PageHeader data-testid="header">Content</PageHeader>);
|
||||
const header = screen.getByTestId("header");
|
||||
expect(header).toHaveClass("backdrop-blur-sm");
|
||||
expect(header).toHaveClass("bg-transparent");
|
||||
});
|
||||
});
|
||||
@@ -69,7 +69,7 @@ export function SideDrawer({
|
||||
/>
|
||||
<div
|
||||
className={cn(
|
||||
'fixed top-0 bottom-0 bg-background border-l border-border pt-safe pb-safe flex flex-col',
|
||||
'fixed top-0 bottom-0 bg-background border-l border-border pt-safe pb-safe flex flex-col z-50',
|
||||
side === 'right' ? 'right-0' : 'left-0',
|
||||
widthClass,
|
||||
className,
|
||||
|
||||
Reference in new issue
Block a user